fix(site/src): name MultiSelectCombobox remove and clear-all buttons (#32763)
The per-badge remove button and the clear-all button in
`MultiSelectCombobox` rendered only an `XIcon`, so they had no
accessible name and axe reported `button-name` (WCAG 4.1.2). They are
now named "Remove <option label>" and "Clear all", matching `TagInput`
and `FilterCombobox`. The `data-testid` attributes are removed, and
every caller now queries the buttons by role and name.
Enter already activates each button once, not twice as the ticket
suspected: cmdk's root `onKeyDown` prevents the default of Enter, so the
native click never fires and the button's own Enter handler is the only
path. A short comment now explains why those handlers must stay, and a
new test guards it.
Closes DEQ-664
| Ticket | UI surface |
|---|---|
| DEQ-664 | `MultiSelectCombobox` badge remove and clear-all buttons:
IdP organization, group, and role sync; OAuth2 app form scopes;
multi-select dynamic parameters. Accessible names only, no visual
change. |
**Dropped review findings**
- Focus is lost after a keyboard removal (frontend-accessibility manual
focus check, SA6). When Enter removes a badge or clears all, the focused
button unmounts and focus falls to `<body>`. This happens on `main` too
and is not caused by this diff. Fixing it would mean new focus
management (for example, moving focus to the input), which is a behavior
change outside this ticket. It should be its own ticket.
<details>
<summary>Decision log</summary>
- **Names:** I followed the existing `Remove ${value}` pattern
(`TagInput`, `FilterCombobox` chips) and the "Clear all" copy
(`FilterCombobox`). `aria-label` is correct here because the buttons
have no visible text.
- **Enter behavior:** In jsdom and in real Chromium (Vitest browser
mode), Enter on either button calls `onChange` exactly once on `main`.
Removing the button's Enter handler makes Enter do nothing (0 calls),
because cmdk calls `preventDefault()` on Enter. So the handlers stay.
Space and Backspace/Delete in the input are unchanged.
- **Tests:** They extend the existing "Multi-Select Parameter" block in
`DynamicParameter.test.tsx`, which renders `MultiSelectCombobox` (same
place as #32678). "handles option deselection" now clicks "Remove Option
1" and expects `onChange` exactly once. A new `it.each` presses Enter on
"Remove Option 1" and "Clear all" and expects one call with
`["option2"]` and `[]`. All three fail on `main` (no named buttons). The
Enter cases also fail with 0 calls when the Enter handlers are removed.
- **Callers:** `OAuth2AppForm.test.tsx` and the `OAuth2AppForm` and
`MultiSelectCombobox` stories now use the role queries. The clicked
badge is the same one as before, so screenshots are unchanged. Nothing
under `site/e2e` used the test IDs.
- **Story cleanup:** `ClearAllComboboxItems` no longer ends with a
`waitFor(... toBeInTheDocument())` assertion, because play functions
must not assert (FE1) and this diff edits that play.
- **Commit scope:** The scope is `site/src` because the changed tests
live under `modules/` and `pages/`.
- **Self-review:** frontend-review (FE1 to FE10 pass);
frontend-deep-review (two findings fixed, the story assertion and the
Enter rationale comment, then a clean second pass);
frontend-accessibility: a full axe run in Chromium on the component with
badges selected, closed and open, gives `button-name` 3 violations on
`main` and 0 on this branch.
- **Pre-existing, untouched:** axe reports `aria-valid-attr-value` on
the closed cmdk input (`aria-controls` points at the unmounted list) on
both `main` and this branch.
</details>
🤖 Generated by Coder Agents on behalf of @bartekgatzcoder.
This commit is contained in:
1 parent
4e82a34246
commit
a81eecdb71
5 files changed
+41
-18
No files matched your search
@@ -131,7 +131,9 @@ export const ClearFirstSelectedItem: Story = {
|
||||
await userEvent.click(
|
||||
canvas.getByRole("option", { name: "My Organization 2" }),
|
||||
);
|
||||
await userEvent.click(canvas.getAllByTestId("clear-option-button")[0]);
|
||||
await userEvent.click(
|
||||
canvas.getByRole("button", { name: "Remove My Organization" }),
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -142,13 +144,7 @@ export const ClearAllComboboxItems: Story = {
|
||||
await userEvent.click(
|
||||
canvas.getByRole("option", { name: "My Organization" }),
|
||||
);
|
||||
await userEvent.click(canvas.getByTestId("clear-all-button"));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
canvas.getByPlaceholderText("Select organization"),
|
||||
).toBeInTheDocument(),
|
||||
);
|
||||
await userEvent.click(canvas.getByRole("button", { name: "Clear all" }));
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -484,12 +484,13 @@ export const MultiSelectCombobox: React.FC<MultiSelectComboboxProps> = ({
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
data-testid="clear-option-button"
|
||||
aria-label={`Remove ${option.label}`}
|
||||
className={cn(
|
||||
"ml-1 pr-0 rounded-sm bg-transparent border-none outline-hidden",
|
||||
"focus-visible:ring-2 focus-visible:ring-content-link focus-visible:ml-2.5 focus-visible:pl-0 cursor-pointer",
|
||||
(disabled || option.fixed) && "hidden",
|
||||
)}
|
||||
// cmdk prevents the default of Enter, so Enter never fires a native click.
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
handleUnselect(option);
|
||||
@@ -548,11 +549,12 @@ export const MultiSelectCombobox: React.FC<MultiSelectComboboxProps> = ({
|
||||
<div className="flex items-center justify-between">
|
||||
<button
|
||||
type="button"
|
||||
data-testid="clear-all-button"
|
||||
aria-label="Clear all"
|
||||
onClick={() => {
|
||||
setSelected(fixedOptions);
|
||||
onChange?.(fixedOptions);
|
||||
}}
|
||||
// cmdk prevents the default of Enter, so Enter never fires a native click.
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
setSelected(fixedOptions);
|
||||
|
||||
@@ -622,13 +622,34 @@ describe("DynamicParameter", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
const removeButtons = screen.getAllByTestId("clear-option-button");
|
||||
await waitFor(async () => {
|
||||
await userEvent.click(removeButtons[0]);
|
||||
});
|
||||
await userEvent.click(
|
||||
screen.getByRole("button", { name: "Remove Option 1" }),
|
||||
);
|
||||
|
||||
expect(mockOnChange).toHaveBeenCalledWith('["option2"]');
|
||||
expect(mockOnChange).toHaveBeenCalledExactlyOnceWith('["option2"]');
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ name: "Remove Option 1", expectedValue: '["option2"]' },
|
||||
{ name: "Clear all", expectedValue: "[]" },
|
||||
])(
|
||||
"calls onChange once when Enter activates $name",
|
||||
async ({ name, expectedValue }) => {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<DynamicParameter
|
||||
parameter={mockMultiSelectParameter}
|
||||
value='["option1", "option2"]'
|
||||
onChange={mockOnChange}
|
||||
/>,
|
||||
);
|
||||
|
||||
act(() => screen.getByRole("button", { name }).focus());
|
||||
await user.keyboard("{Enter}");
|
||||
|
||||
expect(mockOnChange).toHaveBeenCalledExactlyOnceWith(expectedValue);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("Error Parameter", () => {
|
||||
|
||||
+6
-2
@@ -104,7 +104,9 @@ export const SelfRegisteredScopesNarrowed: Story = {
|
||||
},
|
||||
play: async ({ canvasElement }) => {
|
||||
await userEvent.click(
|
||||
within(canvasElement).getAllByTestId("clear-option-button")[0],
|
||||
within(canvasElement).getByRole("button", {
|
||||
name: "Remove coder:workspaces.access",
|
||||
}),
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -113,7 +115,9 @@ export const AdminCreatedScopesNarrowed: Story = {
|
||||
args: { app: appWithScopes },
|
||||
play: async ({ canvasElement }) => {
|
||||
await userEvent.click(
|
||||
within(canvasElement).getAllByTestId("clear-option-button")[0],
|
||||
within(canvasElement).getByRole("button", {
|
||||
name: "Remove coder:workspaces.access",
|
||||
}),
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -877,7 +877,7 @@ describe("OAuth2AppForm", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
await user.click(screen.getByTestId("clear-all-button"));
|
||||
await user.click(screen.getByRole("button", { name: "Clear all" }));
|
||||
await user.click(
|
||||
screen.getByRole("button", { name: /update application/i }),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user