Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(1200): disable typeahead dropdown field on unknown value #1215

Merged
merged 1 commit into from
Jun 28, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,22 @@ describe('TypeaheadField', () => {
expect(inputElement).toHaveValue('');
expect(mockOnChange).toHaveBeenCalledWith(undefined, {});
});

it('should be disabled when there are no matching elements', async () => {
render(
<TypeaheadEditor
selectOptions={initialDataFormatOptions}
title="Test"
selected={undefined}
selectedModel={undefined}
selectedSchema={undefined}
selectionOnChange={mockOnChange}
/>,
);
const inputElement = screen.getByRole('combobox');
await act(async () => {
fireEvent.change(inputElement, { target: { value: 'no-matching-elements' } });
});
expect(screen.getByText('No results found for "no-matching-elements"').closest('button')).toBeDisabled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const TypeaheadEditor: FunctionComponent<TypeaheadEditorProps> = (props)
// When no options are found after filtering, display 'No results found'
if (!newSelectOptions.length) {
newSelectOptions = [
{ isDisabled: false, children: `No results found for "${filterValue}"`, value: 'no results' },
{ isDisabled: true, children: `No results found for "${filterValue}"`, value: 'no results' },
];
}
// Open the menu when the input value changes and the new value is not empty
Expand Down
Loading