Skip to content

Commit f577097

Browse files
fix(text-input-affix): fix right TextInput.Affix alignment with onPress (#4415)
1 parent 1a82b2c commit f577097

File tree

2 files changed

+58
-65
lines changed

2 files changed

+58
-65
lines changed

src/components/TextInput/Adornment/TextInputAffix.tsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,18 @@ const TextInputAffix = ({
153153

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

156-
const affix = (
156+
const content = (
157+
<Text
158+
maxFontSizeMultiplier={maxFontSizeMultiplier}
159+
style={[{ color: textColor }, textStyle, labelStyle]}
160+
onLayout={onTextLayout}
161+
testID={`${testID}-text`}
162+
>
163+
{text}
164+
</Text>
165+
);
166+
167+
return (
157168
<Animated.View
158169
style={[
159170
styles.container,
@@ -169,30 +180,19 @@ const TextInputAffix = ({
169180
onLayout={onLayout}
170181
testID={testID}
171182
>
172-
<Text
173-
maxFontSizeMultiplier={maxFontSizeMultiplier}
174-
style={[{ color: textColor }, textStyle, labelStyle]}
175-
onLayout={onTextLayout}
176-
testID={`${testID}-text`}
177-
>
178-
{text}
179-
</Text>
183+
{onPress ? (
184+
<Pressable
185+
onPress={onPress}
186+
accessibilityRole="button"
187+
accessibilityLabel={accessibilityLabel}
188+
>
189+
{content}
190+
</Pressable>
191+
) : (
192+
content
193+
)}
180194
</Animated.View>
181195
);
182-
183-
if (onPress) {
184-
return (
185-
<Pressable
186-
onPress={onPress}
187-
accessibilityRole="button"
188-
accessibilityLabel={accessibilityLabel}
189-
style={styles.container}
190-
>
191-
{affix}
192-
</Pressable>
193-
);
194-
}
195-
return affix;
196196
};
197197

198198
TextInputAffix.displayName = 'TextInput.Affix';

src/components/__tests__/__snapshots__/TextInput.test.tsx.snap

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -224,61 +224,54 @@ exports[`call onPress when affix adornment pressed 1`] = `
224224
/>
225225
</View>
226226
<View
227-
accessibilityLabel="+39"
228-
accessibilityRole="button"
229-
accessibilityState={
230-
{
231-
"busy": undefined,
232-
"checked": undefined,
233-
"disabled": undefined,
234-
"expanded": undefined,
235-
"selected": undefined,
236-
}
237-
}
238-
accessibilityValue={
239-
{
240-
"max": undefined,
241-
"min": undefined,
242-
"now": undefined,
243-
"text": undefined,
244-
}
245-
}
246-
accessible={true}
247227
collapsable={false}
248-
focusable={true}
249-
onBlur={[Function]}
250-
onClick={[Function]}
251-
onFocus={[Function]}
252-
onMouseEnter={[Function]}
253-
onMouseLeave={[Function]}
254-
onResponderGrant={[Function]}
255-
onResponderMove={[Function]}
256-
onResponderRelease={[Function]}
257-
onResponderTerminate={[Function]}
258-
onResponderTerminationRequest={[Function]}
259-
onStartShouldSetResponder={[Function]}
228+
onLayout={[Function]}
260229
style={
261230
{
262231
"alignItems": "center",
263232
"justifyContent": "center",
233+
"left": 16,
234+
"opacity": 0,
264235
"position": "absolute",
236+
"top": null,
265237
}
266238
}
239+
testID="left-affix-adornment"
267240
>
268241
<View
269-
collapsable={false}
270-
onLayout={[Function]}
271-
style={
242+
accessibilityLabel="+39"
243+
accessibilityRole="button"
244+
accessibilityState={
272245
{
273-
"alignItems": "center",
274-
"justifyContent": "center",
275-
"left": 16,
276-
"opacity": 0,
277-
"position": "absolute",
278-
"top": null,
246+
"busy": undefined,
247+
"checked": undefined,
248+
"disabled": undefined,
249+
"expanded": undefined,
250+
"selected": undefined,
279251
}
280252
}
281-
testID="left-affix-adornment"
253+
accessibilityValue={
254+
{
255+
"max": undefined,
256+
"min": undefined,
257+
"now": undefined,
258+
"text": undefined,
259+
}
260+
}
261+
accessible={true}
262+
collapsable={false}
263+
focusable={true}
264+
onBlur={[Function]}
265+
onClick={[Function]}
266+
onFocus={[Function]}
267+
onMouseEnter={[Function]}
268+
onMouseLeave={[Function]}
269+
onResponderGrant={[Function]}
270+
onResponderMove={[Function]}
271+
onResponderRelease={[Function]}
272+
onResponderTerminate={[Function]}
273+
onResponderTerminationRequest={[Function]}
274+
onStartShouldSetResponder={[Function]}
282275
>
283276
<Text
284277
maxFontSizeMultiplier={1.5}

0 commit comments

Comments
 (0)