GeezerVison is showing github.com — fix(web): make composer suggestions usable with screen readers (#10154) · RTVision/t3code@0cf482b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ComposerPromptEditorTiptap.tsx +25-1Lines changed: 25 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -121,6 +121,11 @@ export interface ComposerPromptEditorProps { | 121 | 121 | skills: ReadonlyArray<ServerProviderSkill>; | 122 | 122 | disabled: boolean; | 123 | 123 | placeholder: string; | | 124 | + ariaLabel?: string | undefined; | | 125 | + /** Identifies an editor with suggestions, even while its list is closed. */ | | 126 | + suggestionListId?: string | undefined; | | 127 | + /** References the highlighted option only while its list is rendered. */ | | 128 | + activeSuggestionId?: string | undefined; | 124 | 129 | containerClassName?: string; | 125 | 130 | className?: string; | 126 | 131 | placeholderClassName?: string; | @@ -592,6 +597,9 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) { | 592 | 597 | skills, | 593 | 598 | disabled, | 594 | 599 | placeholder, | | 600 | + ariaLabel, | | 601 | + suggestionListId, | | 602 | + activeSuggestionId, | 595 | 603 | containerClassName, | 596 | 604 | className, | 597 | 605 | placeholderClassName, | @@ -752,9 +760,25 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) { | 752 | 760 | ), | 753 | 761 | "data-testid": "composer-editor", | 754 | 762 | "data-composer-rich-text": richText ? "true" : "false", | | 763 | + role: "textbox", | | 764 | + "aria-multiline": "true", | | 765 | + ...(ariaLabel ? { "aria-label": ariaLabel } : {}), | | 766 | + ...(disabled ? { "aria-readonly": "true" } : {}), | | 767 | + ...(!disabled && suggestionListId | | 768 | + ? { | | 769 | + "aria-autocomplete": "list", | | 770 | + "aria-haspopup": "listbox", | | 771 | + ...(activeSuggestionId | | 772 | + ? { | | 773 | + "aria-controls": suggestionListId, | | 774 | + "aria-activedescendant": activeSuggestionId, | | 775 | + } | | 776 | + : {}), | | 777 | + } | | 778 | + : {}), | 755 | 779 | "aria-placeholder": placeholder, | 756 | 780 | }), | 757 | | - [className, placeholder, richText], | | 781 | + [activeSuggestionId, ariaLabel, className, disabled, placeholder, richText, suggestionListId], | 758 | 782 | ); | 759 | 783 |
| 760 | 784 | const editor = useEditor( | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/ChatComposer.tsx +33-3Lines changed: 33 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -58,6 +58,7 @@ import { | 58 | 58 | type ReactNode, | 59 | 59 | useCallback, | 60 | 60 | useEffect, | | 61 | + useId, | 61 | 62 | useImperativeHandle, | 62 | 63 | useLayoutEffect, | 63 | 64 | useMemo, | @@ -245,7 +246,11 @@ import { useEnvironmentQuery } from "~/state/query"; | 245 | 246 | import { useDebouncedValue } from "~/state/queries"; | 246 | 247 | import { ProviderModelPicker } from "./ProviderModelPicker"; | 247 | 248 | import { resolveModelPickerSelectedModel } from "./ModelPickerContent"; | 248 | | -import { type ComposerCommandItem, ComposerCommandMenu } from "./ComposerCommandMenu"; | | 249 | +import { | | 250 | + type ComposerCommandItem, | | 251 | + ComposerCommandMenu, | | 252 | + composerSuggestionOptionId, | | 253 | +} from "./ComposerCommandMenu"; | 249 | 254 | import { ComposerPendingApprovalActions } from "./ComposerPendingApprovalActions"; | 250 | 255 | import { CompactComposerControlsMenu } from "./CompactComposerControlsMenu"; | 251 | 256 | import { ComposerImageThumbnail } from "./ComposerImageThumbnail"; | @@ -2108,6 +2113,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) | 2108 | 2113 | resetTrigger: resetComposerTrigger, | 2109 | 2114 | } = useComposerTriggerState(() => detectComposerTrigger(prompt, prompt.length)); | 2110 | 2115 | const [composerHighlightedItemId, setComposerHighlightedItemId] = useState<string | null>(null); | | 2116 | + const composerSuggestionId = useId(); | | 2117 | + const composerSuggestionListId = `${composerSuggestionId}-${encodeURIComponent(draftId ?? activeThreadId ?? "new")}-suggestions`; | 2111 | 2118 | // Active ArrowUp recall. Cleared on edit and on thread switch. | 2112 | 2119 | const promptHistoryPositionRef = useRef<ComposerPromptHistoryPosition | null>(null); | 2113 | 2120 | const [composerHighlightedSearchKey, setComposerHighlightedSearchKey] = useState<string | null>( | @@ -2502,7 +2509,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) | 2502 | 2509 |
| 2503 | 2510 | const composerMenuOpen = Boolean(composerTrigger); | 2504 | 2511 | const composerMenuSearchKey = composerTrigger | 2505 | | - ? `${composerTrigger.kind}:${composerTrigger.query.trim().toLowerCase()}` | | 2512 | + ? `${composerSuggestionListId}:${composerTrigger.kind}:${composerTrigger.query.trim().toLowerCase()}` | 2506 | 2513 | : null; | 2507 | 2514 | const activeComposerMenuItem = useMemo(() => { | 2508 | 2515 | const activeItemId = resolveComposerMenuActiveItemId({ | @@ -2529,6 +2536,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) | 2529 | 2536 | ); | 2530 | 2537 |
| 2531 | 2538 | const isComposerApprovalState = activePendingApproval !== null; | | 2539 | + const composerSuggestionsVisible = composerMenuOpen && !isComposerApprovalState; | | 2540 | + const composerSuggestionListVisible = composerSuggestionsVisible && composerMenuItems.length > 0; | 2532 | 2541 | const activePendingUserInput = pendingUserInputs[0] ?? null; | 2533 | 2542 | const isChoiceOnlyPendingQuestion = | 2534 | 2543 | activePendingProgress?.activeQuestion?.allowCustomAnswer === false; | @@ -3176,6 +3185,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) | 3176 | 3185 | // ------------------------------------------------------------------ | 3177 | 3186 | useEffect(() => { | 3178 | 3187 | setComposerHighlightedItemId(null); | | 3188 | + setComposerHighlightedSearchKey(null); | 3179 | 3189 | setComposerSubmissionError(null); | 3180 | 3190 | setProviderInputSubmissionError(null); | 3181 | 3191 | setComposerCursor(collapseExpandedComposerCursor(promptRef.current, promptRef.current.length)); | @@ -6454,9 +6464,19 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) | 6454 | 6464 | </ComposerCommandMenuLayer> | 6455 | 6465 | )} | 6456 | 6466 |
| 6457 | | - {composerMenuOpen && !isComposerApprovalState && ( | | 6467 | + <div role="status" aria-atomic="true" className="sr-only"> | | 6468 | + {composerSuggestionsVisible && composerMenuItems.length === 0 | | 6469 | + ? isComposerMenuLoading | | 6470 | + ? composerTriggerKind === "pull-request" | | 6471 | + ? "Finding pull request..." | | 6472 | + : "Searching workspace files..." | | 6473 | + : composerMenuEmptyState | | 6474 | + : ""} | | 6475 | + </div> | | 6476 | + {composerSuggestionsVisible && ( | 6458 | 6477 | <ComposerCommandMenuLayer anchor={composerMenuAnchor}> | 6459 | 6478 | <ComposerCommandMenu | | 6479 | + listId={composerSuggestionListId} | 6460 | 6480 | items={composerMenuItems} | 6461 | 6481 | resolvedTheme={resolvedTheme} | 6462 | 6482 | isLoading={isComposerMenuLoading} | @@ -6845,6 +6865,16 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) | 6845 | 6865 | ) : null} | 6846 | 6866 | <ComposerContextActionsContext value={composerContextActions}> | 6847 | 6867 | <ComposerPromptEditor | | 6868 | + ariaLabel="Message" | | 6869 | + suggestionListId={composerSuggestionListId} | | 6870 | + activeSuggestionId={ | | 6871 | + composerSuggestionListVisible && activeComposerMenuItem | | 6872 | + ? composerSuggestionOptionId( | | 6873 | + composerSuggestionListId, | | 6874 | + activeComposerMenuItem.id, | | 6875 | + ) | | 6876 | + : undefined | | 6877 | + } | 6848 | 6878 | editorRef={composerEditorRef} | 6849 | 6879 | richTextEnabled={settings.composerRichTextEnabled} | 6850 | 6880 | value={ | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/ComposerCommandMenu.test.tsx +28-1Lines changed: 28 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,12 +2,37 @@ import { renderToStaticMarkup } from "react-dom/server"; | 2 | 2 | import { ProviderDriverKind } from "@t3tools/contracts"; | 3 | 3 | import { describe, expect, it } from "vite-plus/test"; | 4 | 4 |
| 5 | | -import { ComposerCommandMenu } from "./ComposerCommandMenu"; | | 5 | +import { ComposerCommandMenu, composerSuggestionOptionId } from "./ComposerCommandMenu"; | | 6 | + | | 7 | +describe("composerSuggestionOptionId", () => { | | 8 | + it("keeps whitespace, escape-like paths, and malformed UTF-16 distinct", () => { | | 9 | + const paths = [ | | 10 | + "docs/my file.md", | | 11 | + "docs/my_file.md", | | 12 | + "docs/my%20file.md", | | 13 | + "docs/my\tfile.md", | | 14 | + "docs/\ud800.md", | | 15 | + "docs/\ud801.md", | | 16 | + "docs/\udc00.md", | | 17 | + "docs/\ufffd.md", | | 18 | + "docs/\\ud800.md", | | 19 | + "docs/\ud83d\ude80.md", | | 20 | + ]; | | 21 | + const ids = paths.map((path) => composerSuggestionOptionId("suggestions", `path:file:${path}`)); | | 22 | + | | 23 | + expect(new Set(ids).size).toBe(paths.length); | | 24 | + for (const id of ids) expect(id).not.toMatch(/\s|[\ud800-\udfff]/u); | | 25 | + expect(composerSuggestionOptionId("other-composer", paths[0]!)).not.toBe( | | 26 | + composerSuggestionOptionId("suggestions", paths[0]!), | | 27 | + ); | | 28 | + }); | | 29 | +}); | 6 | 30 |
| 7 | 31 | describe("ComposerCommandMenu", () => { | 8 | 32 | it("renders slash commands with their descriptions", () => { | 9 | 33 | const markup = renderToStaticMarkup( | 10 | 34 | <ComposerCommandMenu | | 35 | + listId="test-suggestions" | 11 | 36 | items={[ | 12 | 37 | { | 13 | 38 | id: "slash:model", | @@ -33,6 +58,7 @@ describe("ComposerCommandMenu", () => { | 33 | 58 | it("shows the app source for an app skill", () => { | 34 | 59 | const markup = renderToStaticMarkup( | 35 | 60 | <ComposerCommandMenu | | 61 | + listId="test-suggestions" | 36 | 62 | items={[ | 37 | 63 | { | 38 | 64 | id: "skill:codex:browser", | @@ -67,6 +93,7 @@ describe("ComposerCommandMenu", () => { | 67 | 93 | it("shows the repo source for a slash skill", () => { | 68 | 94 | const markup = renderToStaticMarkup( | 69 | 95 | <ComposerCommandMenu | | 96 | + listId="test-suggestions" | 70 | 97 | items={[ | 71 | 98 | { | 72 | 99 | id: "skill:codex:ask-matt", | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/ComposerCommandMenu.tsx +22-1Lines changed: 22 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -69,6 +69,7 @@ export type ComposerCommandItem = | 69 | 69 | }; | 70 | 70 |
| 71 | 71 | export const ComposerCommandMenu = memo(function ComposerCommandMenu(props: { | | 72 | + listId: string; | 72 | 73 | items: ComposerCommandItem[]; | 73 | 74 | resolvedTheme: "light" | "dark"; | 74 | 75 | isLoading: boolean; | @@ -104,11 +105,16 @@ export const ComposerCommandMenu = memo(function ComposerCommandMenu(props: { | 104 | 105 | data-composer-command-drawer="true" | 105 | 106 | > | 106 | 107 | {props.items.length > 0 ? ( | 107 | | - <CommandList className="max-h-72 min-h-0 scroll-pb-6"> | | 108 | + <CommandList | | 109 | + id={props.listId} | | 110 | + aria-label={props.triggerKind ? LISTBOX_LABEL_BY_TRIGGER[props.triggerKind] : undefined} | | 111 | + className="max-h-72 min-h-0 scroll-pb-6" | | 112 | + > | 108 | 113 | <CommandGroup> | 109 | 114 | {props.items.map((item) => ( | 110 | 115 | <ComposerCommandMenuItem | 111 | 116 | key={item.id} | | 117 | + optionId={composerSuggestionOptionId(props.listId, item.id)} | 112 | 118 | item={item} | 113 | 119 | triggerKind={props.triggerKind} | 114 | 120 | resolvedTheme={props.resolvedTheme} | @@ -143,6 +149,7 @@ export const ComposerCommandMenu = memo(function ComposerCommandMenu(props: { | 143 | 149 | }); | 144 | 150 |
| 145 | 151 | const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: { | | 152 | + optionId: string; | 146 | 153 | item: ComposerCommandItem; | 147 | 154 | triggerKind: ComposerTriggerKind | null; | 148 | 155 | resolvedTheme: "light" | "dark"; | @@ -159,6 +166,8 @@ const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: { | 159 | 166 |
| 160 | 167 | return ( | 161 | 168 | <CommandItem | | 169 | + render={<div id={props.optionId} />} | | 170 | + aria-selected={props.isActive} | 162 | 171 | value={props.item.id} | 163 | 172 | data-composer-item-id={props.item.id} | 164 | 173 | active={props.isActive} | @@ -211,6 +220,18 @@ const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: { | 211 | 220 | ); | 212 | 221 | }); | 213 | 222 |
| | 223 | +export function composerSuggestionOptionId(listId: string, itemId: string): string { | | 224 | + // JSON escapes lone UTF-16 surrogates before URI encoding without losing identity. | | 225 | + return `${listId}-${encodeURIComponent(JSON.stringify(itemId))}`; | | 226 | +} | | 227 | + | | 228 | +const LISTBOX_LABEL_BY_TRIGGER: Record<ComposerTriggerKind, string> = { | | 229 | + path: "Files and folders", | | 230 | + "pull-request": "Pull requests", | | 231 | + "slash-command": "Commands", | | 232 | + skill: "Skills", | | 233 | +}; | | 234 | + | 214 | 235 | const SKILL_SOURCE_ICON_BY_KIND: Record<ProviderSkillSourceKind, LucideIcon> = { | 215 | 236 | app: BlocksIcon, | 216 | 237 | repo: FolderIcon, | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/composerMenuHighlight.test.ts +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -48,4 +48,21 @@ describe("resolveComposerMenuActiveItemId", () => { | 48 | 48 | }), | 49 | 49 | ).toBe("top"); | 50 | 50 | }); | | 51 | + | | 52 | + it("clears the active result while async results are empty and resolves against restored results", () => { | | 53 | + const search = { | | 54 | + highlightedItemId: "second", | | 55 | + currentSearchKey: "path:src", | | 56 | + highlightedSearchKey: "path:src", | | 57 | + }; | | 58 | + const cleared = resolveComposerMenuActiveItemId({ ...search, items: [] }); | | 59 | + expect(cleared).toBeNull(); | | 60 | + expect( | | 61 | + resolveComposerMenuActiveItemId({ | | 62 | + ...search, | | 63 | + highlightedItemId: cleared, | | 64 | + items: [{ id: "new-result" }, { id: "second" }], | | 65 | + }), | | 66 | + ).toBe("new-result"); | | 67 | + }); | 51 | 68 | }); |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/settings/SettingsFontPreviews.tsx +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,6 +39,7 @@ export function PromptFontPreview() { | 39 | 39 | return ( | 40 | 40 | <div className="mt-1 mb-2 rounded-lg border border-border bg-background px-3 py-2"> | 41 | 41 | <ComposerPromptEditor | | 42 | + ariaLabel="Prompt font preview" | 42 | 43 | editorRef={editorRef} | 43 | 44 | value={prompt} | 44 | 45 | cursor={cursor} | |
|