diff --git a/.changeset/slow-owls-report.md b/.changeset/slow-owls-report.md new file mode 100644 index 00000000000..c572b98f1c2 --- /dev/null +++ b/.changeset/slow-owls-report.md @@ -0,0 +1,5 @@ +--- +"@primer/react": patch +--- + +ActionList: Prevent scroll when an item is selected with `Space` diff --git a/packages/react/src/ActionList/Item.tsx b/packages/react/src/ActionList/Item.tsx index a65a10372c6..ee6592210d7 100644 --- a/packages/react/src/ActionList/Item.tsx +++ b/packages/react/src/ActionList/Item.tsx @@ -229,6 +229,12 @@ export const Item = React.forwardRef( (event: React.KeyboardEvent) => { 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) } },