Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Input): Add v-model:value.trim support to input component #7662

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions components/_util/BaseInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const BaseInput = defineComponent({
size: PropTypes.string,
style: PropTypes.oneOfType([String, Object]),
class: PropTypes.string,
valueModifiers: PropTypes.object,
},
emits: [
'change',
Expand Down Expand Up @@ -86,6 +87,9 @@ const BaseInput = defineComponent({
};

const handleBlur = (e: Event) => {
if (props?.valueModifiers?.trim) {
(e.target as HTMLInputElement).value = (e.target as HTMLInputElement).value.trim();
}
emit('blur', e);
};
const handleFocus = (e: Event) => {
Expand Down
2 changes: 2 additions & 0 deletions components/vc-input/BaseInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ export default defineComponent({
affixWrapperClassName,
wrapperClassName,
groupClassName,
valueModifiers,
} = props;
let element = cloneElement(inputElement, {
value,
hidden,
valueModifiers,
});
// ================== Prefix & Suffix ================== //
if (hasPrefixSuffix({ prefix, suffix, allowClear })) {
Expand Down
3 changes: 2 additions & 1 deletion components/vc-input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export default defineComponent({
}
});
return () => {
const { prefixCls, disabled, ...rest } = props;
const { prefixCls, disabled, valueModifiers, ...rest } = props;
return (
<BaseInput
{...rest}
Expand All @@ -245,6 +245,7 @@ export default defineComponent({
triggerFocus={focus}
suffix={getSuffix()}
disabled={disabled}
valueModifiers={valueModifiers}
v-slots={slots}
/>
);
Expand Down
1 change: 1 addition & 0 deletions components/vc-input/inputProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const baseInputProps = () => {
readonly: { type: Boolean, default: undefined },
handleReset: Function as PropType<MouseEventHandler>,
hidden: { type: Boolean, default: undefined },
valueModifiers: { type: Object, default: undefined },
};
};
export const inputProps = () => ({
Expand Down
Loading