Skip to content

Commit 1726f7a

Browse files
authored
feat(BulkSelect): disable Select none option when no rows are selected (#914)
* feat(BulkSelect): disable Select none when no rows are selected * test(BulkSelect): add unit tests for disabling Select none option AssistedBy: Cursor
1 parent a46b56b commit 1726f7a

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

packages/module/src/BulkSelect/BulkSelect.test.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,40 @@ describe('BulkSelect component', () => {
100100
expect(screen.getByText('Sélectionner la page (5)')).toBeInTheDocument();
101101
expect(screen.getByText('Tout sélectionner (10)')).toBeInTheDocument();
102102
});
103+
104+
test('should disable Select none when nothing is selected', async () => {
105+
const user = userEvent.setup();
106+
render(
107+
<BulkSelect
108+
canSelectAll
109+
pageCount={5}
110+
totalCount={10}
111+
selectedCount={0}
112+
pageSelected={false}
113+
pagePartiallySelected={false}
114+
onSelect={() => null}
115+
/>
116+
);
117+
118+
await user.click(screen.getByLabelText('Bulk select toggle'));
119+
expect(screen.getByRole('menuitem', { name: 'Select none (0)' })).toBeDisabled();
120+
});
121+
122+
test('should enable Select none when at least one row is selected', async () => {
123+
const user = userEvent.setup();
124+
render(
125+
<BulkSelect
126+
canSelectAll
127+
pageCount={5}
128+
totalCount={10}
129+
selectedCount={1}
130+
pageSelected={false}
131+
pagePartiallySelected={true}
132+
onSelect={() => null}
133+
/>
134+
);
135+
136+
await user.click(screen.getByLabelText('Bulk select toggle'));
137+
expect(screen.getByRole('menuitem', { name: 'Select none (0)' })).not.toBeDisabled();
138+
});
103139
});

packages/module/src/BulkSelect/BulkSelect.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ export const BulkSelect: FC<BulkSelectProps> = ({
8888
const splitButtonDropdownItems = useMemo(
8989
() => (
9090
<>
91-
<DropdownItem ouiaId={`${ouiaId}-select-none`} value={BulkSelectValue.none} key={BulkSelectValue.none}>
91+
<DropdownItem
92+
ouiaId={`${ouiaId}-select-none`}
93+
value={BulkSelectValue.none}
94+
key={BulkSelectValue.none}
95+
isDisabled={selectedCount === 0}
96+
>
9297
{selectNoneLabel}
9398
</DropdownItem>
9499
{isDataPaginated && (
@@ -103,7 +108,7 @@ export const BulkSelect: FC<BulkSelectProps> = ({
103108
)}
104109
</>
105110
),
106-
[ isDataPaginated, canSelectAll, ouiaId, selectNoneLabel, selectPageLabel, selectAllLabel, pageCount, totalCount ]
111+
[ isDataPaginated, canSelectAll, ouiaId, selectNoneLabel, selectPageLabel, selectAllLabel, pageCount, totalCount, selectedCount ]
107112
);
108113

109114
const selectedLabelText = selectedLabel(selectedCount);

0 commit comments

Comments
 (0)