Skip to content

TextField - only use leadingAccessoryRef when needed (i.e. floatingPlaceholder={true}) #3197

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

Merged
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
14 changes: 9 additions & 5 deletions src/components/textField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const TextField = (props: InternalTextFieldProps) => {
labelStyle,
labelProps,
// Accessory Buttons
leadingAccessory,
leadingAccessory: propsLeadingAccessory,
trailingAccessory,
topTrailingAccessory,
bottomAccessory,
Expand Down Expand Up @@ -107,12 +107,16 @@ const TextField = (props: InternalTextFieldProps) => {
}, [fieldState, others.editable, readonly, validateField, checkValidity]);

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

const leadingAccessory = useMemo(() => {
return floatingPlaceholder ? leadingAccessoryClone : propsLeadingAccessory;
}, [floatingPlaceholder, leadingAccessoryClone, propsLeadingAccessory]);

const {margins, paddings, typography, positionStyle, color} = modifiers;
const typographyStyle = useMemo(() => omit(typography, 'lineHeight'), [typography]);
Expand Down Expand Up @@ -161,7 +165,7 @@ const TextField = (props: InternalTextFieldProps) => {
</View>
<View style={[paddings, fieldStyle]} row centerV centerH={centered}>
{/* <View row centerV> */}
{leadingAccessoryClone}
{leadingAccessory}

{/* Note: We're passing flexG to the View to support properly inline behavior - so the input will be rendered correctly in a row container.
Known Issue: This slightly push the trailing accessory and clear button when entering a long text
Expand Down