Skip to content

Commit 4f3ce35

Browse files
authored
refactor:input (#6237)
* refactor:input * fix inheritAttrs:false * fix attrs.class
1 parent 69c17dc commit 4f3ce35

File tree

6 files changed

+988
-16
lines changed

6 files changed

+988
-16
lines changed

components/input/ClearableLabeledInput.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default defineComponent({
3939
triggerFocus: { type: Function as PropType<() => void> },
4040
hidden: Boolean,
4141
status: String as PropType<InputStatus>,
42+
hashId: String,
4243
},
4344
setup(props, { slots, attrs }) {
4445
const statusContext = FormItemInputContext.useInject();
@@ -73,6 +74,7 @@ export default defineComponent({
7374
status: customStatus,
7475
addonAfter = slots.addonAfter,
7576
addonBefore = slots.addonBefore,
77+
hashId,
7678
} = props;
7779

7880
const { status: contextStatus, hasFeedback } = statusContext;
@@ -96,6 +98,7 @@ export default defineComponent({
9698
// className will go to addon wrapper
9799
[`${attrs.class}`]: !hasAddon({ addonAfter, addonBefore }) && attrs.class,
98100
},
101+
hashId,
99102
);
100103
return (
101104
<span class={affixWrapperCls} style={attrs.style as CSSProperties} hidden={hidden}>

components/input/Group.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ import type { SizeType } from '../config-provider';
44
import { FormItemInputContext } from '../form/FormItemContext';
55
import type { FocusEventHandler, MouseEventHandler } from '../_util/EventInterface';
66
import useConfigInject from '../config-provider/hooks/useConfigInject';
7+
import classNames from '../_util/classNames';
8+
9+
// CSSINJS
10+
import useStyle from './style';
711

812
export default defineComponent({
913
compatConfig: { MODE: 3 },
1014
name: 'AInputGroup',
15+
inheritAttrs: false,
1116
props: {
1217
prefixCls: String,
1318
size: { type: String as PropType<SizeType> },
@@ -17,33 +22,40 @@ export default defineComponent({
1722
onFocus: { type: Function as PropType<FocusEventHandler> },
1823
onBlur: { type: Function as PropType<FocusEventHandler> },
1924
},
20-
setup(props, { slots }) {
25+
setup(props, { slots, attrs }) {
2126
const { prefixCls, direction } = useConfigInject('input-group', props);
2227
const formItemInputContext = FormItemInputContext.useInject();
2328
FormItemInputContext.useProvide(formItemInputContext, {
2429
isFormItemInput: false,
2530
});
31+
32+
// style
33+
const { prefixCls: inputPrefixCls } = useConfigInject('input', props);
34+
const [wrapSSR, hashId] = useStyle(inputPrefixCls);
35+
2636
const cls = computed(() => {
2737
const pre = prefixCls.value;
2838
return {
2939
[`${pre}`]: true,
40+
[hashId.value]: true,
3041
[`${pre}-lg`]: props.size === 'large',
3142
[`${pre}-sm`]: props.size === 'small',
3243
[`${pre}-compact`]: props.compact,
3344
[`${pre}-rtl`]: direction.value === 'rtl',
3445
};
3546
});
3647
return () => {
37-
return (
48+
return wrapSSR(
3849
<span
39-
class={cls.value}
50+
{...attrs}
51+
class={classNames(cls.value, attrs.class)}
4052
onMouseenter={props.onMouseenter}
4153
onMouseleave={props.onMouseleave}
4254
onFocus={props.onFocus}
4355
onBlur={props.onBlur}
4456
>
4557
{slots.default?.()}
46-
</span>
58+
</span>,
4759
);
4860
};
4961
},

components/input/Input.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import inputProps from './inputProps';
1414
import omit from '../_util/omit';
1515
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
1616

17+
// CSSINJS
18+
import useStyle from './style';
19+
1720
export default defineComponent({
1821
compatConfig: { MODE: 3 },
1922
name: 'AInput',
@@ -26,6 +29,9 @@ export default defineComponent({
2629
const mergedStatus = computed(() => getMergedStatus(formItemInputContext.status, props.status));
2730
const { direction, prefixCls, size, autocomplete } = useConfigInject('input', props);
2831

32+
// Style
33+
const [wrapSSR, hashId] = useStyle(prefixCls);
34+
2935
const focus = (option?: InputFocusOptions) => {
3036
inputRef.value?.focus(option);
3137
};
@@ -117,7 +123,7 @@ export default defineComponent({
117123
const prefixClsValue = prefixCls.value;
118124
const inputHasPrefixSuffix = hasPrefixSuffix({ prefix, suffix }) || !!hasFeedback;
119125
const clearIcon = slots.clearIcon || (() => <CloseCircleFilled />);
120-
return (
126+
return wrapSSR(
121127
<VcInput
122128
{...attrs}
123129
{...omit(rest, ['onUpdate:value', 'onChange', 'onInput'])}
@@ -140,6 +146,7 @@ export default defineComponent({
140146
[`${prefixClsValue}-borderless`]: !bordered,
141147
},
142148
!inputHasPrefixSuffix && getStatusClassNames(prefixClsValue, mergedStatus.value),
149+
hashId.value,
143150
)}
144151
affixWrapperClassName={classNames(
145152
{
@@ -149,20 +156,25 @@ export default defineComponent({
149156
[`${prefixClsValue}-affix-wrapper-borderless`]: !bordered,
150157
},
151158
getStatusClassNames(`${prefixClsValue}-affix-wrapper`, mergedStatus.value, hasFeedback),
159+
hashId.value,
160+
)}
161+
wrapperClassName={classNames(
162+
{
163+
[`${prefixClsValue}-group-rtl`]: direction.value === 'rtl',
164+
},
165+
hashId.value,
152166
)}
153-
wrapperClassName={classNames({
154-
[`${prefixClsValue}-group-rtl`]: direction.value === 'rtl',
155-
})}
156167
groupClassName={classNames(
157168
{
158169
[`${prefixClsValue}-group-wrapper-sm`]: size.value === 'small',
159170
[`${prefixClsValue}-group-wrapper-lg`]: size.value === 'large',
160171
[`${prefixClsValue}-group-wrapper-rtl`]: direction.value === 'rtl',
161172
},
162173
getStatusClassNames(`${prefixClsValue}-group-wrapper`, mergedStatus.value, hasFeedback),
174+
hashId.value,
163175
)}
164176
v-slots={{ ...slots, clearIcon }}
165-
></VcInput>
177+
></VcInput>,
166178
);
167179
};
168180
},

components/input/TextArea.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import omit from '../_util/omit';
2121
import type { VueNode } from '../_util/type';
2222
import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils';
2323

24+
// CSSINJS
25+
import useStyle from './style';
26+
2427
function fixEmojiLength(value: string, maxLength: number) {
2528
return [...(value || '')].slice(0, maxLength).join('');
2629
}
@@ -58,6 +61,10 @@ export default defineComponent({
5861
const resizableTextArea = ref();
5962
const mergedValue = ref('');
6063
const { prefixCls, size, direction } = useConfigInject('input', props);
64+
65+
// Style
66+
const [wrapSSR, hashId] = useStyle(prefixCls);
67+
6168
const showCount = computed(() => {
6269
return (props.showCount as any) === '' || props.showCount || false;
6370
});
@@ -198,6 +205,7 @@ export default defineComponent({
198205
[`${prefixCls.value}-lg`]: size.value === 'large',
199206
},
200207
getStatusClassNames(prefixCls.value, mergedStatus.value),
208+
hashId.value,
201209
],
202210
showCount: null,
203211
prefixCls: prefixCls.value,
@@ -252,6 +260,7 @@ export default defineComponent({
252260
direction: direction.value,
253261
bordered,
254262
style: showCount.value ? undefined : style,
263+
hashId: hashId.value,
255264
};
256265

257266
let textareaNode = (
@@ -283,6 +292,7 @@ export default defineComponent({
283292
},
284293
`${prefixCls.value}-textarea-show-count`,
285294
customClass,
295+
hashId.value,
286296
)}
287297
style={style as CSSProperties}
288298
data-count={typeof dataCount !== 'object' ? dataCount : undefined}
@@ -296,7 +306,7 @@ export default defineComponent({
296306
</div>
297307
);
298308
}
299-
return textareaNode;
309+
return wrapSSR(textareaNode);
300310
};
301311
},
302312
});

0 commit comments

Comments
 (0)