-
Notifications
You must be signed in to change notification settings - Fork 31
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
Menu: Arrow key navigation updates #1761
Conversation
...Basic.args, | ||
label: undefined, | ||
} | ||
|
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.
Adding this image snapshot to make up for a jest snapshot I removed.
const { getByTestId } = renderWithTheme( | ||
<MenuList> | ||
<MenuItem icon="Calendar">Gouda</MenuItem> | ||
describe('MenuGroup', () => { |
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.
Removing all the snapshots since they're covered by image snapshots and otherwise this PR would need to update them. Also added the describe
– just cuz.
rel={rel} | ||
role="menuitem" | ||
target={target} | ||
tabIndex={-1} |
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.
tabIndex={-1}
supports the "use arrows to move focus between items, tab to move focus in & out of the list" behavior.
</Tabs> | ||
) | ||
}) | ||
|
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.
Removing this snapshot since it's covered by an image snapshot and otherwise this PR would have to update it. I tried removing the other 2 snapshots as well but I ran into this issue when trying to use toHaveStyleRule
.
enabled?: boolean | ||
children?: JSX.Element | JSX.Element[] | ||
/** Derive the height of each child using props, type, etc. */ | ||
childHeight: number | ChildHeightFunction | ||
/** Tagname to use for the spacers above and below the window */ | ||
spacerTag?: WindowSpacerTag | ||
ref?: Ref<E> |
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.
Added ref
as a prop here to avoid the need for useForkedRef
in MenuList
.
e158293
to
76eb23d
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.
This is awesome! Really liked the implementation of getNextFocus
and useArrowKeyNav
.
LGTM
vertical | ||
) | ||
if (newFocusedItem) { | ||
e.preventDefault() |
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.
Out of curiosity, why do we need to preventDefault here?
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.
It stops the scrolling that would otherwise happen with the arrow keys.
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.
This looks great! :)
76eb23d
to
d7accae
Compare
✨ Changes
moveFocus
with newuseArrowKeyNav
hook inMenu
andTabs
Menu
) and left/right arrows (Tabs
) via theaxis
propDataTable
) withaxis="both"
and a customgetNextFocus
.✅ Requirements
yarn image-snapshots
locally)📷 Screenshots