-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat(tabs): support home/end keyboard navigation #3258
Conversation
bf39a48
to
23ea20c
Compare
Deploy preview for the-carbon-components ready! Built with commit bf39a48 https://deploy-preview-3258--the-carbon-components.netlify.com |
Deploy preview for carbon-components-react ready! Built with commit bf39a48 https://deploy-preview-3258--carbon-components-react.netlify.com |
Deploy preview for carbon-elements ready! Built with commit bf39a48 |
Deploy preview for the-carbon-components ready! Built with commit bfdc52a https://deploy-preview-3258--the-carbon-components.netlify.com |
Deploy preview for carbon-components-react ready! Built with commit bfdc52a https://deploy-preview-3258--carbon-components-react.netlify.com |
Deploy preview for carbon-elements ready! Built with commit bfdc52a |
There was a problem hiding this 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.
@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? |
@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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 - Thanks @emyarod!
@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 |
23ea20c
to
ea9d72a
Compare
4313217
to
3f484cc
Compare
} else if (index > tabCount) { | ||
tabIndex = 0; | ||
handleTabAnchorFocus = onSelectionChange => (evt, { index }) => { | ||
const newIndex = (() => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
firstTab.simulate('keydown', { ...ArrowRight }); | |
firstTab.simulate('keydown', ArrowRight); |
If you want! Although I'm sure you had a good reason for the spread 👍
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
3f484cc
to
e786bdf
Compare
e786bdf
to
2190ad4
Compare
There was a problem hiding this 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 👍
This reverts commit cb25e3e.
Closes #1495
This PR adds
Home
andEnd
key support for the tabs component and addresses an issue where disabled tabs can still be focused via keyboardChangelog
New
Changed
Tabs.getTabs
now includesindex
information on each tabTabs.handleKeydown
refactored to use the internal keyboard event handler toolsTabs.handleTabAnchorFocus
to ignore disabled tabsTesting / 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