mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-02 20:18:22 +08:00
chore: declare input type (#3130)
This commit is contained in:
parent
bd1f42a5ef
commit
7e53c435c3
@ -7,16 +7,16 @@ import { hasProp, getComponent, getOptionProps } from '../_util/props-util';
|
||||
import { defaultConfigProvider } from '../config-provider';
|
||||
import ClearableLabeledInput from './ClearableLabeledInput';
|
||||
|
||||
export function fixControlledValue(value) {
|
||||
export function fixControlledValue(value: string | number) {
|
||||
if (typeof value === 'undefined' || value === null) {
|
||||
return '';
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function resolveOnChange(target, e, onChange) {
|
||||
export function resolveOnChange(target: HTMLInputElement, e: Event, onChange?: Function) {
|
||||
if (onChange) {
|
||||
const event = e;
|
||||
const event = e as any;
|
||||
if (e.type === 'click') {
|
||||
// click clear icon
|
||||
//event = Object.create(e);
|
||||
@ -40,7 +40,7 @@ export function resolveOnChange(target, e, onChange) {
|
||||
}
|
||||
}
|
||||
|
||||
export function getInputClassName(prefixCls, size, disabled) {
|
||||
export function getInputClassName(prefixCls: string, size: string, disabled: boolean) {
|
||||
return classNames(prefixCls, {
|
||||
[`${prefixCls}-sm`]: size === 'small',
|
||||
[`${prefixCls}-lg`]: size === 'large',
|
||||
@ -91,12 +91,12 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleInputFocus(e) {
|
||||
handleInputFocus(e: Event) {
|
||||
this.isFocused = true;
|
||||
this.onFocus && this.onFocus(e);
|
||||
},
|
||||
|
||||
handleInputBlur(e) {
|
||||
handleInputBlur(e: Event) {
|
||||
this.isFocused = false;
|
||||
this.onBlur && this.onBlur(e);
|
||||
},
|
||||
@ -112,15 +112,15 @@ export default defineComponent({
|
||||
this.input.select();
|
||||
},
|
||||
|
||||
saveClearableInput(input: any) {
|
||||
saveClearableInput(input: HTMLInputElement) {
|
||||
this.clearableInput = input;
|
||||
},
|
||||
|
||||
saveInput(input: any) {
|
||||
saveInput(input: HTMLInputElement) {
|
||||
this.input = input;
|
||||
},
|
||||
|
||||
setValue(value: any, callback?: Function) {
|
||||
setValue(value: string | number, callback?: Function) {
|
||||
if (this.stateValue === value) {
|
||||
return;
|
||||
}
|
||||
@ -134,7 +134,7 @@ export default defineComponent({
|
||||
});
|
||||
},
|
||||
triggerChange(e: Event) {
|
||||
this.$emit('update:value', (e.target as any).value);
|
||||
this.$emit('update:value', (e.target as HTMLInputElement).value);
|
||||
this.$emit('change', e);
|
||||
this.$emit('input', e);
|
||||
},
|
||||
|
@ -57,12 +57,12 @@ export default defineComponent({
|
||||
const iconTrigger = ActionMap[action] || '';
|
||||
const iconProps = {
|
||||
[iconTrigger]: this.onVisibleChange,
|
||||
onMousedown: e => {
|
||||
onMousedown: (e: Event) => {
|
||||
// Prevent focused state lost
|
||||
// https://github.com/ant-design/ant-design/issues/15173
|
||||
e.preventDefault();
|
||||
},
|
||||
onMouseup: e => {
|
||||
onMouseup: (e: Event) => {
|
||||
// Prevent focused state lost
|
||||
// https://github.com/ant-design/ant-design/pull/23633/files
|
||||
e.preventDefault();
|
||||
|
@ -61,7 +61,7 @@ const ResizableTextArea = defineComponent({
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
saveTextArea(textArea: any) {
|
||||
saveTextArea(textArea: HTMLTextAreaElement) {
|
||||
this.textArea = textArea;
|
||||
},
|
||||
handleResize(size: any) {
|
||||
|
@ -28,17 +28,17 @@ export default defineComponent({
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
saveInput(node: any) {
|
||||
saveInput(node: HTMLInputElement) {
|
||||
this.input = node;
|
||||
},
|
||||
handleChange(e) {
|
||||
handleChange(e: Event) {
|
||||
if (e && e.target && e.type === 'click') {
|
||||
this.$emit('search', e.target.value, e);
|
||||
this.$emit('search', (e.target as HTMLInputElement).value, e);
|
||||
}
|
||||
this.$emit('update:value', e.target.value);
|
||||
this.$emit('update:value', (e.target as HTMLInputElement).value);
|
||||
this.$emit('change', e);
|
||||
},
|
||||
handleSearch(e) {
|
||||
handleSearch(e: Event) {
|
||||
if (this.loading || this.disabled) {
|
||||
return;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ export default defineComponent({
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
value(val) {
|
||||
value(val: string) {
|
||||
this.stateValue = val;
|
||||
},
|
||||
},
|
||||
@ -49,7 +49,7 @@ export default defineComponent({
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
setValue(value: any, callback?: Function) {
|
||||
setValue(value: string, callback?: Function) {
|
||||
if (!hasProp(this, 'value')) {
|
||||
this.stateValue = value;
|
||||
} else {
|
||||
@ -74,7 +74,7 @@ export default defineComponent({
|
||||
const { value, composing, isComposing } = e.target as any;
|
||||
if (((isComposing || composing) && this.lazy) || this.stateValue === value) return;
|
||||
|
||||
this.setValue((e.target as any).value, () => {
|
||||
this.setValue((e.target as HTMLTextAreaElement).value, () => {
|
||||
this.resizableTextArea.resizeTextarea();
|
||||
});
|
||||
resolveOnChange(this.resizableTextArea.textArea, e, this.triggerChange);
|
||||
@ -91,7 +91,7 @@ export default defineComponent({
|
||||
this.resizableTextArea = resizableTextArea;
|
||||
},
|
||||
|
||||
saveClearableInput(clearableInput: any) {
|
||||
saveClearableInput(clearableInput: HTMLTextAreaElement) {
|
||||
this.clearableInput = clearableInput;
|
||||
},
|
||||
handleReset(e: Event) {
|
||||
@ -124,7 +124,7 @@ export default defineComponent({
|
||||
const { style, class: customClass } = this.$attrs;
|
||||
const getPrefixCls = this.configProvider.getPrefixCls;
|
||||
const prefixCls = getPrefixCls('input', customizePrefixCls);
|
||||
let value = fixControlledValue(stateValue);
|
||||
let value = fixControlledValue(stateValue) as string;
|
||||
// Max length value
|
||||
const hasMaxlength = Number(maxlength) > 0;
|
||||
value = hasMaxlength ? value.slice(0, maxlength) : value;
|
||||
|
Loading…
Reference in New Issue
Block a user