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

fix(text-input-affix): fix right TextInput.Affix alignment with onPress #4415

Merged
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
46 changes: 23 additions & 23 deletions src/components/TextInput/Adornment/TextInputAffix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,18 @@ const TextInputAffix = ({

const textColor = getTextColor({ theme, disabled });

const affix = (
const content = (
<Text
maxFontSizeMultiplier={maxFontSizeMultiplier}
style={[{ color: textColor }, textStyle, labelStyle]}
onLayout={onTextLayout}
testID={`${testID}-text`}
>
{text}
</Text>
);

return (
<Animated.View
style={[
styles.container,
Expand All @@ -169,30 +180,19 @@ const TextInputAffix = ({
onLayout={onLayout}
testID={testID}
>
<Text
maxFontSizeMultiplier={maxFontSizeMultiplier}
style={[{ color: textColor }, textStyle, labelStyle]}
onLayout={onTextLayout}
testID={`${testID}-text`}
>
{text}
</Text>
{onPress ? (
<Pressable
onPress={onPress}
accessibilityRole="button"
accessibilityLabel={accessibilityLabel}
>
{content}
</Pressable>
) : (
content
)}
</Animated.View>
);

if (onPress) {
return (
<Pressable
onPress={onPress}
accessibilityRole="button"
accessibilityLabel={accessibilityLabel}
style={styles.container}
>
{affix}
</Pressable>
);
}
return affix;
};

TextInputAffix.displayName = 'TextInput.Affix';
Expand Down
77 changes: 35 additions & 42 deletions src/components/__tests__/__snapshots__/TextInput.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -198,61 +198,54 @@ exports[`call onPress when affix adornment pressed 1`] = `
/>
</View>
<View
accessibilityLabel="+39"
accessibilityRole="button"
accessibilityState={
{
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
accessibilityValue={
{
"max": undefined,
"min": undefined,
"now": undefined,
"text": undefined,
}
}
accessible={true}
collapsable={false}
focusable={true}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
onLayout={[Function]}
style={
{
"alignItems": "center",
"justifyContent": "center",
"left": 16,
"opacity": 0,
"position": "absolute",
"top": null,
}
}
testID="left-affix-adornment"
>
<View
collapsable={false}
onLayout={[Function]}
style={
accessibilityLabel="+39"
accessibilityRole="button"
accessibilityState={
{
"alignItems": "center",
"justifyContent": "center",
"left": 16,
"opacity": 0,
"position": "absolute",
"top": null,
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
testID="left-affix-adornment"
accessibilityValue={
{
"max": undefined,
"min": undefined,
"now": undefined,
"text": undefined,
}
}
accessible={true}
collapsable={false}
focusable={true}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
>
<Text
maxFontSizeMultiplier={1.5}
Expand Down
Loading