@grafana/ui: Add support for showing selected options in Select ()

* Add support for showing selected options

* Don't set a default to avoid breaking existing
This commit is contained in:
Andreas Christou 2023-04-12 18:05:52 +01:00 committed by GitHub
parent 4ea7677bff
commit c5172247a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions
packages/grafana-ui/src/components/Select

View File

@ -206,5 +206,16 @@ describe('SelectBase', () => {
{ action: 'select-option', name: undefined, option: undefined }
);
});
it('hideSelectedOptions prop - when false does not hide selected', async () => {
render(<SelectBase onChange={jest.fn()} options={options} aria-label="My select" hideSelectedOptions={false} />);
const selectEl = screen.getByLabelText('My select');
await selectOptionInTest(selectEl, 'Option 2');
await userEvent.click(screen.getByText(/option 2/i));
const menuOptions = screen.getAllByLabelText('Select option');
expect(menuOptions).toHaveLength(2);
});
});
});

View File

@ -144,6 +144,7 @@ export function SelectBase<T>({
width,
isValidNewOption,
formatOptionLabel,
hideSelectedOptions,
}: SelectBaseProps<T>) {
const theme = useTheme2();
const styles = getSelectStyles(theme);
@ -222,6 +223,7 @@ export function SelectBase<T>({
filterOption,
getOptionLabel,
getOptionValue,
hideSelectedOptions,
inputValue,
invalid,
isClearable,

View File

@ -37,6 +37,7 @@ export interface SelectCommonProps<T> {
formatCreateLabel?: (input: string) => string;
getOptionLabel?: (item: SelectableValue<T>) => React.ReactNode;
getOptionValue?: (item: SelectableValue<T>) => string;
hideSelectedOptions?: boolean;
inputValue?: string;
invalid?: boolean;
isClearable?: boolean;