Skip to content

Commit d1411c7

Browse files
tulsi-builderBasilBotclaude
committed
fix(shell): describe toolbar page buttons with their badge
In the toolbar placement the badge sits beside the icon-only button, so the button's accessible name did not include the unread count. Point the button's aria-describedby at the badge. Co-authored-by: BasilBot <399581b6165ab01343e3a1324774b1024d76942aea563468f93c975e5ee5193c@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: tulsi <[email protected]>
1 parent e83fdbf commit d1411c7

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

‎src/app/shell/AppShell.test.tsx‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,52 @@ it("falls back from a failed toolbar image and isolates toolbar badge errors", (
648648
}
649649
});
650650

651+
it("describes a toolbar page button with its badge", () => {
652+
const current = createServices();
653+
services = current;
654+
render(
655+
<ToastProvider>
656+
<AppShell
657+
pages={[
658+
{
659+
id: "inbox",
660+
key: "example/inbox",
661+
pluginId: "example",
662+
revision: "one",
663+
title: "Inbox",
664+
primary: true,
665+
placement: "toolbar",
666+
component: () => null,
667+
badge: () => (
668+
<span role="img" aria-label="3 unread conversations">
669+
3
670+
</span>
671+
),
672+
},
673+
]}
674+
selected="example/inbox"
675+
navigationAttempt=""
676+
onSelect={() => {}}
677+
tone="default"
678+
communities={current.communities}
679+
accountActions={current.accountActions}
680+
appearance={testAppearance}
681+
>
682+
content
683+
</AppShell>
684+
</ToastProvider>,
685+
);
686+
const button = screen.getByRole("button", { name: "Inbox" });
687+
// jsdom's accname reads the described wrapper's text ("3"); Chromium and
688+
// Playwright's accname use the labelled image: "3 unread conversations".
689+
const description = document.getElementById(
690+
button.getAttribute("aria-describedby") ?? "",
691+
);
692+
expect(description).toContainElement(
693+
screen.getByRole("img", { name: "3 unread conversations" }),
694+
);
695+
});
696+
651697
it("uses chrome tabs with manual keyboard selection, page linkage, and isolated badges", async () => {
652698
const current = createServices();
653699
services = current;

‎src/app/shell/PageNavigation.tsx‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useId } from "react";
12
import type { RegisteredPage } from "../../features/pages/service";
23
import type { NavigationOpenOptions } from "../../features/navigation/controller";
34
import {
@@ -30,6 +31,7 @@ export function PageNavigation({
3031
placement?: "sidebar" | "topbar" | "toolbar";
3132
}) {
3233
const presentation = usePagePresentation();
34+
const badgeId = useId();
3335
if (placement === "topbar") {
3436
return (
3537
<Tabs
@@ -60,7 +62,7 @@ export function PageNavigation({
6062
/>
6163
);
6264
}
63-
return pages.map((page) => {
65+
return pages.map((page, index) => {
6466
const { label, icon, image, avatar } = presentation(page);
6567
const Badge = page.badge;
6668
const badge = Badge && (
@@ -90,17 +92,25 @@ export function PageNavigation({
9092
strokeWidth={2.5}
9193
/>
9294
);
95+
// The toolbar badge sits beside its icon-only button, not inside it, so
96+
// the button names the page and the badge describes it.
97+
const describedBy = badge ? `${badgeId}-${index}` : undefined;
9398
return placement === "toolbar" ? (
9499
<span className="shell-toolbar-page" key={page.key}>
95100
<IconButton
96101
aria-label={label}
102+
aria-describedby={describedBy}
97103
title={label}
98104
variant="chrome"
99105
aria-current={selected === page.key ? "page" : undefined}
100106
onClick={select}
101107
icon={pageIcon}
102108
/>
103-
{badge && <span className="shell-toolbar-badge">{badge}</span>}
109+
{badge && (
110+
<span id={describedBy} className="shell-toolbar-badge">
111+
{badge}
112+
</span>
113+
)}
104114
</span>
105115
) : (
106116
<NavigationItem

0 commit comments

Comments
 (0)