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

refactor(v2): update tabs to follow WAI-ARIA spec #4193

Merged
merged 1 commit into from
Feb 8, 2021
Merged

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Feb 8, 2021

Motivation

After some research, I realized that the current implementation of the Tabs component is not entirely correct. We should better follow the WAI-ARIA Tabs Pattern, which is described at https://www.w3.org/TR/wai-aria-practices/#tabpanel.

The main difference is that pressing on tabs list with Tab key will not switch tab, but instead move focus to the corresponding tabpanel (if necessary). This is useful if the tab content contains a focusable element like a link.

References (with automatic activation):

In addition, I also decided to refactor the code - when rendering each tab item, we use the same functions instead of creating new ones. It seems to me to improve performance a little.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Now the link in the tab content is available for navigating from the keyboard by pressing the Tab button (previously there was a switch to the next tab).

Before After
ezgif com-gif-maker (14) ezgif com-gif-maker (13)

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@lex111 lex111 added the pr: polish This PR adds a very minor behavior improvement that users will enjoy. label Feb 8, 2021
@lex111 lex111 requested a review from slorber as a code owner February 8, 2021 11:52
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Feb 8, 2021
@netlify
Copy link

netlify bot commented Feb 8, 2021

Deploy preview for docusaurus-2 failed.

Built with commit e964e08

https://app.netlify.com/sites/docusaurus-2/deploys/602125eedc037800078667c1

@netlify
Copy link

netlify bot commented Feb 8, 2021

[V1] Deploy preview failure

Built with commit e964e08

https://app.netlify.com/sites/docusaurus-1/deploys/602125eed5c0a2000786173b

@github-actions
Copy link

github-actions bot commented Feb 8, 2021

Size Change: +16 B (0%)

Total Size: 156 kB

ℹ️ View Unchanged
Filename Size Change
website/build/assets/css/styles.********.css 17.6 kB 0 B
website/build/assets/js/main.********.js 109 kB +14 B (0%)
website/build/blog/2017/12/14/introducing-docusaurus/index.html 21.7 kB +2 B (0%)
website/build/docs/introduction/index.html 180 B 0 B
website/build/index.html 6.95 kB 0 B

compressed-size-action

@netlify
Copy link

netlify bot commented Feb 8, 2021

[V1] Deploy preview success

Built with commit 9cd9e72

https://deploy-preview-4193--docusaurus-1.netlify.app

@netlify
Copy link

netlify bot commented Feb 8, 2021

Deploy preview for docusaurus-2 ready!

Built with commit 9cd9e72

https://deploy-preview-4193--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Feb 8, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 80
🟢 Accessibility 96
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4193--docusaurus-2.netlify.app/classic/

@slorber
Copy link
Collaborator

slorber commented Feb 8, 2021

As looks fine to me, also see this behavior on ReachUI demo.
However I don't see this behavior on Reakit page.

@Mythra do you want to give us some thoughts?

@lex111
Copy link
Contributor Author

lex111 commented Feb 8, 2021

However I don't see this behavior on Reakit page.

What do you have in mind? Reakit makes the tab panel always focusable, it seems unreasonable to me, so I did not adopt this behavior.

@slorber
Copy link
Collaborator

slorber commented Feb 8, 2021

What do you have in mind? Reakit makes the tab panel always focusable, it seems unreasonable to me, so I did not adopt this behavior.

I don't say Reakit does the right thing, just highlighting that some of your refs are doing things differently 😅

Wouldn't we benefit from including comps like ReachUI tabs directly instead of implementing our own? As they are small and isolated that may be useful?

@Mythra
Copy link

Mythra commented Feb 8, 2021

This is definitely a good change, I didn't have any tabs on the site I was testing, but yes this is the way tabs are expected to work.

One note I may mention is usually if a contents of the tab list are lazy which you seem to have a prop for, it's recommended a user manually hit "space", or "enter" to activate the tab as to not potentially slow down a user. A user who may be using the arrow keys to scroll, don't want them accidentally getting stuck on a tab list if there's going to be a delay.

@lex111
Copy link
Contributor Author

lex111 commented Feb 8, 2021

Dah, you caught me 😄, but actually this is just a list of examples that follow the pattern noted above.

Since we already have a large JS bundle, and we are not using tree-shaking correctly, for now wise to use our own component implementations. Maybe after migrating to webpack 5 and loadable components, we should switch to using third-party UI components, but no sure about this.

@slorber
Copy link
Collaborator

slorber commented Feb 8, 2021

thanks for the review

let's merge this for now

Since we already have a large JS bundle, and we are not using tree-shaking correctly, for now wise to use our own component implementations. Maybe after migrating to webpack 5 and loadable components, we should switch to using third-party UI components, but no sure about this.

I don't think it's related, we don't need treeshaking for libs that have multiple packages like @reachui/tabs, as you won't import anything else from ReachUI that you don't use. Also treeshaking should work already for libs that emit ESM modules

But yeah we can postpone that choice for now, just think that it could save us some time in the future

@slorber slorber merged commit 00c1e8d into master Feb 8, 2021
@lex111 lex111 deleted the lex111/tabs-impr branch February 19, 2021 18:20
@lex111 lex111 added this to the v2.0.0-alpha.71 milestone Mar 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: polish This PR adds a very minor behavior improvement that users will enjoy.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants