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

[TreeView] Change focus management to aria-activedescendant #21695

Merged
merged 17 commits into from
Jul 22, 2020

Conversation

joshwooding
Copy link
Member

@joshwooding joshwooding commented Jul 6, 2020

Docs: https://deploy-preview-21695--material-ui.netlify.app/components/tree-view/

Closes #20204
Closes #20097

Allows us to have more flexibility in the future and simplifies TreeItem. Since I was changing a lot of the tests due to the focus change I refactored them all to use screen and removed all uses of container.

Todo:

  • Stop allowing custom ids on TreeItems

@joshwooding joshwooding added bug 🐛 Something doesn't work new feature New feature or request component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! labels Jul 6, 2020
@mui-pr-bot
Copy link

mui-pr-bot commented Jul 6, 2020

@material-ui/lab: parsed: -0.24% 😍, gzip: -0.11% 😍

Details of bundle changes

Generated by 🚫 dangerJS against 2845299

@joshwooding joshwooding force-pushed the tree-aria-descendant branch from 2863f50 to 4a50f8a Compare July 6, 2020 19:46
}
// Is before
// eslint-disable-next-line no-bitwise
if (array[middle].element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING) {
Copy link
Member

Choose a reason for hiding this comment

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

This exists 😮 Is it an issue if elements are portaled?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, It shouldn't be but I should add a test :P

test/utils/initMatchers.js Show resolved Hide resolved

expect(getByRole('tree')).to.have.attribute('aria-multiselectable', 'true');
expect(screen.getByRole('tree')).to.have.attribute('aria-multiselectable', 'true');
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should have left this change for another pull request, it makes reviewing the change more challenging.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, did we settle on this approach? I have seen it mentioned in https://kentcdodds.com/blog/common-mistakes-with-react-testing-library#not-using-screen. cc @mui-org/core-team.

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've removed it from the PR to see if it makes it easier to review.

@joshwooding joshwooding force-pushed the tree-aria-descendant branch from ec0dd83 to 4018be7 Compare July 7, 2020 21:36
eps1lon
eps1lon previously requested changes Jul 8, 2020
Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

Stop allowing custom ids on TreeItems

Is this for this PR or another one?

@joshwooding
Copy link
Member Author

Stop allowing custom ids on TreeItems

Is this for this PR or another one?

Probably for this one. It's quite badly worded - active descendant requires an id on the TreeItem but currently, users can override this breaking functionality. We need to add a warning or to change nodeId -> id. What are your thoughts about the latter? @eps1lon @oliviertassinari

@eps1lon
Copy link
Member

eps1lon commented Jul 8, 2020

I'd prefer to not overload id because that is associated with a DOM attribute on a global scope. It sounds like you're proposing to reduce API surface (no more custom IDs) which I quite like. This component is in the lab for a reason.

@joshwooding joshwooding requested a review from eps1lon July 9, 2020 01:26
eps1lon
eps1lon previously requested changes Jul 9, 2020
Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

I thought we were getting rid of nodeId. Not being able to set id on the underlying DOM node for role="treeitem" could be quite problematic if people need to reference it in another IDREF attribute (e.g. aria-labelledby) though I'm not aware of concrete use cases. It's just the first component where people are not able to query it by ID.

Can we put the id in the nodeMap and read it from there instead?

setFocusedNodeId(id);

if (onNodeFocus) {
onNodeFocus(event, id);
Copy link
Member Author

@joshwooding joshwooding Jul 9, 2020

Choose a reason for hiding this comment

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

I'm not a big fan of passing an event here. Sometimes the target will be the tree e.g. on keyboard events. I don't really think there is an alternative apart from creating some kind of pseudo-event where we only populate target.

@eps1lon @oliviertassinari

Copy link
Member

Choose a reason for hiding this comment

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

This is fine in my book as long as it's typed as a generic synthetic event i.e. React.SyntheticEvent. We already have this in place in a couple of other places. It's similar to how React itself doesn't make any guarantee about event.nativeEvent. #21552 has more context on this issue.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TreeView] Cannot be controlled soley by keyboard after tabbable item removal [TreeView] Selection focus
4 participants