-
Notifications
You must be signed in to change notification settings - Fork 2
Dropdown component #204
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
Dropdown component #204
Conversation
severo
left a comment
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.
cool. Some comments + I made a PR against this branch: #207
|
We should also add a keyboard handler here for up/down arrow. Going down from the main button should loop through the children but not cycle back to the main button again. function handleArrowKeys(event: KeyboardEvent) {
if (isOpen && (event.key === 'ArrowDown' || event.key === 'ArrowUp')) {
event.preventDefault()
const focusableElements = menuRef.current?.querySelectorAll<HTMLElement>(
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
)
if (focusableElements && focusableElements.length > 0) {
const currentIndex = Array.from(focusableElements).indexOf(document.activeElement as HTMLElement)
let nextIndex = currentIndex
if (event.key === 'ArrowDown') {
nextIndex = (currentIndex + 1) % focusableElements.length
} else if (event.key === 'ArrowUp') {
nextIndex = (currentIndex - 1 + focusableElements.length) % focusableElements.length
}
focusableElements[nextIndex]?.focus()
}
}
} |
bleakley
left a comment
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.
Arrow key handling would be nice but not absolutely needed
| } | ||
| } | ||
|
|
||
| function handleEscape(event: KeyboardEvent) { |
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.
I don't think we need to add this escape key listener to the dropdown anymore, unless there's some tiny part of the element that's outside of the button and the content.
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.
if the user tabs out to another part of the page and hits escape, we should probably close the menu? leaving it for now
Adds a Dropdown component to the
hyperparampackage. Useful for the demos, etc.I also fixed a few random nits and upgraded the dependencies.