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

[core] fix(Tabs): use tabIndex of -1 for non-active tabs #4951

Merged
merged 1 commit into from
Oct 6, 2021

Conversation

styu
Copy link
Contributor

@styu styu commented Oct 5, 2021

I learned recently that the recommendation (from https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Tab_Role#best_practices) for tab behavior is to only set tabIndex={0} for the active tab, and rely on left/right keyboard navigation for navigating the other tabs. This helps reduce the clutter on the screen for a user to have to tab through, while still allowing for navigation within the tablist

The blueprint tabs already support left/right key navigation, so it's mostly just the tabIndex that needed to be changed to respect the above

cc @evansjohnson

@blueprint-bot
Copy link

Set tabIndex -1 for non-active tabs

Previews: documentation | landing | table | modern colors demo

Copy link
Contributor

@evansjohnson evansjohnson left a comment

Choose a reason for hiding this comment

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

PR preview works for me!

@@ -54,7 +54,7 @@ export class TabTitle extends AbstractPureComponent2<TabTitleProps> {
id={generateTabTitleId(parentId, id)}
onClick={disabled ? undefined : this.handleClick}
role="tab"
tabIndex={disabled ? undefined : 0}
tabIndex={disabled ? undefined : selected ? 0 : -1}
Copy link
Contributor

Choose a reason for hiding this comment

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

tangentially related to this PR but I think if we set tabIndex={0} when disabled here the element may not be visible to screen-readers

not 100% sure on that/not set up right now with a good way to test but it's been a working assumption of mine for awhile that disabled elements should remain in the tab order

if so it would possibly would be more appropriate to add to the wrapping div here but again I'm not sure

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this code will never set tabIndex={0} when it's disabled, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, ^ was my understanding as well so i thought this was ok

@@ -54,7 +54,7 @@ export class TabTitle extends AbstractPureComponent2<TabTitleProps> {
id={generateTabTitleId(parentId, id)}
onClick={disabled ? undefined : this.handleClick}
role="tab"
tabIndex={disabled ? undefined : 0}
tabIndex={disabled ? undefined : selected ? 0 : -1}
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this code will never set tabIndex={0} when it's disabled, though.

@adidahiya adidahiya changed the title Set tabIndex -1 for non-active tabs [core] fix(Tabs): use tabIndex of -1 for non-active tabs Oct 6, 2021
@adidahiya adidahiya merged commit 7b10ace into develop Oct 6, 2021
@adidahiya adidahiya deleted the syu/tabs branch October 6, 2021 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants