Skip to content

Commit

Permalink
Do not wrap aria attributes getter into an object
Browse files Browse the repository at this point in the history
  • Loading branch information
arminmeh committed Jul 4, 2024
1 parent abd3b1c commit 0be3e83
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { useGridRootProps } from '../../utils/useGridRootProps';
export const useGridRowAriaAttributes = () => {
const apiRef = useGridPrivateApiContext();
const props = useGridRootProps();
const { getRowAriaAttributes: getRowAriaAttributesCommunity } =
useGridRowAriaAttributesCommunity();
const getRowAriaAttributesCommunity = useGridRowAriaAttributesCommunity();

const filteredTopLevelRowCount = useGridSelector(apiRef, gridFilteredTopLevelRowCountSelector);
const filteredChildrenCountLookup = useGridSelector(
Expand All @@ -27,7 +26,7 @@ export const useGridRowAriaAttributes = () => {
gridExpandedSortedRowIdsLookupSelector,
);

const getRowAriaAttributes = React.useCallback(
return React.useCallback(
(rowId: GridRowId, index: number) => {
const rowNode = apiRef.current.getRowNode(rowId);
const ariaAttributes = getRowAriaAttributesCommunity(rowId, index);
Expand Down Expand Up @@ -64,6 +63,4 @@ export const useGridRowAriaAttributes = () => {
getRowAriaAttributesCommunity,
],
);

return { getRowAriaAttributes };
};
2 changes: 1 addition & 1 deletion packages/x-data-grid/src/components/GridRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const GridRow = React.forwardRef<HTMLDivElement, GridRowProps>(function GridRow(
};

const classes = useUtilityClasses(ownerState);
const { getRowAriaAttributes } = configuration.hooks.useGridRowAriaAttributes();
const getRowAriaAttributes = configuration.hooks.useGridRowAriaAttributes();

React.useLayoutEffect(() => {
if (currentPage.range) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const useGridRowAriaAttributes: GridRowInternalHook = () => {
const selectedIdsLookup = useGridSelector(apiRef, selectedIdsLookupSelector);
const headerGroupingMaxDepth = useGridSelector(apiRef, gridColumnGroupsHeaderMaxDepthSelector);

const getRowAriaAttributes = React.useCallback(
return React.useCallback(
(rowId: GridRowId, index: number) => {
const rowNode = apiRef.current.getRowNode(rowId);
const ariaAttributes = {} as Record<string, string | number | boolean>;
Expand All @@ -31,6 +31,4 @@ export const useGridRowAriaAttributes: GridRowInternalHook = () => {
},
[apiRef, selectedIdsLookup, headerGroupingMaxDepth],
);

return { getRowAriaAttributes };
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { GridRowId } from '../gridRows';

export type GridRowInternalHook = () => {
/**
* Get the ARIA attributes for a row
* @param {GridRowId} rowId The id of the row
* @param {number} index The position index of the row
* @returns {Record<string, string | number | boolean>} The ARIA attributes
*/
getRowAriaAttributes: (
rowId: GridRowId,
index: number,
) => Record<string, string | number | boolean>;
};
/**
* Get the ARIA attributes for a row
* @param {GridRowId} rowId The id of the row
* @param {number} index The position index of the row
* @returns {Record<string, string | number | boolean>} The ARIA attributes
*/
type GetAriaAttributesFn = (
rowId: GridRowId,
index: number,
) => Record<string, string | number | boolean>;

export type GridRowInternalHook = () => GetAriaAttributesFn;

0 comments on commit 0be3e83

Please sign in to comment.