@devries-cameron20 / t3code-1 / commits / 6cdbf76fa4
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

feat(web): expose each chat message as a heading for screen readers (#11199)

Khai Shern, Toh committed Sep 13, 2026 at 08:56 UTC 6cdbf76fa4b0509913046abe6105037ded9e52bb
4 files changed +78 -2
apps/web/src/components/ChatMarkdown.test.tsx
+22
@@ -694,6 +694,28 @@ describe("ChatMarkdown artifact-template cards", () => {
694 });
695 });
696
697 +describe("ChatMarkdown heading levels", () => {
698 + it("exposes headings below the host heading without changing their tags", () => {
699 + const html = renderToStaticMarkup(
700 + <ChatMarkdown
701 + cwd="/tmp/project"
702 + text={"# Top\n\n## Section\n\n###### Fine print"}
703 + headingLevelOffset={3}
704 + />,
705 + );
706 +
707 + expect(html).toContain('<h1 aria-level="4">Top</h1>');
708 + expect(html).toContain('<h2 aria-level="5">Section</h2>');
709 + expect(html).toContain('<h6 aria-level="6">Fine print</h6>');
710 + });
711 +
712 + it("leaves heading levels alone when the markdown is not nested", () => {
713 + const html = renderToStaticMarkup(<ChatMarkdown cwd="/tmp/project" text="# Top" />);
714 +
715 + expect(html).toContain("<h1>Top</h1>");
716 + });
717 +});
718 +
719 describe("shouldUseMarkdownFileBrowserPrimaryAction", () => {
720 it("uses the browser when it is the only available primary action", () => {
721 expect(
apps/web/src/components/ChatMarkdown.tsx
+37 -1
@@ -71,7 +71,11 @@ import React, {
71 useState,
72 type ReactNode,
73 } from "react";
74 -import type { Components, Options as ReactMarkdownOptions } from "react-markdown";
74 +import type {
75 + Components,
76 + ExtraProps as ReactMarkdownExtraProps,
77 + Options as ReactMarkdownOptions,
78 +} from "react-markdown";
79 import ReactMarkdown from "react-markdown";
80 import { toHtml } from "hast-util-to-html";
81 import { createIncrementalMarkdownPlugin } from "../markdown-incremental";
@@ -216,6 +220,10 @@ interface ChatMarkdownProps {
220 extraRemarkPlugins?: NonNullable<ReactMarkdownOptions["remarkPlugins"]>;
221 /** Renders a `t3-context://` link as a chip; without it the link shows its label as text. */
222 renderContextReference?: ((reference: ChatMarkdownContextReference) => ReactNode) | undefined;
223 + /** Levels added to each markdown heading in the accessibility tree so the
224 + text nests under the heading that introduces it, such as a chat message's
225 + author. Rendered tags and their styling are unchanged. */
226 + headingLevelOffset?: number | undefined;
227 }
228
229 export interface ChatMarkdownContextReference {
@@ -2217,6 +2225,7 @@ function useChatMarkdownState({
2225 imageBaseDir,
2226 onImageExpand,
2227 renderContextReference,
2228 + headingLevelOffset = 0,
2229 }: ChatMarkdownProps) {
2230 const { resolvedTheme } = useTheme();
2231 const [localMediaPreview, setLocalMediaPreview] = useState<ExpandedImagePreview | null>(null);
@@ -2615,6 +2624,7 @@ function useChatMarkdownState({
2624 expandMedia,
2625 fileLinkChip,
2626 renderContextReference,
2627 + headingLevelOffset,
2628 imageBaseDir,
2629 inlineCodeFileLinkMetaByText,
2630 isStreaming,
@@ -2643,6 +2653,7 @@ function useChatMarkdownState({
2653 expandMedia,
2654 fileLinkChip,
2655 renderContextReference,
2656 + headingLevelOffset,
2657 imageBaseDir,
2658 inlineCodeFileLinkMetaByText,
2659 isStreaming,
@@ -2679,8 +2690,33 @@ const ChatMarkdownRendererContext = React.createContext<
2690 ReturnType<typeof useChatMarkdownState>["componentState"]
2691 >(null!);
2692
2693 +// Screen readers take a heading's level from its tag, which would let a `#` in a
2694 +// message outrank the heading placed above it. Override only the exposed level:
2695 +// the tag keeps driving the stylesheet and copy-as-markdown.
2696 +function markdownHeadingRenderer(level: 1 | 2 | 3 | 4 | 5 | 6) {
2697 + const Tag = `h${level}` as const;
2698 + return function MarkdownHeading({
2699 + node: _node,
2700 + ...props
2701 + }: ComponentProps<typeof Tag> & ReactMarkdownExtraProps) {
2702 + const { headingLevelOffset } = use(ChatMarkdownRendererContext);
2703 + return (
2704 + <Tag
2705 + {...props}
2706 + aria-level={headingLevelOffset > 0 ? Math.min(level + headingLevelOffset, 6) : undefined}
2707 + />
2708 + );
2709 + };
2710 +}
2711 +
2712 // Keep component types stable when streaming changes the message state.
2713 const CHAT_MARKDOWN_COMPONENTS = {
2714 + h1: markdownHeadingRenderer(1),
2715 + h2: markdownHeadingRenderer(2),
2716 + h3: markdownHeadingRenderer(3),
2717 + h4: markdownHeadingRenderer(4),
2718 + h5: markdownHeadingRenderer(5),
2719 + h6: markdownHeadingRenderer(6),
2720 div: function MarkdownDiv({ node, children, ...props }) {
2721 const { onUseArtifactTemplate } = use(ChatMarkdownRendererContext);
2722 const artifactTemplate = artifactTemplateFromHastProperties(node?.properties);
apps/web/src/components/chat/MessagesTimeline.tsx
+14
@@ -1455,6 +1455,16 @@ function UserVideoAttachment({ file }: { readonly file: ChatFileAttachment }) {
1455 );
1456 }
1457
1458 +// Screen readers skim a transcript by heading, so every message announces its
1459 +// author as one. The thread title in ChatHeader is an <h2>; headings written
1460 +// inside a message are exposed below this level. Visually hidden and excluded
1461 +// from selection so sighted users and copied text are unaffected.
1462 +const MESSAGE_HEADING_LEVEL = 3;
1463 +
1464 +function MessageAuthorHeading({ children }: { children: string }) {
1465 + return <h3 className="sr-only select-none">{children}</h3>;
1466 +}
1467 +
1468 function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
1469 const ctx = use(TimelineRowCtx);
1470 const { onImageExpand, onFileOpen } = ctx;
@@ -1614,6 +1624,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
1624 return (
1625 <div className="group flex flex-col items-end gap-1">
1626 <div className="relative max-w-[80%] rounded-2xl bg-message p-3 text-message-foreground">
1627 + <MessageAuthorHeading>You</MessageAuthorHeading>
1628 {(regularImages.length > 0 || userVideos.length > 0) && (
1629 <div className="mb-2 grid max-w-[210px] grid-cols-2 gap-2">
1630 {regularImages.map((image) => (
@@ -1845,6 +1856,7 @@ function AssistantTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "mess
1856 return (
1857 <>
1858 <div className="relative min-w-0 px-1 py-0.5">
1859 + <MessageAuthorHeading>T3 Code</MessageAuthorHeading>
1860 <AssistantCitationSource
1861 messageId={row.message.id}
1862 {...(ctx.threadRef ? { threadRef: ctx.threadRef } : {})}
@@ -1859,6 +1871,7 @@ function AssistantTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "mess
1871 isStreaming={Boolean(row.message.streaming)}
1872 lineBreaks={shouldPreserveAssistantLineBreaks(messageText)}
1873 skills={ctx.skills}
1874 + headingLevelOffset={MESSAGE_HEADING_LEVEL}
1875 onUseArtifactTemplate={ctx.onUseArtifactTemplate}
1876 onImageExpand={ctx.onImageExpand}
1877 />
@@ -3214,6 +3227,7 @@ const UserMessageBody = memo(function UserMessageBody(props: {
3227 lineBreaks
3228 parseRawHtml={false}
3229 renderContextReference={props.renderContextReference}
3230 + headingLevelOffset={MESSAGE_HEADING_LEVEL}
3231 />
3232 );
3233 });
apps/web/src/components/chat/ProposedPlanCard.tsx
+5 -1
@@ -150,7 +150,9 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({
150 <div className="flex flex-wrap items-center justify-between gap-3">
151 <div className="flex min-w-0 items-center gap-2">
152 <Badge variant="secondary">Plan</Badge>
153 - <p className="truncate text-sm font-medium text-foreground">{title}</p>
153 + {/* Same heading level as the message author headings in the timeline,
154 + so a plan's own headings nest beneath it in the outline. */}
155 + <h3 className="truncate text-sm font-medium text-foreground">{title}</h3>
156 </div>
157 <Menu>
158 <MenuTrigger
@@ -177,6 +179,7 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({
179 cwd={cwd}
180 threadRef={threadRef}
181 isStreaming={false}
182 + headingLevelOffset={3}
183 />
184 ) : (
185 <ChatMarkdown
@@ -184,6 +187,7 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({
187 cwd={cwd}
188 threadRef={threadRef}
189 isStreaming={false}
190 + headingLevelOffset={3}
191 />
192 )}
193 {canCollapse && !expanded ? (