MultiCombobox: Fix select all when only a single option is available (#109910)

* Fix condition

* Add tests
This commit is contained in:
Andreas Christou
2025-08-21 11:19:33 +01:00
committed by GitHub
parent 0262a23d7f
commit 8f1ba9acef
2 changed files with 21 additions and 1 deletions
@@ -67,7 +67,7 @@ export const ComboboxList = <T extends string | number>({
[selectedItems]
);
const allItemsSelected = enableAllOption && selectedItems.length === options.length - 1;
const allItemsSelected = enableAllOption && options.length > 1 && selectedItems.length === options.length - 1;
return (
<ScrollContainer showScrollIndicators maxHeight="inherit" ref={scrollRef} padding={0.5}>
@@ -142,6 +142,7 @@ export const ComboboxList = <T extends string | number>({
onClick={(e) => {
e.stopPropagation();
}}
data-testid={`${itemId}-checkbox`}
/>
)}
</div>
@@ -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(<MultiCombobox width={200} options={options} onChange={jest.fn()} enableAllOption />);
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(<MultiCombobox width={200} options={options} onChange={jest.fn()} enableAllOption />);
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', () => {