Skip to content

Commit

Permalink
Use grid selector hook in the pipe processor. Mutate aria attributes …
Browse files Browse the repository at this point in the history
…directly
  • Loading branch information
arminmeh committed Jun 27, 2024
1 parent b75e0fe commit b616ce8
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
GridStrategyProcessor,
useGridRegisterPipeProcessor,
useGridRegisterStrategyProcessor,
useGridSelector,
} from '@mui/x-data-grid/internals';
import {
GRID_TREE_DATA_GROUPING_COL_DEF,
Expand Down Expand Up @@ -209,18 +210,25 @@ export const useGridTreeDataPreProcessors = (
);

const updateGridRowAriaAttributes = React.useCallback<GridPipeProcessor<'ariaAttributes'>>(
(attributes, rowId) => {
(ariaAttributes, rowId) => {
const rowNode = privateApiRef.current.getRowNode(rowId);
const ariaAttributes = attributes as Record<string, string | number | boolean>;

if (props.treeData !== true || rowNode === null) {
return ariaAttributes;
}

const filteredTopLevelRowCount = gridFilteredTopLevelRowCountSelector(privateApiRef);
const filteredDescendantCountLookup =
gridFilteredDescendantCountLookupSelector(privateApiRef);
const sortedVisibleRowPositionsLookup = gridExpandedSortedRowIdsLookupSelector(privateApiRef);
const filteredTopLevelRowCount = useGridSelector(
privateApiRef,
gridFilteredTopLevelRowCountSelector,
);
const filteredDescendantCountLookup = useGridSelector(
privateApiRef,
gridFilteredDescendantCountLookupSelector,
);
const sortedVisibleRowPositionsLookup = useGridSelector(
privateApiRef,
gridExpandedSortedRowIdsLookupSelector,
);

ariaAttributes['aria-level'] = rowNode.depth + 1;

Expand Down

0 comments on commit b616ce8

Please sign in to comment.