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
25 changes: 25 additions & 0 deletions packages/react/components/select/__tests__/select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,5 +329,30 @@ describe('Select', () => {
expect(options[0]).toHaveTextContent('Apple');
expect(options[1]).toHaveTextContent('Pineapple');
});

it('shows a controlled searchValue in the search input', async () => {
render(<BasicSelect autocomplete searchValue='app' />);

fireEvent.click(screen.getByLabelText('Select option'));
await flushMicrotasks();
const searchInput = screen.getByPlaceholderText('Search...');
fireEvent.change(searchInput, { target: { value: 'b' } });
await flushMicrotasks();

expect(searchInput).toHaveValue('app');
});

it('shows and filters by defaultSearchValue', async () => {
render(<BasicSelect autocomplete defaultSearchValue='app' />);

fireEvent.click(screen.getByLabelText('Select option'));
await flushMicrotasks();

expect(screen.getByPlaceholderText('Search...')).toHaveValue('app');
const options = screen.getAllByRole('option');
expect(options.length).toBe(2);
expect(options[0]).toHaveTextContent('Apple');
expect(options[1]).toHaveTextContent('Pineapple');
});
});
});
2 changes: 2 additions & 0 deletions packages/react/components/select/select-root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ export const SelectRoot = (props: SelectRootProps) => {
<SelectContext value={contextValue}>
<ComboboxPrimitive.Root
{...commonProps}
inputValue={providedSearchValue}
defaultInputValue={defaultSearchValue}
onInputValueChange={handleSearchValueChange}
filter={itemsProp ? undefined : null}
items={itemsProp}
Expand Down
Loading