From 032e3b8f4d9fade9cd401c3c71a110a81ba8eb18 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 14 Mar 2024 14:59:36 +0100 Subject: [PATCH] fix(theme): improve a11y of DocSidebarItemCategory expand/collapsed button (#9944) --- .../src/theme/DocSidebarItem/Category/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Category/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Category/index.tsx index 8890a8043d..06dad7c76a 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Category/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Category/index.tsx @@ -101,6 +101,7 @@ function CollapseButton({ {label: categoryLabel}, ) } + aria-expanded={!collapsed} type="button" className="clean-btn menu__caret" onClick={onClick} @@ -193,7 +194,8 @@ export default function DocSidebarItemCategory({ } } aria-current={isCurrentPage ? 'page' : undefined} - aria-expanded={collapsible ? !collapsed : undefined} + role={collapsible && !href ? 'button' : undefined} + aria-expanded={collapsible && !href ? !collapsed : undefined} href={collapsible ? hrefWithSSRFallback ?? '#' : hrefWithSSRFallback} {...props}> {label}