MultiCombobox: Fix select all when only a single option is available (#109910)
* Fix condition * Add tests
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user