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