Skip to content

Commit

Permalink
ActionList: Prevent scroll when an item is selected with Space (#4259)
Browse files Browse the repository at this point in the history
* prevent default on Space

* immediately reset defaultPrevented

* improve comment

* Create slow-owls-report.md
  • Loading branch information
siddharthkp authored Feb 13, 2024
1 parent 1159a72 commit c9fbef6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-owls-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

ActionList: Prevent scroll when an item is selected with `Space`
6 changes: 6 additions & 0 deletions packages/react/src/ActionList/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
(event: React.KeyboardEvent<HTMLLIElement>) => {
if (disabled || inactive) return
if ([' ', 'Enter'].includes(event.key)) {
if (event.key === ' ') {
event.preventDefault() // prevent scrolling on Space
// immediately reset defaultPrevented once it's job is done
// so as to not disturb the functions that use that event after this
event.defaultPrevented = false
}
onSelect(event, afterSelect)
}
},
Expand Down

0 comments on commit c9fbef6

Please sign in to comment.