Skip to content

Commit

Permalink
fix: datagrid select all behavior in virtual scroll (#6546)
Browse files Browse the repository at this point in the history
  • Loading branch information
devadula-nandan authored Dec 10, 2024
1 parent 336a5b0 commit b80d7f0
Showing 1 changed file with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import React, { useLayoutEffect, useState } from 'react';
import { TableSelectAll } from '@carbon/react';
import cx from 'classnames';
import { pkg } from '../../../settings';
import { handleOnPageSelectAllRowData } from './addons/stateReducer';
import {
handleOnPageSelectAllRowData,
handleSelectAllRowData,
} from './addons/stateReducer';
import { DataGridState, DataGridToggleAllRowsProps } from '../types';

const blockClass = `${pkg.prefix}--datagrid`;
Expand Down Expand Up @@ -41,6 +44,8 @@ const SelectAll = (datagridState: DataGridState) => {
dispatch,
rows,
getRowId,
toggleAllRowsSelected,
withVirtualScroll,
onAllRowSelect,
} = datagridState;
const isFirstColumnStickyLeft =
Expand Down Expand Up @@ -75,6 +80,33 @@ const SelectAll = (datagridState: DataGridState) => {
return onChange?.(event);
};

const handleSelectAllChange = (event) => {
if (indeterminate) {
handleSelectAllRowData({
dispatch,
rows,
getRowId,
indeterminate: true,
isChecked: undefined,
});
toggleAllRowsSelected(false);
onAllRowSelect?.(rows, event);

return onChange?.({
target: { checked: false },
} as any);
}
handleSelectAllRowData({
dispatch,
rows,
getRowId,
isChecked: event.target.checked,
indeterminate,
});
onAllRowSelect?.(rows, event);
return onChange?.(event);
};

return (
<TableSelectAll
{...selectProps}
Expand All @@ -89,7 +121,9 @@ const SelectAll = (datagridState: DataGridState) => {
}
)}
name={`${tableId}-select-all-checkbox-name`}
onSelect={handleOnPageSelectAllChange}
onSelect={
withVirtualScroll ? handleSelectAllChange : handleOnPageSelectAllChange
}
disabled={isFetching || selectProps?.disabled}
id={`${tableId}-select-all-checkbox-id`}
/>
Expand Down

0 comments on commit b80d7f0

Please sign in to comment.