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): support home/end keyboard navigation #3258

Merged
merged 7 commits into from
Jul 9, 2019

Conversation

emyarod
Copy link
Member

@emyarod emyarod commented Jul 2, 2019

Closes #1495

This PR adds Home and End key support for the tabs component and addresses an issue where disabled tabs can still be focused via keyboard

Changelog

New

  • support for home/end key press

Changed

  • Tabs.getTabs now includes index information on each tab
  • Tabs.handleKeydown refactored to use the internal keyboard event handler tools
  • modified Tabs.handleTabAnchorFocus to ignore disabled tabs

Testing / Reviewing

Ensure there are no regressions with the tabs component keyboard navigation

Ensure that the home and end keydown event handlers behave as expected

Ensure that disabled tabs cannot be focused

@netlify
Copy link

netlify bot commented Jul 2, 2019

Deploy preview for the-carbon-components ready!

Built with commit bf39a48

https://deploy-preview-3258--the-carbon-components.netlify.com

@netlify
Copy link

netlify bot commented Jul 2, 2019

Deploy preview for carbon-components-react ready!

Built with commit bf39a48

https://deploy-preview-3258--carbon-components-react.netlify.com

@netlify
Copy link

netlify bot commented Jul 2, 2019

Deploy preview for carbon-elements ready!

Built with commit bf39a48

https://deploy-preview-3258--carbon-elements.netlify.com

@netlify
Copy link

netlify bot commented Jul 2, 2019

Deploy preview for the-carbon-components ready!

Built with commit bfdc52a

https://deploy-preview-3258--the-carbon-components.netlify.com

@netlify
Copy link

netlify bot commented Jul 2, 2019

Deploy preview for carbon-components-react ready!

Built with commit bfdc52a

https://deploy-preview-3258--carbon-components-react.netlify.com

@netlify
Copy link

netlify bot commented Jul 2, 2019

Deploy preview for carbon-elements ready!

Built with commit bfdc52a

https://deploy-preview-3258--carbon-elements.netlify.com

Copy link
Contributor

@joshblack joshblack left a comment

Choose a reason for hiding this comment

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

Would we want to try and consolidate this kind of keyboard navigation into hooks for Accordion/ContentSwitcher/Tabs? Can time it alongside refactors of those components.

@emyarod
Copy link
Member Author

emyarod commented Jul 2, 2019

@joshblack yeah if there is significant overlap, although I need some clarification about the original ticket WRT the arrow key vs tab navigation. or were you just referring to home/end key navigation?

@joshblack
Copy link
Contributor

@emyarod we can definitely revisit it post this PR, just was noticing some similarity in these different widgets that we might be able to consolidate.

Copy link
Contributor

@asudoh asudoh left a comment

Choose a reason for hiding this comment

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

LGTM 👍 - Thanks @emyarod!

@emyarod
Copy link
Member Author

emyarod commented Jul 3, 2019

@joshblack agreed, I think there is some shared logic we can combine and once the navigation pattern is fleshed out for these components it will be clearer

} else if (index > tabCount) {
tabIndex = 0;
handleTabAnchorFocus = onSelectionChange => (evt, { index }) => {
const newIndex = (() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be wrapped in an IIFE?

Copy link
Member Author

Choose a reason for hiding this comment

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

not really, but we immediately execute the function and assign the return value to newIndex this way

Copy link
Contributor

Choose a reason for hiding this comment

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

@emyarod right, I'm just curious why we need to do this versus hoisting it to the parent scope?

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure I fully understand your question, but it references index so it needs to be within the scope of handleTabAnchorFocus


describe('state: selected', () => {
it('updates selected state when pressing arrow keys', () => {
firstTab.simulate('keydown', { which: rightKey });
firstTab.simulate('keydown', { ...ArrowRight });
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
firstTab.simulate('keydown', { ...ArrowRight });
firstTab.simulate('keydown', ArrowRight);

If you want! Although I'm sure you had a good reason for the spread 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

just to get all of the properties in the simulated event and not just which

Copy link
Contributor

@joshblack joshblack Jul 9, 2019

Choose a reason for hiding this comment

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

@emyarod not sure I understand, it seems like you're calling out going from which to ArrorRight, I was just suggesting there was no need to spread the object as it works inline as well

@emyarod emyarod requested a review from joshblack July 9, 2019 18:26
Copy link
Contributor

@joshblack joshblack left a comment

Choose a reason for hiding this comment

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

Going to approve as-is, changes can always come in after we ship 👍

@asudoh asudoh merged commit cb25e3e into carbon-design-system:master Jul 9, 2019
@emyarod emyarod deleted the 1495-tabs-keyboard-a11y branch July 10, 2019 12:58
joshblack added a commit that referenced this pull request Jul 12, 2019
asudoh pushed a commit that referenced this pull request Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tabs component needs more keyboard behavior for improved accessibility
4 participants