Skip to content

Commit

Permalink
UnderlineNav2: Only allow Enter and Space to select item (#2553)
Browse files Browse the repository at this point in the history
* Only allow space and enter to select item

* code review comments
  • Loading branch information
broccolinisoup committed Nov 10, 2022
1 parent 7877f89 commit 3a4b312
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-goats-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

UnderlineNav2: Only allow `Enter` and `Space` key to select an UnderlineNav item
8 changes: 4 additions & 4 deletions src/UnderlineNav2/UnderlineNavItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ export const UnderlineNavItem = forwardRef(

const keyPressHandler = React.useCallback(
event => {
if (!event.defaultPrevented && [' ', 'Enter'].includes(event.key)) {
if (typeof onSelect === 'function') onSelect(event)
if (typeof afterSelect === 'function') afterSelect(event)
if (event.key === ' ' || event.key === 'Enter') {
if (!event.defaultPrevented && typeof onSelect === 'function') onSelect(event)
if (!event.defaultPrevented && typeof afterSelect === 'function') afterSelect(event)
setSelectedLink(ref as RefObject<HTMLElement>)
}
setSelectedLink(ref as RefObject<HTMLElement>)
},
[onSelect, afterSelect, ref, setSelectedLink]
)
Expand Down

0 comments on commit 3a4b312

Please sign in to comment.