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

[material-ui][docs] Add aria-current for nav tabs demo #39594

Merged
merged 8 commits into from
Dec 22, 2023

Conversation

Kimzify
Copy link
Contributor

@Kimzify Kimzify commented Oct 24, 2023

This PR changed aria-selected to aria-current in Tab component.

From the MDN docs:

When you have a group of related elements, such as several links in a breadcrumb or steps in a multi-step flow, with one element in the group styled differently from the others to indicate to the sighted user that this is the current element within its group, the aria-current should be used to inform the assistive technology user what has been indicated via styling.

the aria-selected docs define the following.

The option, tab, and treeitem roles permit user agents to provide an implicit value for aria-selected when specified conditions are met

Closes #32924

https://deploy-preview-39594--material-ui.netlify.app/material-ui/react-tabs/#nav-tabs

@mui-bot
Copy link

mui-bot commented Oct 24, 2023

Netlify deploy preview

https://deploy-preview-39594--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 3f02c7f

@Kimzify Kimzify marked this pull request as draft October 24, 2023 19:30
@Kimzify Kimzify marked this pull request as ready for review October 24, 2023 19:33
@danilo-leal danilo-leal changed the title [docs][Tabs] change aria-selected to aria-current [joy-ui][material-ui][Tabs] Change aria-selected to aria-current Oct 25, 2023
@danilo-leal danilo-leal added accessibility a11y component: tabs This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material package: joy-ui Specific to @mui/joy labels Oct 25, 2023
@michaldudak
Copy link
Member

ARIA docs explicitly state that the active tab should have the aria-selected attribute set to true:

Authors SHOULD ensure that a selected tab has its aria-selected attribute set to true, that inactive tab elements have their aria-selected attribute set to false, and that the currently selected tab provides a visual indication that it is selected.

@Kimzify
Copy link
Contributor Author

Kimzify commented Oct 25, 2023

ARIA docs explicitly state that the active tab should have the aria-selected attribute set to true:

Authors SHOULD ensure that a selected tab has its aria-selected attribute set to true, that inactive tab elements have their aria-selected attribute set to false, and that the currently selected tab provides a visual indication that it is selected.

I've updated the PR and add aria-current as a separate props to tab component. Also as aria-current indicates visually styled I've changed style's conditions to be chosen by aria-current rather than aria-selected and I've added some related tests as well. Could you please check it and tell me if there is any issues?

@michaldudak
Copy link
Member

Why would we need both? Neither ARIA docs nor demos for the tab role mention the aria-current attribute. Is there an accessibility issue you're trying to fix?

@Kimzify
Copy link
Contributor Author

Kimzify commented Oct 27, 2023

Why would we need both? Neither ARIA docs nor demos for the tab role mention the aria-current attribute. Is there an accessibility issue you're trying to fix?

there was an open issue for that and I have trying to fix #32924
am I getting the issue wrong?

@michaldudak
Copy link
Member

michaldudak commented Oct 27, 2023

Sorry, I should have explained this better. I haven't noticed at first that you're fixing #32924.
The issue is only about the navigation tabs demo (https://mui.com/material-ui/react-tabs/#nav-tabs), not the tabs in general.

@Kimzify
Copy link
Contributor Author

Kimzify commented Oct 27, 2023

Sorry, I should have explained this better. I haven't noticed at first that you're fixing #32924. The issue is only about the navigation tabs demo (https://mui.com/material-ui/react-tabs/#nav-tabs), not the tabs in general.

thank you so much. Just I have another question to clarify solution.

  1. we need Tab component to detect links by itself(with component="a" props) and add aria-current label instead of aria-selected
    or
  2. just we need to update document for Nav tabs to contain aria-current beside aria-selected?

@Kimzify
Copy link
Contributor Author

Kimzify commented Nov 12, 2023

As I was checked, if aria-current and aria-selected both have the same value, aria-selected is preferred to be used. If tabs represent navigations, aria-current="page" should be used to indicate navigation usage.
from w3 doc:

In some use cases for widgets that support aria-selected, current and selected can have different meanings and can both be used within the same set of elements. For example, aria-current="page" can be used in a navigation tree to indicate which page is currently displayed, while aria-selected="true" indicates which page will be displayed if the user activates the treeitem

@michaldudak, could you please check the PR again?

@siriwatknp siriwatknp changed the title [joy-ui][material-ui][Tabs] Change aria-selected to aria-current [material-ui][docs] Add aria-current for nav tabs demo Nov 12, 2023
@@ -34,6 +35,7 @@ function LinkTab(props: LinkTabProps) {
event.preventDefault();
}
}}
aria-current={props.selected && "page"}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
aria-current={props.selected && "page"}
aria-current={props.selected ? "page" : undefined}

Copy link
Member

Choose a reason for hiding this comment

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

Also, please add aria-selected={undefined} at the end to override the default behavior of the Tab.

  <Tab
      component="a"
      onClick={(event) => {
        // Routing libraries handle this, you can remove the onClick handle when using them.
        if (samePageLinkNavigation(event)) {
          event.preventDefault();
        }
      }}
      aria-current={props.selected && "page"}
      {...props}
      aria-selected={undefined}
    />

Copy link
Contributor Author

@Kimzify Kimzify Nov 13, 2023

Choose a reason for hiding this comment

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

for the first issue, as I was checked, based on w3 document the default value of aria-current is false.

If the attribute is not present or its value is an empty string or undefined, the default value of false applies and the aria-current state MUST NOT be exposed by user agents or assistive technologies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and for the second issue, we still need aria-selected tag, because aria-selected and aria-current represents different concepts and meanings here.

based on w3 document:

In some use cases for widgets that support aria-selected, current and selected can have different meanings and can both be used within the same set of elements.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the info!

Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

Based on #32924 (comment), the Tabs should have role="navigation" as well.

When you update the code, please run yarn docs:typescript:formatted.

@@ -27,11 +28,17 @@ function LinkTab(props) {
event.preventDefault();
}
}}
aria-current={props.selected && 'page'}
role="navigation"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
role="navigation"

role="navigation" should be at Tabs element below, not Tab.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@Kimzify
Copy link
Contributor Author

Kimzify commented Nov 29, 2023

@siriwatknp @michaldudak, current PR is ready to review again. could you please check it if you have time?

Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

👍 Thanks for the improvements!

@danilo-leal danilo-leal added docs Improvements or additions to the documentation and removed package: joy-ui Specific to @mui/joy labels Dec 22, 2023
@danilo-leal danilo-leal merged commit 9e798d8 into mui:master Dec 22, 2023
19 checks passed
mnajdova pushed a commit to mnajdova/material-ui that referenced this pull request Jan 9, 2024
Co-authored-by: siriwatknp <siriwatkunaporn@gmail.com>
Co-authored-by: Danilo Leal <67129314+danilo-leal@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility a11y component: tabs This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[material-ui][Tabs] The Nav Tabs examples demonstrate incorrect aria usage
5 participants