Skip to content
Open
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
2 changes: 1 addition & 1 deletion packages/react-aria-components/src/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ function ComboBoxInner<T extends object>({props, collection, comboBoxRef: ref}:
let validationBehavior = props.validationBehavior ?? formValidationBehavior ?? 'native';
let {contains} = useFilter({sensitivity: 'base'});
let state = useComboBoxState({
defaultFilter: props.defaultFilter || contains,
...props,
defaultFilter: props.defaultFilter || contains,
// If props.items isn't provided, rely on collection filtering (aka listbox.items is provided or defaultItems provided to Combobox)
items: props.items,
children: undefined,
Expand Down
42 changes: 40 additions & 2 deletions packages/react-aria-components/test/ComboBox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,44 @@ describe('ComboBox', () => {
expect(options).toHaveLength(1);
});

it('should support undefined defaultFilter', async () => {
let tree = render(
<ComboBox defaultFilter={undefined}>
<Label>Preferred fruit or vegetable</Label>
<Input />
<Button />
<Popover>
<ListBox>
<ListBoxSection>
<Header>Fruit</Header>
<ListBoxItem id="Apple">Apple</ListBoxItem>
<ListBoxItem id="Banana">Banana</ListBoxItem>
</ListBoxSection>
<ListBoxSection>
<Header>Vegetable</Header>
<ListBoxItem id="Cabbage">Cabbage</ListBoxItem>
<ListBoxItem id="Broccoli">Broccoli</ListBoxItem>
</ListBoxSection>
</ListBox>
</Popover>
</ComboBox>
);

let comboboxTester = testUtilUser.createTester('ComboBox', {root: tree.container});
act(() => {
comboboxTester.combobox.focus();
});
await user.keyboard('p');

let groups = comboboxTester.sections;
expect(groups).toHaveLength(1);
expect(groups[0]).toHaveAttribute('aria-labelledby');
expect(document.getElementById(groups[0].getAttribute('aria-labelledby'))).toHaveTextContent('Fruit');

let options = within(groups[0]).getAllByRole('option');
expect(options).toHaveLength(1);
});

it('should support dynamic collections', async () => {
let defaultItems = [
{id: 1, name: 'Cat'},
Expand Down Expand Up @@ -413,7 +451,7 @@ describe('ComboBox', () => {
let onAction = jest.fn();
function WithCreateOption() {
let [inputValue, setInputValue] = useState('');

return (
<ComboBox
allowsEmptyCollection
Expand Down Expand Up @@ -464,7 +502,7 @@ describe('ComboBox', () => {
}
expect(onAction).toHaveBeenCalledTimes(1);
expect(comboboxTester.combobox).toHaveValue('');

// Repeat with an option selected.
await comboboxTester.selectOption({option: 'Cat'});

Expand Down