Skip to content
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

TreeView: Add aria-label to TreeView subtree #5174

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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/ten-mirrors-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': minor
---

TreeView: Adds `aria-label` prop to `TreeView.Subtree`
5 changes: 5 additions & 0 deletions packages/react/src/TreeView/TreeView.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
"name": "count",
"type": "number",
"description": "The number of items expected to be in the subtree. When in the loading state, the subtree will render a skeleton loading placeholder with the specified count of items"
},
{
"name": "aria-label",
"type": "string",
"description": "An accessible name for the subtree. It is recommended that you provide a short version of the parent list item's name as the name of the subtree."
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/TreeView/TreeView.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ export const NestedTrees: StoryFn = () => {
<TreeView.DirectoryIcon />
</TreeView.LeadingVisual>
Directory with async items
<TreeView.SubTree state={state}>
<TreeView.SubTree state={state} aria-label="With async items">
{asyncItems.map(item => (
<TreeView.Item id={`item-${item}`} key={item}>
<TreeView.LeadingVisual>
Expand All @@ -672,7 +672,7 @@ export const NestedTrees: StoryFn = () => {
))}
<TreeView.Item id="nested-directory">
Nested Sub-tree
<TreeView.SubTree state="done">
<TreeView.SubTree state="done" aria-label="Nested">
<TreeView.Item id="nested-directory/file-1">
<TreeView.LeadingVisual>
<FileIcon />
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/TreeView/TreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,10 @@ export type TreeViewSubTreeProps = {
* Display a skeleton loading state with the specified count of items
*/
count?: number
'aria-label'?: string
}

const SubTree: React.FC<TreeViewSubTreeProps> = ({count, state, children}) => {
const SubTree: React.FC<TreeViewSubTreeProps> = ({count, state, children, 'aria-label': ariaLabel}) => {
const {announceUpdate} = React.useContext(RootContext)
const {itemId, isExpanded, isSubTreeEmpty, setIsSubTreeEmpty} = React.useContext(ItemContext)
const loadingItemRef = React.useRef<HTMLElement>(null)
Expand Down Expand Up @@ -695,6 +696,7 @@ const SubTree: React.FC<TreeViewSubTreeProps> = ({count, state, children}) => {
}}
// @ts-ignore Box doesn't have type support for `ref` used in combination with `as`
ref={ref}
aria-label={ariaLabel}
>
{state === 'loading' ? <LoadingItem ref={loadingItemRef} count={count} /> : children}
</ul>
Expand Down
Loading