Skip to content

Commit

Permalink
Triggering onSelect for tree item middle click (#2692)
Browse files Browse the repository at this point in the history
* Triggering onSelect for tree item middle click

* Add changeset
  • Loading branch information
jdrush89 authored Dec 15, 2022
1 parent bce7bf4 commit 5352bcc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-shoes-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Trigger onSelect when TreeView items are middle clicked
7 changes: 7 additions & 0 deletions src/TreeView/TreeView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,13 @@ describe('Keyboard interactions', () => {

// onSelect should have been called
expect(onSelect).toHaveBeenCalledTimes(1)

onSelect.mockClear()
// Press middle click
fireEvent.click(document.activeElement?.firstChild || document.body, {button: 1})

// onSelect should have been called
expect(onSelect).toHaveBeenCalledTimes(1)
})

it('toggles expanded state if no onSelect function is provided', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/TreeView/TreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ const Item = React.forwardRef<HTMLElement, TreeViewItemProps>(
toggle(event)
}
}}
onAuxClick={event => {
if (onSelect && event.button === 1) {
onSelect(event)
}
}}
>
<div style={{gridArea: 'spacer', display: 'flex'}}>
<LevelIndicatorLines level={level} />
Expand Down

0 comments on commit 5352bcc

Please sign in to comment.