Skip to content

Commit

Permalink
fix(RAC): Select when label is numeric 0 (adobe#6968)
Browse files Browse the repository at this point in the history
fixes adobe#6961

Co-authored-by: Homa Wong <[email protected]>
  • Loading branch information
unional and Homa Wong committed Aug 28, 2024
1 parent 32574f8 commit a5679cd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/react-aria-components/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function SelectValue<T extends object>(props: SelectValueProps<T>, ref: Forwarde

let renderProps = useRenderProps({
...props,
defaultChildren: rendered || placeholder || stringFormatter.format('selectPlaceholder'),
defaultChildren: rendered ?? placeholder ?? stringFormatter.format('selectPlaceholder'),
defaultClassName: 'react-aria-SelectValue',
values: {
selectedItem: state.selectedItem?.value as T ?? null,
Expand Down
29 changes: 29 additions & 0 deletions packages/react-aria-components/test/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,33 @@ describe('Select', () => {
expect(button).not.toHaveAttribute('aria-describedby');
expect(select).not.toHaveAttribute('data-invalid');
});

it('should support falsy (0) as a valid default value', async () => {
let {getByRole} = render(
<Select placeholder="pick a number">
<Label>Pick a number</Label>
<Button>
<SelectValue />
</Button>
<Popover>
<ListBox
items={Array.from({length: 5}).map((_, i) => ({
id: i,
label: i
}))}>
{(item) => <ListBoxItem id={item.id} textValue={`${item.label}`}>{item.label}</ListBoxItem>}
</ListBox>
</Popover>
</Select>
);

let button = getByRole('button');
await user.click(button);

let listbox = getByRole('listbox');
let options = within(listbox).getAllByRole('option');
await user.click(options[0]);

expect(button).toHaveTextContent('0');
});
});

0 comments on commit a5679cd

Please sign in to comment.