diff --git a/packages/grafana-ui/src/components/Combobox/ComboboxList.tsx b/packages/grafana-ui/src/components/Combobox/ComboboxList.tsx index 16d1bb11a0c..626418213ff 100644 --- a/packages/grafana-ui/src/components/Combobox/ComboboxList.tsx +++ b/packages/grafana-ui/src/components/Combobox/ComboboxList.tsx @@ -67,7 +67,7 @@ export const ComboboxList = ({ [selectedItems] ); - const allItemsSelected = enableAllOption && selectedItems.length === options.length - 1; + const allItemsSelected = enableAllOption && options.length > 1 && selectedItems.length === options.length - 1; return ( @@ -142,6 +142,7 @@ export const ComboboxList = ({ onClick={(e) => { e.stopPropagation(); }} + data-testid={`${itemId}-checkbox`} /> )} diff --git a/packages/grafana-ui/src/components/Combobox/MultiCombobox.test.tsx b/packages/grafana-ui/src/components/Combobox/MultiCombobox.test.tsx index 4d3c1e0abee..572a9d865a0 100644 --- a/packages/grafana-ui/src/components/Combobox/MultiCombobox.test.tsx +++ b/packages/grafana-ui/src/components/Combobox/MultiCombobox.test.tsx @@ -281,6 +281,25 @@ describe('MultiCombobox', () => { await user.type(input, 'b'); expect(screen.getByText('A')).toBeInTheDocument(); }); + + it('should not render All when only one option is available and enableAll is true', async () => { + const options = [{ label: 'A', value: 'a' }]; + render(); + const input = screen.getByRole('combobox'); + await user.click(input); + expect(screen.queryByRole('option', { name: 'All' })).not.toBeInTheDocument(); + }); + + it('should not select option when only one option is available and enableAll is true', async () => { + const options = [{ label: 'A', value: 'a' }]; + render(); + const input = screen.getByRole('combobox'); + await user.click(input); + + const checkbox = screen.getByTestId(`combobox-option-${options[0].value}-checkbox`); + expect(checkbox).toBeInTheDocument(); + expect(checkbox).not.toBeChecked(); + }); }); describe('async', () => {