Skip to content

Commit

Permalink
fix(withTableSelection): range select must ignore disabled lines (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeraS authored Dec 12, 2022
1 parent 2fdab3f commit 5b50237
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/components/Table/hoc/withTableSelection/withTableSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function withTableSelection<I extends TableDataItem, E extends {} = {}>(
}: {
checked: boolean;
disabled: boolean;
handler: any;
handler: React.ChangeEventHandler<HTMLInputElement>;
}) {
return (
<Checkbox
Expand Down Expand Up @@ -122,18 +122,19 @@ export function withTableSelection<I extends TableDataItem, E extends {} = {}>(
const begin = Math.min(this.lastCheckedIndex, index);
const end = Math.max(this.lastCheckedIndex, index);

const dataIds = data.map((item, index) => Table.getRowId(this.props, item, index));
const diffIds = dataIds.slice(begin, end + 1);

this.lastCheckedIndex = index;
const dataIds = data.map((item, i) => Table.getRowId(this.props, item, i));
const diffIds = dataIds.filter(
(_id, i) => begin <= i && i <= end && !this.isDisabled(data[i], i),
);

return onSelectionChange(
onSelectionChange(
checked ? _union(selectedIds, diffIds) : _without(selectedIds, ...diffIds),
);
} else {
onSelectionChange(checked ? [...selectedIds, id] : _without(selectedIds, id));
}

this.lastCheckedIndex = index;
onSelectionChange(checked ? [...selectedIds, id] : _without(selectedIds, id));
};

private handleAllCheckBoxUpdate = (event: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -151,7 +152,7 @@ export function withTableSelection<I extends TableDataItem, E extends {} = {}>(
);
};

// eslint-disable-next-line @typescript-eslint/member-ordering
// eslint-disable-next-line @typescript-eslint/member-ordering, react/sort-comp
private enhanceColumns = _memoize((columns: TableColumnConfig<I>[]) => {
const selectionColumn: TableColumnConfig<I> = {
id: selectionColumnId,
Expand Down Expand Up @@ -185,7 +186,7 @@ export function withTableSelection<I extends TableDataItem, E extends {} = {}>(
`.${checkboxClassName}, .${checkboxClassName} *`,
)
) {
return;
return undefined;
}

return onRowClick(item, index, event);
Expand Down

0 comments on commit 5b50237

Please sign in to comment.