Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGridPro] Fix Tree Data and Row Grouping rows accessibility #13623

Merged
merged 94 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 92 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
d1ceefd
Add visible row ids to parent id lookup selector
arminmeh Jun 25, 2024
895c71e
Extend grid row for the pro grid to include additional aria atteribut…
arminmeh Jun 25, 2024
5b7aa0b
aria-rowcount is updated when filter is applied
arminmeh Jun 25, 2024
3cac35a
Extract pro grid row into a separate component to use conditional ren…
arminmeh Jun 25, 2024
b0c2ff9
Update API docs
arminmeh Jun 25, 2024
ce93f09
Add tests
arminmeh Jun 25, 2024
3ddce45
Generate tree grid aria attributes via hook
arminmeh Jun 26, 2024
8f8b45b
Remove slow selector and filter out current level ids in the callback
arminmeh Jun 26, 2024
38c7cf3
Remove unused import and rebuild API docs
arminmeh Jun 26, 2024
b49a771
Expand test with the assertion that checks reset of the position counter
arminmeh Jun 27, 2024
9587f1e
Add lookup selector for position in set (branch) of the tree
arminmeh Jun 27, 2024
f6e08fa
Use pipe processor to adjust aria attributes for better performance. …
arminmeh Jun 27, 2024
d5cced0
Fix lint issues
arminmeh Jun 27, 2024
d5774f2
Update API docs
arminmeh Jun 27, 2024
8abb528
Fix counter reset logic
arminmeh Jun 27, 2024
2b8b493
Fix top level set size count
arminmeh Jun 27, 2024
4289b1d
Remove grid row attributes pipe processor
arminmeh Jul 3, 2024
83f833b
Add grid configuration context and models
arminmeh Jul 3, 2024
52f6d75
Create community and pro version of the hooks that compile row specif…
arminmeh Jul 3, 2024
0cb9b81
Add hooks to the configuration context
arminmeh Jul 3, 2024
9cc9f07
Use configuration context to add aria attributes to the grid row
arminmeh Jul 3, 2024
0380e54
Fix lint issue
arminmeh Jul 3, 2024
a55ad86
Ignore multiple export lint issue for re-exporting of the aria attrib…
arminmeh Jul 3, 2024
82c7d7b
Add additional assertions to the tree data accessbility test to cover…
arminmeh Jul 3, 2024
1ea6d0b
Add children count lookup
arminmeh Jul 3, 2024
2aa1850
Add children count lookup selector
arminmeh Jul 3, 2024
e0f8830
Use children count lookup to determine the set size (excludes grand c…
arminmeh Jul 3, 2024
c4677b7
Add tests for the new count lookup
arminmeh Jul 3, 2024
2f4cb25
Fix lint issues
arminmeh Jul 3, 2024
323d3eb
Rebuild API docs
arminmeh Jul 3, 2024
65fa808
Remove ariaAttributes from pipe processing interface
arminmeh Jul 3, 2024
841f0e0
Extract static object to prevent unnecessary re-renders
arminmeh Jul 3, 2024
1c881b4
Rename useGridConfigurationContext -> useGridConfiguration
arminmeh Jul 3, 2024
0d0090d
Rename gridConfiguration -> configuration
arminmeh Jul 3, 2024
226ac3f
Do not wrap aria attributes getter into an object
arminmeh Jul 4, 2024
bc80a39
Add new prop to the return value of the skip filtering utility
arminmeh Jul 11, 2024
49ae70f
Change hasServerChildren to serverChildrenCount to be able to re-use …
arminmeh Jul 11, 2024
2bbfa54
Fix build
arminmeh Jul 11, 2024
c44f000
group row should not be made if serverChildrenCount is undefined
arminmeh Jul 11, 2024
6289ff2
Expand the filteredChildrenCountLookup description
arminmeh Jul 11, 2024
943ddce
treegird role is set if row grouping is in place
arminmeh Jul 15, 2024
752d575
Add additional aria attributes to the rows in a grid that has row gro…
arminmeh Jul 15, 2024
8a3fe59
Add accessibility test to the row grouping feature
arminmeh Jul 15, 2024
587ec30
Util cleanup
arminmeh Jul 19, 2024
aaf0f2e
Pass row node instead of id to the aria attributes hook
arminmeh Jul 19, 2024
6aae705
Fallback to 0 if node does not have serverChildrenCount
arminmeh Jul 19, 2024
3c9c0ae
Fix server row count models and update their descriptions
arminmeh Jul 19, 2024
8351828
Extend tests
arminmeh Jul 19, 2024
b38642f
Update filter state model description for the child count
arminmeh Jul 19, 2024
c80b879
Update selector name to better reflect its purpose. Make it private a…
arminmeh Jul 19, 2024
53f342c
Use sanitized grouping model selector
arminmeh Jul 19, 2024
5f348d2
Use grid configuration to apply different values to the grid aria att…
arminmeh Jul 19, 2024
1ddc129
Update serverChildrenCount description
arminmeh Jul 19, 2024
a79c418
Group internal exports that need lint rule disabled
arminmeh Aug 2, 2024
ea42fe2
debug: list installed dependencies
cherniavskii Aug 2, 2024
f91871c
try removing everything from .next except cache folder
cherniavskii Aug 2, 2024
f254de6
do not error on directories
cherniavskii Aug 2, 2024
f887561
fix exit code 2
cherniavskii Aug 2, 2024
43374fe
fork netlify plugin
cherniavskii Aug 2, 2024
33a5376
try removing docs/.next before build
cherniavskii Aug 3, 2024
ba96136
make sure the next folder does not exist before build
cherniavskii Aug 4, 2024
aeca849
Code cleanup
arminmeh Aug 5, 2024
008cd4e
isRowSelectable returns false if the whole feature is disabled
arminmeh Aug 5, 2024
41837e5
Fix docs referring to a cell for a row API
arminmeh Aug 5, 2024
a6cc046
Selectable row always has 'aria-selected' attribute
arminmeh Aug 5, 2024
ac70073
pinned and footer rows should not get the set specific aria attributes
arminmeh Aug 5, 2024
2a51b10
Add missing dependencies
arminmeh Aug 5, 2024
9e546d8
log @mui/joy/package.json
cherniavskii Aug 5, 2024
73b64a7
fix import order
cherniavskii Aug 5, 2024
0a72fd5
log @mui/joy/package.json
cherniavskii Aug 5, 2024
6c45d83
add InitColorSchemeScript import
cherniavskii Aug 5, 2024
b5965ee
Delete from the docs script
arminmeh Aug 5, 2024
cbaa807
try importing InitColorSchemeScript from MUI X _document
cherniavskii Aug 5, 2024
2f089d5
Merge branch 'expandable-rows-not-accessible' of https://github.com/a…
cherniavskii Aug 5, 2024
56f5131
duplicate _document from monorepo
cherniavskii Aug 5, 2024
985cc2a
revert _document
cherniavskii Aug 5, 2024
38a3195
revert netlify config changes
cherniavskii Aug 5, 2024
36ee004
remove netlify plugin fork
cherniavskii Aug 5, 2024
7d53c83
Merge branch 'master' into expandable-rows-not-accessible
cherniavskii Aug 7, 2024
0ec4fa5
No need to return an object
arminmeh Aug 8, 2024
e5bf5ea
Add experimental flag for the aria attribute change in the premium da…
arminmeh Aug 8, 2024
106cc31
upgrade @tanstack/query-core
cherniavskii Aug 8, 2024
f440e68
Make selector internal
arminmeh Aug 8, 2024
f06d32b
Make children count selector internal
arminmeh Aug 8, 2024
7135b28
Merge branch 'master' into expandable-rows-not-accessible
arminmeh Aug 12, 2024
23ed256
Merge branch 'master' into expandable-rows-not-accessible
cherniavskii Aug 12, 2024
d3aff14
downgrade pnpm
cherniavskii Aug 12, 2024
dff8750
downgrade pnpm (again)
cherniavskii Aug 12, 2024
d9d4107
reset pnpm version
cherniavskii Aug 12, 2024
8069753
Add documentation section for the experimental flag
arminmeh Aug 13, 2024
c70e68e
Align names
arminmeh Aug 13, 2024
aa892fe
remove --shamefully-hoist flag
cherniavskii Aug 13, 2024
84ef55f
Merge branch 'master' into expandable-rows-not-accessible
cherniavskii Aug 13, 2024
4f48e06
revert dependency upgrade
cherniavskii Aug 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/data/data-grid/row-grouping/RowGroupingAriaV8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as React from 'react';
import {
DataGridPremium,
useGridApiRef,
useKeepGroupedColumnsHidden,
} from '@mui/x-data-grid-premium';
import { useMovieData } from '@mui/x-data-grid-generator';

export default function RowGroupingAriaV8() {
const data = useMovieData();
const apiRef = useGridApiRef();

const initialState = useKeepGroupedColumnsHidden({
apiRef,
initialState: {
rowGrouping: {
model: ['company'],
},
},
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGridPremium
{...data}
apiRef={apiRef}
initialState={initialState}
experimentalFeatures={{ ariaV8: true }}
/>
</div>
);
}
32 changes: 32 additions & 0 deletions docs/data/data-grid/row-grouping/RowGroupingAriaV8.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as React from 'react';
import {
DataGridPremium,
useGridApiRef,
useKeepGroupedColumnsHidden,
} from '@mui/x-data-grid-premium';
import { useMovieData } from '@mui/x-data-grid-generator';

export default function RowGroupingAriaV8() {
const data = useMovieData();
const apiRef = useGridApiRef();

const initialState = useKeepGroupedColumnsHidden({
apiRef,
initialState: {
rowGrouping: {
model: ['company'],
},
},
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGridPremium
{...data}
apiRef={apiRef}
initialState={initialState}
experimentalFeatures={{ ariaV8: true }}
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<DataGridPremium
{...data}
apiRef={apiRef}
initialState={initialState}
experimentalFeatures={{ ariaV8: true }}
/>
1 change: 1 addition & 0 deletions docs/data/data-grid/row-grouping/RowGroupingFullExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default function RowGroupingFullExample() {
groupingColDef={{
leafField: 'traderEmail',
}}
experimentalFeatures={{ ariaV8: true }}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default function RowGroupingFullExample() {
groupingColDef={{
leafField: 'traderEmail',
}}
experimentalFeatures={{ ariaV8: true }}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
groupingColDef={{
leafField: 'traderEmail',
}}
experimentalFeatures={{ ariaV8: true }}
/>
16 changes: 16 additions & 0 deletions docs/data/data-grid/row-grouping/row-grouping.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,22 @@ Don't hesitate to leave a comment on the same issue to influence what gets built

With this panel, your users will be able to control which columns are used for grouping just by dragging them inside the panel.

## Accessibility changes in v8

The Data Grid v8 with row grouping feature will improve the accessibility and will be more aligned with the WAI-ARIA authoring practices.

You can start using the new accessibility features by enabling `ariaV8` experimental feature flag:

```tsx
<DataGridPremium experimentalFeatures={{ ariaV8: true }} />
```

:::warning
The value of `ariaV8` should be constant and not change during the lifetime of the Data Grid.
:::

{{"demo": "RowGroupingAriaV8.js", "bg": "inline", "defaultCodeOpen": false}}

## Full example

{{"demo": "RowGroupingFullExample.js", "bg": "inline", "defaultCodeOpen": false}}
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@mui/x-date-pickers-pro": "workspace:*",
"@mui/x-tree-view": "workspace:*",
"@react-spring/web": "^9.7.4",
"@tanstack/query-core": "^5.51.15",
"@tanstack/query-core": "^5.51.21",
"ast-types": "^0.14.2",
"autoprefixer": "^10.4.19",
"babel-plugin-module-resolver": "^5.0.2",
Expand Down
5 changes: 4 additions & 1 deletion docs/pages/x/api/data-grid/data-grid-premium.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@
},
"estimatedRowCount": { "type": { "name": "number" } },
"experimentalFeatures": {
"type": { "name": "shape", "description": "{ warnIfFocusStateIsNotSynced?: bool }" }
"type": {
"name": "shape",
"description": "{ ariaV8?: bool, warnIfFocusStateIsNotSynced?: bool }"
}
},
"filterDebounceMs": { "type": { "name": "number" }, "default": "150" },
"filterMode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
"description": "Determines if a row can be selected.",
"typeDescriptions": {
"params": "With all properties from <a href='/x/api/data-grid/grid-row-params/'>GridRowParams</a>.",
"boolean": "A boolean indicating if the cell is selectable."
"boolean": "A boolean indicating if the row is selectable."
}
},
"keepColumnPositionIfDraggedOutside": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
"description": "Determines if a row can be selected.",
"typeDescriptions": {
"params": "With all properties from <a href='/x/api/data-grid/grid-row-params/'>GridRowParams</a>.",
"boolean": "A boolean indicating if the cell is selectable."
"boolean": "A boolean indicating if the row is selectable."
}
},
"keepColumnPositionIfDraggedOutside": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"description": "Determines if a row can be selected.",
"typeDescriptions": {
"params": "With all properties from <a href='/x/api/data-grid/grid-row-params/'>GridRowParams</a>.",
"boolean": "A boolean indicating if the cell is selectable."
"boolean": "A boolean indicating if the row is selectable."
}
},
"keepNonExistentRowsSelected": {
Expand Down
1 change: 0 additions & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
[build.environment]
NODE_VERSION = "18"
NODE_OPTIONS = "--max_old_space_size=4096"
PNPM_FLAGS = "--shamefully-hoist"

[[plugins]]
package = "./packages/netlify-plugin-cache-docs"
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,17 @@ import {
} from '../models/dataGridPremiumProps';
import { useDataGridPremiumProps } from './useDataGridPremiumProps';
import { getReleaseInfo } from '../utils/releaseInfo';
import { useGridAriaAttributes } from '../hooks/utils/useGridAriaAttributes';
import { useGridRowAriaAttributes } from '../hooks/features/rows/useGridRowAriaAttributes';

export type { GridPremiumSlotsComponent as GridSlots } from '../models';

const configuration = {
hooks: {
useGridAriaAttributes,
useGridRowAriaAttributes,
},
};
const releaseInfo = getReleaseInfo();

let dataGridPremiumPropValidators: PropValidator<DataGridPremiumProcessedProps>[];
Expand All @@ -40,14 +48,13 @@ const DataGridPremiumRaw = React.forwardRef(function DataGridPremium<R extends G
) {
const props = useDataGridPremiumProps(inProps);
const privateApiRef = useDataGridPremiumComponent(props.apiRef, props);

useLicenseVerifier('x-data-grid-premium', releaseInfo);

if (process.env.NODE_ENV !== 'production') {
validateProps(props, dataGridPremiumPropValidators);
}
return (
<GridContextProvider privateApiRef={privateApiRef} props={props}>
<GridContextProvider privateApiRef={privateApiRef} configuration={configuration} props={props}>
<GridRoot
className={props.className}
style={props.style}
Expand Down Expand Up @@ -312,6 +319,7 @@ DataGridPremiumRaw.propTypes = {
* For each feature, if the flag is not explicitly set to `true`, then the feature is fully disabled, and neither property nor method calls will have any effect.
*/
experimentalFeatures: PropTypes.shape({
ariaV8: PropTypes.bool,
warnIfFocusStateIsNotSynced: PropTypes.bool,
}),
/**
Expand Down Expand Up @@ -486,7 +494,7 @@ DataGridPremiumRaw.propTypes = {
/**
* Determines if a row can be selected.
* @param {GridRowParams} params With all properties from [[GridRowParams]].
* @returns {boolean} A boolean indicating if the cell is selectable.
* @returns {boolean} A boolean indicating if the row is selectable.
*/
isRowSelectable: PropTypes.func,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const filterRowTreeFromGroupingColumns = (
): Omit<GridFilterState, 'filterModel'> => {
const { apiRef, rowTree, isRowMatchingFilters, filterModel } = params;
const filteredRowsLookup: Record<GridRowId, boolean> = {};
const filteredChildrenCountLookup: Record<GridRowId, number> = {};
const filteredDescendantCountLookup: Record<GridRowId, number> = {};
const filterCache = {};

Expand Down Expand Up @@ -110,6 +111,7 @@ export const filterRowTreeFromGroupingColumns = (
isPassingFiltering = true;
}

let filteredChildrenCount = 0;
let filteredDescendantCount = 0;
if (node.type === 'group') {
node.children.forEach((childId) => {
Expand All @@ -120,6 +122,9 @@ export const filterRowTreeFromGroupingColumns = (
[...ancestorsResults, filterResults],
);
filteredDescendantCount += childSubTreeSize;
if (childSubTreeSize > 0) {
filteredChildrenCount += 1;
}
});
}

Expand All @@ -145,6 +150,7 @@ export const filterRowTreeFromGroupingColumns = (
return 0;
}

filteredChildrenCountLookup[node.id] = filteredChildrenCount;
filteredDescendantCountLookup[node.id] = filteredDescendantCount;

if (node.type !== 'group') {
Expand All @@ -164,6 +170,7 @@ export const filterRowTreeFromGroupingColumns = (

return {
filteredRowsLookup,
filteredChildrenCountLookup,
filteredDescendantCountLookup,
};
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useGridRowAriaAttributes';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {
useGridRowAriaAttributes as useGridRowAriaAttributesPro,
useGridSelector,
} from '@mui/x-data-grid-pro/internals';
import { useGridPrivateApiContext } from '../../utils/useGridPrivateApiContext';
import { gridRowGroupingSanitizedModelSelector } from '../rowGrouping/gridRowGroupingSelector';

export const useGridRowAriaAttributes = () => {
const apiRef = useGridPrivateApiContext();
const gridRowGroupingModel = useGridSelector(apiRef, gridRowGroupingSanitizedModelSelector);
return useGridRowAriaAttributesPro(gridRowGroupingModel.length > 0);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from 'react';
import {
useGridAriaAttributes as useGridAriaAttributesPro,
useGridSelector,
} from '@mui/x-data-grid-pro/internals';
import { gridRowGroupingSanitizedModelSelector } from '../features/rowGrouping/gridRowGroupingSelector';
import { useGridPrivateApiContext } from './useGridPrivateApiContext';
import { useGridRootProps } from './useGridRootProps';

export const useGridAriaAttributes = (): React.HTMLAttributes<HTMLElement> => {
const rootProps = useGridRootProps();
const ariaAttributesPro = useGridAriaAttributesPro();
const apiRef = useGridPrivateApiContext();
const gridRowGroupingModel = useGridSelector(apiRef, gridRowGroupingSanitizedModelSelector);

const ariaAttributesPremium =
rootProps.experimentalFeatures?.ariaV8 && gridRowGroupingModel.length > 0
? { role: 'treegrid' }
: {};

return {
...ariaAttributesPro,
...ariaAttributesPremium,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ import { GridInitialStatePremium } from './gridStatePremium';
import { GridApiPremium } from './gridApiPremium';
import { GridCellSelectionModel } from '../hooks/features/cellSelection';

export interface GridExperimentalPremiumFeatures extends GridExperimentalProFeatures {}
export interface GridExperimentalPremiumFeatures extends GridExperimentalProFeatures {
/**
* Enables accessibility improvements that will be enabled by default in V8.
* If you rely on the v7 ARIA attributes (e.g. for CSS selectors), this might be a breaking change.
* @default false
*/
ariaV8: boolean;
}

export interface DataGridPremiumPropsWithComplexDefaultValueBeforeProcessing
extends Pick<DataGridPropsWithComplexDefaultValueBeforeProcessing, 'localeText'> {
Expand Down
Loading