@mui/x-data-grid-pro
Version:
The Pro plan edition of the MUI X Data Grid components.
45 lines (42 loc) • 2.63 kB
JavaScript
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useGridRowAriaAttributesPro = void 0;
var React = _interopRequireWildcard(require("react"));
var _xDataGrid = require("@mui/x-data-grid");
var _internals = require("@mui/x-data-grid/internals");
var _useGridPrivateApiContext = require("../../utils/useGridPrivateApiContext");
var _useGridRootProps = require("../../utils/useGridRootProps");
const useGridRowAriaAttributesPro = addTreeDataAttributes => {
const apiRef = (0, _useGridPrivateApiContext.useGridPrivateApiContext)();
const props = (0, _useGridRootProps.useGridRootProps)();
const getRowAriaAttributesCommunity = (0, _internals.useGridRowAriaAttributes)();
const filteredTopLevelRowCount = (0, _xDataGrid.useGridSelector)(apiRef, _xDataGrid.gridFilteredTopLevelRowCountSelector);
const filteredChildrenCountLookup = (0, _xDataGrid.useGridSelector)(apiRef, _internals.gridFilteredChildrenCountLookupSelector);
const sortedVisibleRowPositionsLookup = (0, _xDataGrid.useGridSelector)(apiRef, _internals.gridExpandedSortedRowTreeLevelPositionLookupSelector);
return React.useCallback((rowNode, index) => {
const ariaAttributes = getRowAriaAttributesCommunity(rowNode, index);
if (!rowNode || !(props.treeData || addTreeDataAttributes)) {
return ariaAttributes;
}
// pinned and footer rows are not part of the rowgroup and should not get the set specific aria attributes
if (rowNode.type === 'footer' || rowNode.type === 'pinnedRow') {
return ariaAttributes;
}
ariaAttributes['aria-level'] = rowNode.depth + 1;
const filteredChildrenCount = filteredChildrenCountLookup[rowNode.id] ?? 0;
// aria-expanded should only be added to the rows that contain children
if (rowNode.type === 'group' && filteredChildrenCount > 0) {
ariaAttributes['aria-expanded'] = Boolean(rowNode.childrenExpanded);
}
// if the parent is null, set size and position cannot be determined
if (rowNode.parent !== null) {
ariaAttributes['aria-setsize'] = rowNode.parent === _xDataGrid.GRID_ROOT_GROUP_ID ? filteredTopLevelRowCount : filteredChildrenCountLookup[rowNode.parent];
ariaAttributes['aria-posinset'] = sortedVisibleRowPositionsLookup[rowNode.id];
}
return ariaAttributes;
}, [props.treeData, addTreeDataAttributes, filteredTopLevelRowCount, filteredChildrenCountLookup, sortedVisibleRowPositionsLookup, getRowAriaAttributesCommunity]);
};
exports.useGridRowAriaAttributesPro = useGridRowAriaAttributesPro;
;