fix(site/src/components/Filter/FilterCombobox): report the filter input collapsed while no list is shown (#32683)
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) |
<details>
<summary>Grouping and decision log</summary>
- 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 `<label>` with that id, and the input's name resolves to the
placeholder text in every state. Only `aria-controls` (and, on mobile,
`aria-activedescendant`) pointed at missing ids.
- The same change also fixes a mobile case: entering a category whose
options fail to load left `aria-expanded="true"` with `aria-controls`
and `aria-activedescendant` pointing at removed ids.
- Behavior change: a popup that is open but lists no rows yet (for
example while options load) now reads as collapsed.
- Rejected alternatives: (1) a plain `<input>` instead of cmdk's: it
would stop updating cmdk's search state, which drives the first-row
highlight, and cmdk does not expose its list id; (2) extending
`site/patches/cmdk@1.1.1.patch`: that means editing minified vendor code
and changing the lockfile.
- Tests: extends two existing `FilterCombobox.test.tsx` tests. One
asserts the input is collapsed with no `aria-controls` before opening,
then expanded and controlling the listbox after ArrowDown. The other
asserts the input is collapsed while the popup lists nothing. Both fail
on `main`.
- axe (4.11.1, `pages/WorkspacesPage` > `UnfilteredSingleResult`,
desktop and mobile): `aria-valid-attr-value` fired on `main` while
closed, in a category, and after Escape. On this branch it is clean in
every state (closed, open, ArrowDown, category, no match, Escape).
- Dropped review findings: (1) TS5/FE1 "no attribute assertions in
Vitest": `aria-expanded` and `aria-controls` are the accessibility state
this bug is about, and screenshots cannot capture them; (2) SD7
"single-use component": `asChild` needs a component child to receive
cmdk's props.
- Self-review: frontend-review (FE1 to FE10 pass); frontend-deep-review
(fixed: named `ChipsInputElementProps` type, clarified the doc comment);
frontend-accessibility (`aria-valid-attr-value`, `aria-required-attr`,
`aria-allowed-attr`, and the accessible name pass; keyboard and focus
behavior unchanged).
- Pre-existing notes, outside this diff: axe `aria-dialog-name` fires
while the popup is open, because the Radix popover content has
`role="dialog"` with no name. If the main panel and a category list
rendered together they would share cmdk's single list id; this did not
occur in the story.
</details>
🤖 Generated by Coder Agents on behalf of @bartekgatzcoder.
This commit is contained in:
1 parent
b4974c61f3
commit
b31ad5eb5a
2 files changed
+42
-2
No files matched your search
@@ -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 () => {
|
||||
|
||||
@@ -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 (
|
||||
<CommandPrimitive.Input
|
||||
{...passwordManagerIgnoreProps}
|
||||
asChild
|
||||
ref={ref}
|
||||
data-slot="combobox-chip-input"
|
||||
value={inputValue}
|
||||
@@ -558,6 +559,35 @@ export const FilterComboboxChipsInput: React.FC<
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChipsInputElement />
|
||||
</CommandPrimitive.Input>
|
||||
);
|
||||
};
|
||||
|
||||
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<ChipsInputElementProps> = ({
|
||||
"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 (
|
||||
<input
|
||||
{...props}
|
||||
role="combobox"
|
||||
aria-expanded={expanded}
|
||||
aria-controls={expanded ? ariaControls : undefined}
|
||||
aria-activedescendant={expanded ? ariaActiveDescendant : undefined}
|
||||
/>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user