From b31ad5eb5a66d37f3446f49770a24eb02abb014e Mon Sep 17 00:00:00 2001 From: Bartek Gatz Date: Wed, 25 Nov 2026 14:48:32 +0100 Subject: [PATCH] fix(site/src/components/Filter/FilterCombobox): report the filter input collapsed while no list is shown (#32683) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The filter search input ("Search and filter workspaces…", plus the Audit, Templates, and Connection log filters) always reported `aria-expanded="true"` and pointed `aria-controls` at cmdk's list id, even while no list was mounted. axe flagged `aria-valid-attr-value` (critical, WCAG 4.1.2), and screen readers announced a popup that did not exist. cmdk 1.1.1's `Command.Input` sets these attributes after the caller's props, so callers cannot override them. `FilterComboboxChipsInput` now renders cmdk's input through `asChild` into a small element that derives `aria-expanded` from cmdk's `useCommandState` (`filtered.count > 0`; with filtering off, items mount only in the open popup's lists). It passes `aria-controls` and `aria-activedescendant` through only while the input is expanded. cmdk still owns the value, the search sync that highlights the first row, the ids, `aria-labelledby`, and keyboard handling. Closes DEQ-624 | Ticket | UI surface | |---|---| | DEQ-624 | `FilterCombobox` search input on the Workspaces, Audit, Templates, and Connection log pages (ARIA only, no visual change) |
Grouping and decision log - Batch `bug-batch-2` has six tickets with six independent root causes, so each gets its own PR. This one covers only DEQ-624. - `aria-labelledby` was never broken: the cmdk root always renders a hidden `
🤖 Generated by Coder Agents on behalf of @bartekgatzcoder. --- .../FilterCombobox/FilterCombobox.test.tsx | 12 ++++++- .../Filter/FilterCombobox/primitives.tsx | 32 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/site/src/components/Filter/FilterCombobox/FilterCombobox.test.tsx b/site/src/components/Filter/FilterCombobox/FilterCombobox.test.tsx index cba6ace07b0..3e36c2d7872 100644 --- a/site/src/components/Filter/FilterCombobox/FilterCombobox.test.tsx +++ b/site/src/components/Filter/FilterCombobox/FilterCombobox.test.tsx @@ -669,9 +669,17 @@ describe("FilterCombobox", () => { await user.tab(); expect(filtersButton).toHaveFocus(); + expect(input).toHaveAttribute("aria-expanded", "false"); + expect(input).not.toHaveAttribute("aria-controls"); await user.keyboard("{Enter}"); expect(input).toHaveFocus(); - await user.keyboard("{ArrowDown}{ArrowRight}"); + await user.keyboard("{ArrowDown}"); + expect(input).toHaveAttribute("aria-expanded", "true"); + expect(input).toHaveAttribute( + "aria-controls", + screen.getByRole("listbox").id, + ); + await user.keyboard("{ArrowRight}"); await screen.findByRole("option", { name: "alice" }); await user.keyboard("{ArrowDown}{Enter}"); @@ -1723,6 +1731,8 @@ describe("FilterCombobox", () => { await waitFor(() => expect(screen.getByRole("status")).toHaveTextContent("No filters found"), ); + expect(input).toHaveAttribute("aria-expanded", "false"); + expect(input).not.toHaveAttribute("aria-controls"); }); it("announces a category search with no match", async () => { diff --git a/site/src/components/Filter/FilterCombobox/primitives.tsx b/site/src/components/Filter/FilterCombobox/primitives.tsx index dda37b9a5da..24482cf2705 100644 --- a/site/src/components/Filter/FilterCombobox/primitives.tsx +++ b/site/src/components/Filter/FilterCombobox/primitives.tsx @@ -1,4 +1,4 @@ -import { Command as CommandPrimitive } from "cmdk"; +import { Command as CommandPrimitive, useCommandState } from "cmdk"; import { cn } from "cn"; import { XIcon } from "lucide-react"; import { @@ -543,6 +543,7 @@ export const FilterComboboxChipsInput: React.FC< return ( + + + ); +}; + +type ChipsInputElementProps = React.ComponentProps<"input">; + +/** + * Renders cmdk's input from the props `asChild` passes in. cmdk sets its ARIA + * props after the caller's, always marking the input expanded and pointing it + * at its list and highlighted row, even while neither is mounted. + */ +const ChipsInputElement: React.FC = ({ + "aria-controls": ariaControls, + "aria-activedescendant": ariaActiveDescendant, + ...props +}) => { + // With filtering off, cmdk counts every mounted item, and items mount only + // in the open popup's lists. + const expanded = useCommandState((state) => state.filtered.count > 0); + + return ( + ); };