Skip to content

Commit

Permalink
[IndexTable] Don't trigger onSelectionChange() on edges of disabled c…
Browse files Browse the repository at this point in the history
…heckbox
  • Loading branch information
jesstelford committed Apr 22, 2024
1 parent 1539f0e commit a83084b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-ghosts-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': patch
---

Fixed edges of disabled `IndexTable.Row` `Checkbox` triggering selection
18 changes: 16 additions & 2 deletions polaris-react/src/components/IndexTable/components/Row/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ export const Row = memo(function Row({
event.stopPropagation();
let selectionType = SelectionType.Single;

if (('key' in event && event.key !== ' ') || !onSelectionChange) return;
if (
disabled ||
!selectable ||
('key' in event && event.key !== ' ') ||
!onSelectionChange
)
return;

if (event.nativeEvent.shiftKey) {
selectionType = SelectionType.Multi;
Expand All @@ -82,7 +88,15 @@ export const Row = memo(function Row({
const selection: string | Range = selectionRange ?? id;
onSelectionChange(selectionType, !selected, selection, position);
},
[id, onSelectionChange, selected, selectionRange, position],
[
id,
onSelectionChange,
selected,
selectionRange,
position,
disabled,
selectable,
],
);

const contextValue = useMemo(
Expand Down

0 comments on commit a83084b

Please sign in to comment.