', () => {
});
});
- it('prevents onChange propagation', () => {
- let stopPropagationSpy = false;
- const checkbox = mountWithTable(
);
-
- triggerCheckboxEvent(checkbox, 'onChange', {
- stopPropagation: () => {
- stopPropagationSpy = true;
- },
- });
-
- expect(stopPropagationSpy).toBe(true);
- });
-
it('toggles the checkbox value when clicked', () => {
const onSelectionChange = jest.fn();
const checkbox = mountWithTable(
, {
@@ -82,21 +69,6 @@ describe('
', () => {
expect(onSelectionChange).toHaveBeenCalledWith('single', false, defaultId);
});
- it('toggles the checkbox when spacebar is pressed', () => {
- const onSelectionChange = jest.fn();
- const checkbox = mountWithTable(
, {
- indexProps: {onSelectionChange},
- rowProps: {selected: true},
- });
-
- triggerCheckboxEvent(checkbox, 'onKeyUp', {
- key: ' ',
- nativeEvent: {shiftKey: false},
- });
-
- expect(onSelectionChange).toHaveBeenCalledWith('single', false, defaultId);
- });
-
describe('CheckboxWrapper', () => {
describe('small screen', () => {
const defaultTableProps = {
diff --git a/src/components/IndexTable/components/Row/Row.tsx b/src/components/IndexTable/components/Row/Row.tsx
index 5a7d46a8f9f..aac8ffe81b3 100644
--- a/src/components/IndexTable/components/Row/Row.tsx
+++ b/src/components/IndexTable/components/Row/Row.tsx
@@ -43,6 +43,7 @@ export const Row = memo(function Row({
const handleInteraction = useCallback(
(event: React.MouseEvent | React.KeyboardEvent) => {
event.stopPropagation();
+
if (('key' in event && event.key !== ' ') || !onSelectionChange) return;
const selectionType = event.nativeEvent.shiftKey
? SelectionType.Multi
@@ -97,7 +98,6 @@ export const Row = memo(function Row({
if (!tableRowRef.current || isNavigating.current) {
return;
}
-
event.stopPropagation();
event.preventDefault();