Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not select group row when checkbox is toggled using keyboard #3246

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Columns.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useRowSelection } from './hooks/useRowSelection';
import { stopPropagation } from './utils';
import type { Column, RenderCellProps, RenderGroupCellProps, RenderHeaderCellProps } from './types';
import { SelectCellFormatter } from './cellRenderers';

Expand Down Expand Up @@ -42,6 +43,7 @@ function SelectGroupFormatter(props: RenderGroupCellProps<unknown>) {
aria-label="Select Group"
tabIndex={props.tabIndex}
value={isRowSelected}
onClick={stopPropagation}
onChange={(checked) => {
onRowSelectionChange({ type: 'ROW', row: props.row, checked, isShiftClick: false });
}}
Expand Down
4 changes: 3 additions & 1 deletion src/cellRenderers/SelectCellFormatter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useDefaultRenderers } from '../DataGridDefaultRenderersProvider';

type SharedInputProps = Pick<
RenderCheckboxProps,
'disabled' | 'tabIndex' | 'aria-label' | 'aria-labelledby'
'aria-label' | 'aria-labelledby' | 'disabled' | 'tabIndex' | 'onClick'
>;

interface SelectCellFormatterProps extends SharedInputProps {
Expand All @@ -15,6 +15,7 @@ export function SelectCellFormatter({
value,
tabIndex,
disabled,
onClick,
onChange,
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledBy
Expand All @@ -27,6 +28,7 @@ export function SelectCellFormatter({
tabIndex,
disabled,
checked: value,
onClick,
onChange
});
}
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export interface RenderSortStatusProps extends RenderSortIconProps, RenderSortPr
export interface RenderCheckboxProps
extends Pick<
React.InputHTMLAttributes<HTMLInputElement>,
'aria-label' | 'aria-labelledby' | 'checked' | 'tabIndex' | 'disabled'
'aria-label' | 'aria-labelledby' | 'checked' | 'tabIndex' | 'disabled' | 'onClick'
> {
onChange: (checked: boolean, shift: boolean) => void;
}
Expand Down
5 changes: 4 additions & 1 deletion test/grouping.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,15 @@ test('should select rows in a group', async () => {
await userEvent.click(checkbox);
selectedRows = screen.getAllByRole('row', { selected: true });
expect(selectedRows).toHaveLength(4);
// clicking on the checkbox should select the row
expect(getRows()[4]).toHaveClass(rowSelectedClassname);

// unselect child group
await userEvent.click(checkbox);
await userEvent.keyboard('{arrowright}" "');
selectedRows = screen.getAllByRole('row', { selected: true });
// eslint-disable-next-line jest-dom/prefer-in-document
expect(selectedRows).toHaveLength(1);
expect(getRows()[4]).not.toHaveClass(rowSelectedClassname);

await userEvent.click(screen.getByRole('gridcell', { name: '2020' }));
await userEvent.click(screen.getByRole('gridcell', { name: '2022' }));
Expand Down