Skip to content

Commit b5cd236

Browse files
committed
Announce collapsible sections in the docs menu
Signed-off-by: Damian Stasik <[email protected]>
1 parent 78cd3a4 commit b5cd236

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

frontend/src/components/TreeView/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import clsx from "clsx";
2-
import { ReactNode } from "react";
2+
import { AriaAttributes, ReactNode } from "react";
33

4-
interface TreeViewProps {
4+
interface TreeViewProps extends Pick<AriaAttributes, "aria-labelledby"> {
55
children: ReactNode;
66
className?: string;
7+
id?: string;
78
}
89

9-
export function TreeView({ children, className }: TreeViewProps) {
10-
return <ul className={clsx("flex flex-col", className)}>{children}</ul>;
10+
export function TreeView({ children, className, id, ...rest }: TreeViewProps) {
11+
return (
12+
<ul className={clsx("flex flex-col", className)} id={id} {...rest}>
13+
{children}
14+
</ul>
15+
);
1116
}
1217

1318
interface TreeViewItemProps {

frontend/src/routes/Provider/components/DocsMenu.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TreeView, TreeViewItem } from "@/components/TreeView";
33
import { chevron } from "@/icons/chevron";
44
import { useSuspenseQuery } from "@tanstack/react-query";
55
import clsx from "clsx";
6-
import { useState, useTransition } from "react";
6+
import { useId, useState, useTransition } from "react";
77
import { To, useHref, useLinkClickHandler } from "react-router-dom";
88

99
import { NestedItem, transformStructure } from "../docsSidebar";
@@ -55,12 +55,17 @@ function DocsTreeViewItem({
5555
const { lang } = useProviderParams();
5656
const [open, setOpen] = useState(isOpenByDefault);
5757
let button;
58+
const listId = useId();
59+
const buttonId = useId();
5860

5961
if (item.items) {
6062
button = (
6163
<button
6264
className="flex gap-2 px-4 py-2 text-left text-inherit hover:bg-gray-100 dark:hover:bg-blue-900"
6365
onClick={() => setOpen(!open)}
66+
aria-expanded={open}
67+
aria-controls={open ? listId : undefined}
68+
id={buttonId}
6469
>
6570
<Icon
6671
path={chevron}
@@ -86,7 +91,7 @@ function DocsTreeViewItem({
8691
<TreeViewItem nested={nested} className={nested ? "ml-2" : ""}>
8792
{button}
8893
{open && item.items && (
89-
<TreeView className="ml-4">
94+
<TreeView className="ml-4" id={listId} aria-labelledby={buttonId}>
9095
{item.items.map((subitem) => (
9196
<DocsTreeViewItem
9297
key={subitem.name}

0 commit comments

Comments
 (0)