Skip to content
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
9 changes: 9 additions & 0 deletions .changeset/light-moose-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"streamdown": patch
---

Fix accessibility warnings for Mermaid toolbar icon buttons:

- Add `aria-hidden="true"` to all decorative SVG icons to hide them from screen readers
- Add `aria-label` attributes to all icon-only buttons for proper screen reader announcements
- Add translation keys (`zoomIn`, `zoomOut`, `resetView`) for zoom controls
8 changes: 4 additions & 4 deletions packages/streamdown/__tests__/mermaid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ describe("Mermaid", () => {
});

const mmdButton = await waitFor(() =>
getByRole("button", { name: "MMD" })
getByRole("button", { name: "Download diagram as MMD" })
);

await act(() => {
Expand Down Expand Up @@ -553,7 +553,7 @@ describe("Mermaid", () => {
});

const svgButton = await waitFor(() =>
getByRole("button", { name: "SVG" })
getByRole("button", { name: "Download diagram as SVG" })
);

await act(() => {
Expand Down Expand Up @@ -624,7 +624,7 @@ describe("Mermaid", () => {
});

const pngButton = await waitFor(() =>
getByRole("button", { name: "PNG" })
getByRole("button", { name: "Download diagram as PNG" })
);

await act(() => {
Expand Down Expand Up @@ -665,7 +665,7 @@ describe("Mermaid", () => {
});

const svgButton = await waitFor(() =>
getByRole("button", { name: "SVG" })
getByRole("button", { name: "Download diagram as SVG" })
);

await act(() => {
Expand Down
3 changes: 2 additions & 1 deletion packages/streamdown/lib/code-block/copy-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const CodeBlockCopyButton = ({

return (
<button
aria-label={t.copyCode}
className={cn(
"cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",
className
Expand All @@ -78,7 +79,7 @@ export const CodeBlockCopyButton = ({
type="button"
{...props}
>
{children ?? <Icon size={14} />}
{children ?? <Icon aria-hidden="true" size={14} />}
</button>
);
};
6 changes: 5 additions & 1 deletion packages/streamdown/lib/mermaid/download-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export const MermaidDownloadDropdown = ({
return (
<div className={cn("relative")} ref={dropdownRef}>
<button
aria-label={t.downloadDiagram}
className={cn(
"cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",
className
Expand All @@ -116,7 +117,7 @@ export const MermaidDownloadDropdown = ({
title={t.downloadDiagram}
type="button"
>
{children ?? <icons.DownloadIcon size={14} />}
{children ?? <icons.DownloadIcon aria-hidden="true" size={14} />}
</button>
{isOpen ? (
<div
Expand All @@ -125,6 +126,7 @@ export const MermaidDownloadDropdown = ({
)}
>
<button
aria-label={t.downloadDiagramAsSvg}
className={cn(
"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"
)}
Expand All @@ -135,6 +137,7 @@ export const MermaidDownloadDropdown = ({
{t.mermaidFormatSvg}
</button>
<button
aria-label={t.downloadDiagramAsPng}
className={cn(
"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"
)}
Expand All @@ -145,6 +148,7 @@ export const MermaidDownloadDropdown = ({
{t.mermaidFormatPng}
</button>
<button
aria-label={t.downloadDiagramAsMmd}
className={cn(
"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"
)}
Expand Down
6 changes: 4 additions & 2 deletions packages/streamdown/lib/mermaid/fullscreen-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ export const MermaidFullscreenButton = ({
title={t.viewFullscreen}
type="button"
{...props}
aria-label={t.viewFullscreen}
>
<Maximize2Icon size={14} />
<Maximize2Icon aria-hidden="true" size={14} />
</button>

{isFullscreen
Expand All @@ -108,14 +109,15 @@ export const MermaidFullscreenButton = ({
tabIndex={0}
>
<button
aria-label={t.exitFullscreen}
className={cn(
"absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"
)}
onClick={handleToggle}
title={t.exitFullscreen}
type="button"
>
<XIcon size={20} />
<XIcon aria-hidden="true" size={20} />
</button>
{/* biome-ignore lint/a11y/noStaticElementInteractions: "div with role=presentation is used for event propagation control" */}
<div
Expand Down
17 changes: 11 additions & 6 deletions packages/streamdown/lib/mermaid/pan-zoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ReactNode } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import { useIcons } from "../icon-context";
import { useCn } from "../prefix-context";
import { useTranslations } from "../translations-context";

interface PanZoomProps {
children: ReactNode;
Expand All @@ -26,6 +27,7 @@ export const PanZoom = ({
}: PanZoomProps) => {
const { RotateCcwIcon, ZoomInIcon, ZoomOutIcon } = useIcons();
const cn = useCn();
const t = useTranslations();
const containerRef = useRef<HTMLDivElement>(null);
const contentRef = useRef<HTMLDivElement>(null);
const [zoom, setZoom] = useState(initialZoom);
Expand Down Expand Up @@ -167,36 +169,39 @@ export const PanZoom = ({
)}
>
<button
aria-label={t.zoomIn}
className={cn(
"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"
)}
disabled={zoom >= maxZoom}
onClick={handleZoomIn}
title="Zoom in"
title={t.zoomIn}
type="button"
>
<ZoomInIcon size={16} />
<ZoomInIcon aria-hidden="true" size={16} />
</button>
<button
aria-label={t.zoomOut}
className={cn(
"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"
)}
disabled={zoom <= minZoom}
onClick={handleZoomOut}
title="Zoom out"
title={t.zoomOut}
type="button"
>
<ZoomOutIcon size={16} />
<ZoomOutIcon aria-hidden="true" size={16} />
</button>
<button
aria-label={t.resetView}
className={cn(
"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
)}
onClick={handleReset}
title="Reset zoom and pan"
title={t.resetView}
type="button"
>
<RotateCcwIcon size={16} />
<RotateCcwIcon aria-hidden="true" size={16} />
</button>
</div>
) : null}
Expand Down
6 changes: 6 additions & 0 deletions packages/streamdown/lib/translations-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ export interface StreamdownTranslations {
mermaidFormatSvg: string;
openExternalLink: string;
openLink: string;
resetView: string;
tableFormatCsv: string;
tableFormatMarkdown: string;
tableFormatTsv: string;
viewFullscreen: string;
zoomIn: string;
zoomOut: string;
}

export const defaultTranslations: StreamdownTranslations = {
Expand All @@ -53,6 +56,9 @@ export const defaultTranslations: StreamdownTranslations = {
mermaidFormatSvg: "SVG",
mermaidFormatPng: "PNG",
mermaidFormatMmd: "MMD",
zoomIn: "Zoom in",
zoomOut: "Zoom out",
resetView: "Reset zoom and pan",
// Table
copyTable: "Copy table",
copyTableAsMarkdown: "Copy table as Markdown",
Expand Down
Loading