Skip to content

Commit b8d645f

Browse files
committed
Use clone in TextField for leadingAccessory to avoid extra wrappers that break layout (#1705)
1 parent 960a723 commit b8d645f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/incubator/TextField/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ const TextField = (props: InternalTextFieldProps) => {
159159
return {...fieldState, disabled: others.editable === false, validateField};
160160
}, [fieldState, others.editable, validateField]);
161161

162+
const leadingAccessoryClone = useMemo(() => {
163+
if (leadingAccessory) {
164+
return React.cloneElement(leadingAccessory, {
165+
ref: leadingAccessoryRef
166+
});
167+
}
168+
}, [leadingAccessory]);
169+
162170
const {margins, paddings, typography, color} = modifiers;
163171
const typographyStyle = useMemo(() => omit(typography, 'lineHeight'), [typography]);
164172
const colorStyle = useMemo(() => color && {color}, [color]);
@@ -188,8 +196,7 @@ const TextField = (props: InternalTextFieldProps) => {
188196
)}
189197
<View style={[paddings, fieldStyle]} row centerV>
190198
{/* <View row centerV> */}
191-
{/* @ts-expect-error */}
192-
{leadingAccessory && <View ref={leadingAccessoryRef}>{leadingAccessory}</View>}
199+
{leadingAccessoryClone}
193200
<View flexG>
194201
{floatingPlaceholder && (
195202
<FloatingPlaceholder

0 commit comments

Comments
 (0)