Skip to content

Commit a5679cd

Browse files
unionalHoma Wong
andauthored
fix(RAC): Select when label is numeric 0 (#6968)
fixes #6961 Co-authored-by: Homa Wong <[email protected]>
1 parent 32574f8 commit a5679cd

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/react-aria-components/src/Select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ function SelectValue<T extends object>(props: SelectValueProps<T>, ref: Forwarde
257257

258258
let renderProps = useRenderProps({
259259
...props,
260-
defaultChildren: rendered || placeholder || stringFormatter.format('selectPlaceholder'),
260+
defaultChildren: rendered ?? placeholder ?? stringFormatter.format('selectPlaceholder'),
261261
defaultClassName: 'react-aria-SelectValue',
262262
values: {
263263
selectedItem: state.selectedItem?.value as T ?? null,

packages/react-aria-components/test/Select.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,33 @@ describe('Select', () => {
243243
expect(button).not.toHaveAttribute('aria-describedby');
244244
expect(select).not.toHaveAttribute('data-invalid');
245245
});
246+
247+
it('should support falsy (0) as a valid default value', async () => {
248+
let {getByRole} = render(
249+
<Select placeholder="pick a number">
250+
<Label>Pick a number</Label>
251+
<Button>
252+
<SelectValue />
253+
</Button>
254+
<Popover>
255+
<ListBox
256+
items={Array.from({length: 5}).map((_, i) => ({
257+
id: i,
258+
label: i
259+
}))}>
260+
{(item) => <ListBoxItem id={item.id} textValue={`${item.label}`}>{item.label}</ListBoxItem>}
261+
</ListBox>
262+
</Popover>
263+
</Select>
264+
);
265+
266+
let button = getByRole('button');
267+
await user.click(button);
268+
269+
let listbox = getByRole('listbox');
270+
let options = within(listbox).getAllByRole('option');
271+
await user.click(options[0]);
272+
273+
expect(button).toHaveTextContent('0');
274+
});
246275
});

0 commit comments

Comments
 (0)