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

[docs] Explain how to manage focus with renderCell #4254

Merged
merged 21 commits into from
May 23, 2022

Conversation

alexfauquette
Copy link
Member

@alexfauquette alexfauquette commented Mar 22, 2022

Preview: https://deploy-preview-4254--material-ui-x.netlify.app/x/react-data-grid/accessibility/#tab-sequence

Part of #4219

The goal of this PR is to explain in the doc how to remove focusable elements from the tab sequence if the cell does not have the focus

@alexfauquette alexfauquette requested a review from m4theushw March 22, 2022 09:52
@mui-bot
Copy link

mui-bot commented Mar 22, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 265.9 518.5 415.9 385.68 89.728
Sort 100k rows ms 489.9 990.2 795.4 779.34 174.618
Select 100k rows ms 149.9 267.3 204.7 204.52 37.612
Deselect 100k rows ms 96.8 296.2 215.3 184.96 67.904

Generated by 🚫 dangerJS against e0fa0f9

@alexfauquette alexfauquette added docs Improvements or additions to the documentation accessibility a11y labels Mar 22, 2022
Copy link
Member

@m4theushw m4theushw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also stop the ripple when the cell loses focus?

image

React.useLayoutEffect(() => {
if (hasFocus) {
const input = checkboxElement.current?.querySelector('input');
input?.focus();
} else if (rippleRef.current) {
// Only available in @mui/material v5.4.1 or later
rippleRef.current.stop({});
}
}, [hasFocus]);

docs/data/data-grid/columns/columns.md Outdated Show resolved Hide resolved
docs/data/data-grid/columns/columns.md Outdated Show resolved Hide resolved
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 29, 2022
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 29, 2022
@alexfauquette alexfauquette requested a review from m4theushw April 8, 2022 08:56
docs/data/data-grid/accessibility/accessibility.md Outdated Show resolved Hide resolved
docs/data/data-grid/accessibility/accessibility.md Outdated Show resolved Hide resolved
docs/data/data-grid/accessibility/accessibility.md Outdated Show resolved Hide resolved
Comment on lines 57 to 58
If you are customizing cell rendering with [`renderCell`](/components/data-grid/columns/#render-cell) method, you become responsible of removing focusable elements from the page tab sequence.
To do so, use the `hasFocus` property from the `renderCell` input, to know if the rendered cell has the focus, and so if the elements should be removed from the tab sequence.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think using "focusable elements" here is correct. An element can be focusable but not tabbable. What happens is that some HTML elements have implicit tabIndex=0, e.g. <a />.

Suggested change
If you are customizing cell rendering with [`renderCell`](/components/data-grid/columns/#render-cell) method, you become responsible of removing focusable elements from the page tab sequence.
To do so, use the `hasFocus` property from the `renderCell` input, to know if the rendered cell has the focus, and so if the elements should be removed from the tab sequence.
If you are customizing cell rendering with [`renderCell`](/components/data-grid/columns/#render-cell) method, you become responsible for removing focusable elements from the page tab sequence.
To do so, use the `tabIndex` prop passed to the `renderCell` params, to know if the rendered cell has the focus, and so if the elements should be removed from the tab sequence.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced the use of hasFocus by tabIndex in the demo too.


export default function FocusManagement() {
return (
<div style={{ width: '100%', display: 'flex', justifyContent: 'space-between' }}>
Copy link
Member

@m4theushw m4theushw Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selecting one cell breaks the demo.

image

Maybe split into two demos so the focus reset button can be used:

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used hideFooterSelectedRowCount to avoid having the "selected row count" modifying the width of the table

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very sure if we should keep two grids inside the same demo. The "reset focus" button is very useful to test the accessibility here. If I click it the focus goes to the first grid.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 9, 2022
@github-actions
Copy link

github-actions bot commented Apr 9, 2022

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 12, 2022
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 13, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 20, 2022
@m4theushw m4theushw mentioned this pull request Apr 22, 2022
12 tasks
@alexfauquette alexfauquette requested a review from m4theushw May 3, 2022 12:07
Copy link
Member

@m4theushw m4theushw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once #4600 is merged we can add a link to the newly added section: #4600 (comment)

docs/data/data-grid/accessibility/accessibility.md Outdated Show resolved Hide resolved
docs/data/data-grid/accessibility/accessibility.md Outdated Show resolved Hide resolved
docs/data/data-grid/accessibility/accessibility.md Outdated Show resolved Hide resolved
docs/data/data-grid/accessibility/accessibility.md Outdated Show resolved Hide resolved
docs/data/data-grid/accessibility/accessibility.md Outdated Show resolved Hide resolved
docs/data/data-grid/accessibility/accessibility.md Outdated Show resolved Hide resolved

export default function FocusManagement() {
return (
<div style={{ width: '100%', display: 'flex', justifyContent: 'space-between' }}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very sure if we should keep two grids inside the same demo. The "reset focus" button is very useful to test the accessibility here. If I click it the focus goes to the first grid.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label May 9, 2022
@github-actions
Copy link

github-actions bot commented May 9, 2022

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label May 18, 2022
@alexfauquette alexfauquette merged commit fa387fa into mui:master May 23, 2022
@alexfauquette alexfauquette deleted the render-cell-info branch May 23, 2022 08:42
@@ -1,25 +1,55 @@
import * as React from 'react';
import Button from '@mui/material/Button';
import { TouchRippleActions } from '@mui/material/ButtonBase/TouchRipple';
Copy link
Member

@oliviertassinari oliviertassinari Jun 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a private type import (more than 1 folder level deep) 🚫, we will need to change this. More details in https://mui.com/material-ui/guides/minimizing-bundle-size/.

alexfauquette added a commit to alexfauquette/mui-x that referenced this pull request Aug 26, 2022
Co-authored-by: Matheus Wichman <matheushw@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility a11y docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants