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

feat(tabs): traverse tabs with arrow keys #8116

Conversation

weronikaolejniczak
Copy link
Contributor

@weronikaolejniczak weronikaolejniczak commented Nov 4, 2024

Summary

Both the WCAG and MDN specifications for tabs specify that they should be within a tab group and traversed via arrow keys.

Screen.Recording.2024-11-05.at.12.41.35.mov

I've noticed there are 2 ways the tabs are used:

  1. either with EuiTabbedContent (that provides a tabpanel; EuiTabs and EuiTab accessible from the same level),
  2. or using EuiTabs + EuiTab directly (composition through children prop).

I decided to put the logic inside EuiTabs as its the common point between the 2 use cases and it makes sense for that wrapper to traverse the nodes within and manipulate the DOM (as opposed to traversing them inside EuiTab from the parentElement or handling in EuiTabbedContent).

closes #8005

QA

I tested the changes in the Storybook, the docs and against Kibana (the provided use case: Main Menu > Management > Dev Tools) with VoiceOver.

General checklist

  • Browser QA
    • Checked in both light and dark modes
    • Checked in mobile
    • Checked in Chrome, Safari, Edge, and Firefox
    • Checked for accessibility including keyboard-only and screenreader modes
  • Docs site QA
  • Code quality checklist
  • Release checklist
    • A changelog entry exists and is marked appropriately.
    • If applicable, added the breaking change issue label (and filled out the breaking change checklist)
  • Designer checklist
    • If applicable, file an issue to update EUI's Figma library with any corresponding UI changes. (This is an internal repo, if you are external to Elastic, ask a maintainer to submit this request)

@weronikaolejniczak weronikaolejniczak force-pushed the feat/8005-traverse-tabs-with-arrow-keys branch from fa2af92 to e4511ae Compare November 5, 2024 11:19
@weronikaolejniczak weronikaolejniczak marked this pull request as ready for review November 5, 2024 17:51
@weronikaolejniczak weronikaolejniczak requested a review from a team as a code owner November 5, 2024 17:51
@weronikaolejniczak weronikaolejniczak force-pushed the feat/8005-traverse-tabs-with-arrow-keys branch 4 times, most recently from c89bb30 to bb63b1c Compare November 5, 2024 18:12
packages/eui/src/components/tabs/tabs.tsx Outdated Show resolved Hide resolved
packages/eui/src/components/tabs/tabs.tsx Outdated Show resolved Hide resolved
packages/eui/src/components/tabs/tabs.tsx Outdated Show resolved Hide resolved
packages/eui/src/components/tabs/tabs.tsx Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a Cypress test checking that this still works if consumers completely change their tabs dynamically? Or what happens if they dynamically disable some tabs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cee-chen that's a very good idea! I didn't even think of a dynamic tab use case. Could you share an example from Kibana? Or maybe you have an idea of what that test could look like?

Copy link
Member

@cee-chen cee-chen Nov 14, 2024

Choose a reason for hiding this comment

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

It's been a use case reported in a bug by our users, primarily for EuiTabbedContent:

Making it an EuiTabbedContent Cypress test (or Jest test, whatever's easier) where the component gets updated with new tabs probably makes the most sense.

packages/eui/src/components/tabs/tabs.tsx Outdated Show resolved Hide resolved
packages/eui/src/components/tabs/tabs.tsx Outdated Show resolved Hide resolved
@weronikaolejniczak weronikaolejniczak force-pushed the feat/8005-traverse-tabs-with-arrow-keys branch 2 times, most recently from a170f27 to 63b23a6 Compare November 8, 2024 11:19
@weronikaolejniczak weronikaolejniczak force-pushed the feat/8005-traverse-tabs-with-arrow-keys branch from 63b23a6 to a0cb507 Compare November 12, 2024 16:36
@cee-chen
Copy link
Member

Apologies it took me so long to get back to this PR Weronika! Your changes look terrific. Just to recap, here's what's remaining

  • Ternary / looping logic comment
  • Adding a test that checks the dynamic of disabling tabs in Cypress or Jest (arrow keys should skip past disabled tabs, and disabling another tab and enabling another after mount should correctly skip past the disabled tab and allow the enabled one to be arrow'd to).

Once the above is in, I think this is good to merge!

@weronikaolejniczak weronikaolejniczak force-pushed the feat/8005-traverse-tabs-with-arrow-keys branch 2 times, most recently from 704a2e8 to c10696e Compare November 20, 2024 15:40
Copy link
Member

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

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

Changes LGTM. I have an optional extra regression test request around tabbing past disabled tabs, but I don't want it to block this PR as it's working now :)

id: 'world',
name: 'New tab 2',
content: <p>World</p>,
},
Copy link
Member

Choose a reason for hiding this comment

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

Optional - can we add a 3rd tab and disable the 2nd one to confirm that arrow keying past disabled tabs works as expected? I mention this because this UX was broken before we added the :not([disabled]) selector as part of the code review, so I'd like to make sure it doesn't regress in the future!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cee-chen absolutely we can add it, thank you for the suggestion 🙌🏻

What would you say about the inert case? I don't see the tabs consuming inert prop and setting inert on a parent doesn't make sense for testing whether an inert element is skipped.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I'm fine skipping explicit inert testing, disabled was the main one I wanted to ensure had a test!

@weronikaolejniczak weronikaolejniczak force-pushed the feat/8005-traverse-tabs-with-arrow-keys branch from c10696e to 62f2781 Compare November 21, 2024 11:35
@kibanamachine
Copy link

Preview staging links for this PR:

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

Copy link
Member

@cee-chen cee-chen 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 adding the extra disabled test Weronika!! This looks and works great!

@weronikaolejniczak weronikaolejniczak merged commit df7a98f into elastic:main Nov 21, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants