Skip to content

Commit

Permalink
Use clone in TextField for leadingAccessory to avoid extra wrappers t…
Browse files Browse the repository at this point in the history
…hat break layout (#1705)
  • Loading branch information
ethanshar committed Dec 2, 2021
1 parent 960a723 commit b8d645f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/incubator/TextField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ const TextField = (props: InternalTextFieldProps) => {
return {...fieldState, disabled: others.editable === false, validateField};
}, [fieldState, others.editable, validateField]);

const leadingAccessoryClone = useMemo(() => {
if (leadingAccessory) {
return React.cloneElement(leadingAccessory, {
ref: leadingAccessoryRef
});
}
}, [leadingAccessory]);

const {margins, paddings, typography, color} = modifiers;
const typographyStyle = useMemo(() => omit(typography, 'lineHeight'), [typography]);
const colorStyle = useMemo(() => color && {color}, [color]);
Expand Down Expand Up @@ -188,8 +196,7 @@ const TextField = (props: InternalTextFieldProps) => {
)}
<View style={[paddings, fieldStyle]} row centerV>
{/* <View row centerV> */}
{/* @ts-expect-error */}
{leadingAccessory && <View ref={leadingAccessoryRef}>{leadingAccessory}</View>}
{leadingAccessoryClone}
<View flexG>
{floatingPlaceholder && (
<FloatingPlaceholder
Expand Down

0 comments on commit b8d645f

Please sign in to comment.