Skip to content
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
1 change: 1 addition & 0 deletions .github/instructions/code.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ applyTo: '**/*.{ts,tsx,js,jsx}'
- Verify that components forward relevant native props and events without changing their meaning.
- Ensure controlled values have callbacks to update them. Support uncontrolled input when controlled rendering causes a demonstrated performance or reliability problem.
- Merge consumer styles after defaults for supported overrides. Check that computed styles preserve supplied padding, colors, dimensions, and other supported values.
- 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`.
- 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.

## Design and Accessibility
Expand Down
12 changes: 12 additions & 0 deletions docs/6.x/docs/guides/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,18 @@ const [value, setValue] = React.useState('');
/>
```

#### Icon size

`TextInput.Icon`'s `size` is renamed `iconSize`, as on `IconButton`, where `size` is now a named container scale.

```tsx
// Before (v5)
<TextInput.Icon icon="magnify" size={20} />

// After (v6)
<TextInput.Icon icon="magnify" iconSize={20} />
```

#### Label and supporting text

- **`label: React.Element | string`** → **`string`**
Expand Down
11 changes: 2 additions & 9 deletions src/components/TextInput/TextInputIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ export type TextInputAccessoryProps = {
};

export type TextInputIconProps = TextInputAccessoryProps &
Omit<IconButtonProps, keyof TextInputAccessoryProps | 'size' | 'iconSize'> & {
/**
* Size of the icon. `iconSize` isn't accepted: the size comes from here.
*/
size?: number;
};
Omit<IconButtonProps, keyof TextInputAccessoryProps | 'size'>;

/**
* A component to render a leading / trailing icon in the TextInput
Expand Down Expand Up @@ -79,7 +74,7 @@ export type TextInputIconProps = TextInputAccessoryProps &
const TextInputIcon = ({
icon,
iconColor,
size,
iconSize = ACCESSORY_SIZE,
style,
error,
disabled,
Comment thread
lukewalczak marked this conversation as resolved.
Resolved
Expand All @@ -91,8 +86,6 @@ const TextInputIcon = ({
}: TextInputIconProps) => {
const theme = useInternalTheme(themeOverride);

const iconSize = size ?? ACCESSORY_SIZE;

const color = getIconColor({
theme,
iconColor,
Expand Down
33 changes: 30 additions & 3 deletions src/components/__tests__/TextInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1824,14 +1824,41 @@
});
});

it('takes the glyph size from `size`, not `iconSize`', async () => {
it('sizes the TextInput.Icon glyph with `iconSize`', async () => {
await render(
<TextInput
label="Search"
value=""
startAccessory={(props) => (
// @ts-expect-error `iconSize` is not a TextInput.Icon prop
<TextInput.Icon {...props} icon="magnify" size={30} iconSize={12} />
<TextInput.Icon
{...props}
iconSize={12}
icon={({ size }) => (
<View testID="glyph" style={{ width: size, height: size }} />
)}
/>
)}
/>
);

expect(screen.getByTestId('glyph', includeHiddenElements)).toHaveStyle({
width: 12,
height: 12,
});
});

it('rejects the named `size` on TextInput.Icon', async () => {
await render(
<TextInput
label="Search"
value=""
startAccessory={(props) => (
<TextInput.Icon
{...props}
icon="magnify"
// @ts-expect-error `size` is not a TextInput.Icon prop
size="small"
/>

Check notice on line 1861 in src/components/__tests__/TextInput.test.tsx

View check run for this annotation

apex-sentinel-staging / Apex Sentinel

nit: "rejects the named `size`" test asserts nothing about `size`; only the @ts-expect-error works

The test named "rejects the named `size` on `TextInput.Icon`" proves the type rule solely through its `@ts-expect-error` comment; the render and `getByLabelText('Search')` assertion check the field, not the icon, and are inert scaffolding. Drop the render and the assertion, keeping the `@ts-expect-error` as a type-only block.
Comment on lines +1851 to +1861

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆕 🔵 Nit · "rejects the named size" test asserts nothing about size; only the @​ts-expect-error works

The test named "rejects the named size on TextInput.Icon" proves the type rule solely through its @ts-expect-error comment; the render and getByLabelText('Search') assertion check the field, not the icon, and are inert scaffolding. Drop the render and the assertion, keeping the @ts-expect-error as a type-only block.

Suggested change

Keep the size rejection as a type-level assertion only; remove the render and the empty test body, or move the @ts-expect-error into an existing type-check fixture.

Details

persona: maintainability

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

)}
/>
);
Expand Down
Loading