Skip to content

Update TreeView based on a11y feedback #2428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/blue-frogs-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Update TreeView focus ring styles and call event.preventDefault() in arrow key events
10 changes: 6 additions & 4 deletions src/TreeView/TreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,20 @@ const Item: React.FC<TreeViewItemProps> = ({
break

case 'ArrowRight':
if (!isExpanded) toggle()
event.preventDefault()
setIsExpanded(true)
break

case 'ArrowLeft':
if (isExpanded) toggle()
event.preventDefault()
setIsExpanded(false)
break
}
}

element?.addEventListener('keydown', handleKeyDown)
return () => element?.removeEventListener('keydown', handleKeyDown)
}, [toggle, onSelect, isExpanded])
}, [toggle, onSelect, setIsExpanded])

return (
<ItemContext.Provider value={{level: level + 1, isExpanded, expandParents: expandParentsAndSelf}}>
Expand Down Expand Up @@ -225,7 +227,7 @@ const Item: React.FC<TreeViewItemProps> = ({
// are unnecessarily specific to work around that styled-components bug.
// Reference issue: https://github.com/styled-components/styled-components/issues/3265
[`[role=tree][aria-activedescendant="${itemId}"]:focus-visible #${itemId} > &:is(div)`]: {
boxShadow: (theme: Theme) => `0 0 0 2px ${theme.colors.accent.emphasis}`
boxShadow: (theme: Theme) => `inset 0 0 0 2px ${theme.colors.accent.emphasis}`
},
'[role=treeitem][aria-current=true] > &:is(div)': {
bg: 'actionListItem.default.selectedBg',
Expand Down