Skip to content

Commit 8ef6476

Browse files
authored
fix: calls onLayout on input affix (#3597)
1 parent eece348 commit 8ef6476

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/components/TextInput/Adornment/TextInputAffix.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const TextInputAffix = ({
118118
text,
119119
textStyle: labelStyle,
120120
theme: themeOverrides,
121+
onLayout: onTextLayout,
121122
}: Props) => {
122123
const theme = useInternalTheme(themeOverrides);
123124
const { AFFIX_OFFSET } = getConstants(theme.isV3);
@@ -167,6 +168,8 @@ const TextInputAffix = ({
167168
<Text
168169
maxFontSizeMultiplier={maxFontSizeMultiplier}
169170
style={[{ color: textColor }, textStyle, labelStyle]}
171+
onLayout={onTextLayout}
172+
testID={`${testID}-text`}
170173
>
171174
{text}
172175
</Text>

src/components/__tests__/TextInput.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,28 @@ it('correctly applies padding offset to input label on Android when LTR', () =>
289289
});
290290
});
291291

292+
it('calls onLayout on right-side affix adornment', () => {
293+
const onLayoutMock = jest.fn();
294+
const nativeEventMock = {
295+
nativeEvent: { layout: { height: 100 } },
296+
};
297+
298+
const { getByTestId } = render(
299+
<TextInput
300+
label="Flat input"
301+
placeholder="Type something"
302+
value={'Some test value'}
303+
right={<TextInput.Affix text={affixTextValue} onLayout={onLayoutMock} />}
304+
/>
305+
);
306+
fireEvent(
307+
getByTestId('right-affix-adornment-text'),
308+
'onLayout',
309+
nativeEventMock
310+
);
311+
expect(onLayoutMock).toHaveBeenCalledWith(nativeEventMock);
312+
});
313+
292314
['outlined', 'flat'].forEach((mode) =>
293315
it(`renders ${mode} input with correct line height`, () => {
294316
const input = render(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,7 @@ exports[`correctly renders left-side affix adornment, and right-side icon adornm
12631263
},
12641264
]
12651265
}
1266+
testID="left-affix-adornment-text"
12661267
>
12671268
/100
12681269
</Text>
@@ -1817,6 +1818,7 @@ exports[`correctly renders left-side icon adornment, and right-side affix adornm
18171818
},
18181819
]
18191820
}
1821+
testID="right-affix-adornment-text"
18201822
>
18211823
/100
18221824
</Text>

0 commit comments

Comments
 (0)