Skip to content

Commit

Permalink
TreeView: Ignore cmd/alt+arrow key events (#3413)
Browse files Browse the repository at this point in the history
* Ignore cmd/alt+arrow key events

* Create polite-kings-rhyme.md
  • Loading branch information
colebemis authored Jun 16, 2023
1 parent fa4bd36 commit 4dc719c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-kings-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

TreeView: Ignore arrow key events when combined with cmd or alt keys to avoid interfering with native browser shortcuts.
4 changes: 4 additions & 0 deletions src/TreeView/TreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,15 @@ const Item = React.forwardRef<HTMLElement, TreeViewItemProps>(
}
break
case 'ArrowRight':
// Ignore if modifier keys are pressed
if (event.altKey || event.metaKey) return
event.preventDefault()
event.stopPropagation()
setIsExpandedWithCache(true)
break
case 'ArrowLeft':
// Ignore if modifier keys are pressed
if (event.altKey || event.metaKey) return
event.preventDefault()
event.stopPropagation()
setIsExpandedWithCache(false)
Expand Down

0 comments on commit 4dc719c

Please sign in to comment.