Skip to content

Commit ef1e41c

Browse files
authored
feat(text-input)!: rename TextInput.Icon size to iconSize (#5262)
TextInput.Icon takes `iconSize` for its glyph instead of `size`, as on IconButton, where `size` is now a named container scale. Passing `size` is a type error. - The migration guide's TextInput section gets an "Icon size" entry. - `.github/instructions/code.instructions.md` names the convention: `size` sizes the whole component, `iconSize` only the icon glyph inside it. - A test checks that the glyph follows `iconSize`. BREAKING CHANGE: TextInput.Icon's `size` is renamed `iconSize`, matching IconButton.
1 parent 86b9988 commit ef1e41c

4 files changed

Lines changed: 45 additions & 12 deletions

File tree

‎.github/instructions/code.instructions.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ applyTo: '**/*.{ts,tsx,js,jsx}'
3737
- Verify that components forward relevant native props and events without changing their meaning.
3838
- Ensure controlled values have callbacks to update them. Support uncontrolled input when controlled rendering causes a demonstrated performance or reliability problem.
3939
- Merge consumer styles after defaults for supported overrides. Check that computed styles preserve supplied padding, colors, dimensions, and other supported values.
40+
- Name size props by what they size: `size` for the whole component (a named scale such as `'small'` or a number), `iconSize` for only the icon glyph inside it. A component that is itself an icon, such as `Icon`, uses `size`.
4041
- Expose test IDs for public interaction or content. Avoid IDs on internal wrappers solely for tests and default IDs that can collide across component instances.
4142

4243
## Design and Accessibility

‎docs/6.x/docs/guides/migration.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,18 @@ const [value, setValue] = React.useState('');
933933
/>
934934
```
935935

936+
#### Icon size
937+
938+
`TextInput.Icon`'s `size` is renamed `iconSize`, as on `IconButton`, where `size` is now a named container scale.
939+
940+
```tsx
941+
// Before (v5)
942+
<TextInput.Icon icon="magnify" size={20} />
943+
944+
// After (v6)
945+
<TextInput.Icon icon="magnify" iconSize={20} />
946+
```
947+
936948
#### Label and supporting text
937949

938950
- **`label: React.Element | string`** → **`string`**

‎src/components/TextInput/TextInputIcon.tsx‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ export type TextInputAccessoryProps = {
2626
};
2727

2828
export type TextInputIconProps = TextInputAccessoryProps &
29-
Omit<IconButtonProps, keyof TextInputAccessoryProps | 'size' | 'iconSize'> & {
30-
/**
31-
* Size of the icon. `iconSize` isn't accepted: the size comes from here.
32-
*/
33-
size?: number;
34-
};
29+
Omit<IconButtonProps, keyof TextInputAccessoryProps | 'size'>;
3530

3631
/**
3732
* A component to render a leading / trailing icon in the TextInput
@@ -79,7 +74,7 @@ export type TextInputIconProps = TextInputAccessoryProps &
7974
const TextInputIcon = ({
8075
icon,
8176
iconColor,
82-
size,
77+
iconSize = ACCESSORY_SIZE,
8378
style,
8479
error,
8580
disabled,
@@ -91,8 +86,6 @@ const TextInputIcon = ({
9186
}: TextInputIconProps) => {
9287
const theme = useInternalTheme(themeOverride);
9388

94-
const iconSize = size ?? ACCESSORY_SIZE;
95-
9689
const color = getIconColor({
9790
theme,
9891
iconColor,

‎src/components/__tests__/TextInput.test.tsx‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,14 +1824,41 @@ it('keeps the 48dp TextInput.Icon target when a forwarded hitSlop is undefined',
18241824
});
18251825
});
18261826

1827-
it('takes the glyph size from `size`, not `iconSize`', async () => {
1827+
it('sizes the TextInput.Icon glyph with `iconSize`', async () => {
18281828
await render(
18291829
<TextInput
18301830
label="Search"
18311831
value=""
18321832
startAccessory={(props) => (
1833-
// @ts-expect-error `iconSize` is not a TextInput.Icon prop
1834-
<TextInput.Icon {...props} icon="magnify" size={30} iconSize={12} />
1833+
<TextInput.Icon
1834+
{...props}
1835+
iconSize={12}
1836+
icon={({ size }) => (
1837+
<View testID="glyph" style={{ width: size, height: size }} />
1838+
)}
1839+
/>
1840+
)}
1841+
/>
1842+
);
1843+
1844+
expect(screen.getByTestId('glyph', includeHiddenElements)).toHaveStyle({
1845+
width: 12,
1846+
height: 12,
1847+
});
1848+
});
1849+
1850+
it('rejects the named `size` on TextInput.Icon', async () => {
1851+
await render(
1852+
<TextInput
1853+
label="Search"
1854+
value=""
1855+
startAccessory={(props) => (
1856+
<TextInput.Icon
1857+
{...props}
1858+
icon="magnify"
1859+
// @ts-expect-error `size` is not a TextInput.Icon prop
1860+
size="small"
1861+
/>
18351862
)}
18361863
/>
18371864
);

0 commit comments

Comments
 (0)