swarm-ui: an agent card is no longer a button around buttons
The card row had role=button and tabindex=0 and held the terminal button, the wanted menu and the login button, which axe reports as nested interactive controls and which a screen reader can't walk. The row is no control now; the agent's name is a real button, so Tab, Enter and Space open the agent, and a press anywhere on the card still does. Picking stays one checkbox per card.
This commit is contained in:
parent
7e6972a191
commit
c77904362d
4 changed files with 60 additions and 19 deletions
|
|
@ -140,7 +140,7 @@ paused, destroy), a **paused by hive** badge when the agent's own harness paused
|
||||||
its turn loop (hover for the reason; set the agent **up** to resume it), and a
|
its turn loop (hover for the reason; set the agent **up** to resume it), and a
|
||||||
**login needed** badge with a **log in** button when its claude has no session.
|
**login needed** badge with a **log in** button when its claude has no session.
|
||||||
|
|
||||||
Select a card to open the agent's details. The address becomes `/agents/<name>`,
|
Select a card to open the agent's details; from the keyboard, **Tab** to the agent's name and press **Enter** or **Space**. The address becomes `/agents/<name>`,
|
||||||
so a link or a reload lands on the same agent, and the browser's back and
|
so a link or a reload lands on the same agent, and the browser's back and
|
||||||
forward buttons walk through the selections. Until you select an agent the list
|
forward buttons walk through the selections. Until you select an agent the list
|
||||||
takes the whole width, in the shell's 90em column. Selecting one narrows the
|
takes the whole width, in the shell's 90em column. Selecting one narrows the
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,22 @@
|
||||||
.ui-agent-card-name {
|
.ui-agent-card-name {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
/* The name is the keyboard's way into the card: a button with no box. The ring
|
||||||
|
is the card's (below), not its own. A click on it reaches the row's handler. */
|
||||||
|
.ui-agent-card-name-button {
|
||||||
|
appearance: none;
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
background: none;
|
||||||
|
color: inherit;
|
||||||
|
font: inherit;
|
||||||
|
font-weight: 600;
|
||||||
|
text-align: left;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.ui-agent-card-name-button:focus-visible {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
/* Pushes the wanted-state control to the row's trailing edge regardless
|
/* Pushes the wanted-state control to the row's trailing edge regardless
|
||||||
of how wide the status badge next to it ends up. */
|
of how wide the status badge next to it ends up. */
|
||||||
.ui-agent-card-wanted {
|
.ui-agent-card-wanted {
|
||||||
|
|
@ -49,15 +65,17 @@
|
||||||
|
|
||||||
/* The header is what opens the agent's details: it reads as a control without
|
/* The header is what opens the agent's details: it reads as a control without
|
||||||
a box. */
|
a box. */
|
||||||
.ui-agent-card-row[role="button"] {
|
.ui-agent-card-row[data-opens] {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
/* The card's own row takes the clicks, so the card shows the hover and the
|
/* The card's own row takes the clicks, so the card shows the hover and the
|
||||||
keyboard focus the way a `Card` with a click handler does. */
|
keyboard focus the way a `Card` with a click handler does. */
|
||||||
.ui-card:has(> .ui-agent-card-row[role="button"]:hover) {
|
.ui-card:has(> .ui-agent-card-row[data-opens]:hover) {
|
||||||
border-color: var(--purple);
|
border-color: var(--purple);
|
||||||
}
|
}
|
||||||
.ui-card:has(> .ui-agent-card-row[role="button"]:focus-visible) {
|
.ui-card:has(
|
||||||
|
> .ui-agent-card-row[data-opens] .ui-agent-card-name-button:focus-visible
|
||||||
|
) {
|
||||||
border-color: var(--purple);
|
border-color: var(--purple);
|
||||||
outline: 2px solid var(--purple);
|
outline: 2px solid var(--purple);
|
||||||
outline-offset: 2px;
|
outline-offset: 2px;
|
||||||
|
|
|
||||||
|
|
@ -74,22 +74,29 @@ export function AgentCard({
|
||||||
return (
|
return (
|
||||||
<Card selected={selecting ? select.picked : selected}>
|
<Card selected={selecting ? select.picked : selected}>
|
||||||
<AgentCardLayout
|
<AgentCardLayout
|
||||||
|
// Picking, the row is one checkbox. Otherwise it is no control: a
|
||||||
|
// mouse press anywhere on it opens the agent, but the keyboard reaches
|
||||||
|
// that through the name, a real button. A button role on the row would
|
||||||
|
// put the card's own buttons inside a button.
|
||||||
rowProps={{
|
rowProps={{
|
||||||
role: selecting ? "checkbox" : "button",
|
...(selecting
|
||||||
tabIndex: 0,
|
? {
|
||||||
|
role: "checkbox",
|
||||||
|
tabIndex: 0,
|
||||||
|
"aria-checked": select.picked,
|
||||||
|
onKeyDown: (e: KeyboardEvent) => {
|
||||||
|
if (e.target !== e.currentTarget) return;
|
||||||
|
if (e.key === "Enter" || e.key === " ") {
|
||||||
|
e.preventDefault();
|
||||||
|
choose();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: { "data-opens": "" }),
|
||||||
"data-agent": row.name,
|
"data-agent": row.name,
|
||||||
"aria-checked": selecting ? select.picked : undefined,
|
|
||||||
"aria-current": !selecting && selected ? "true" : undefined,
|
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
if (!press.shouldIgnoreClick()) choose();
|
if (!press.shouldIgnoreClick()) choose();
|
||||||
},
|
},
|
||||||
onKeyDown: (e) => {
|
|
||||||
if (e.target !== e.currentTarget) return;
|
|
||||||
if (e.key === "Enter" || e.key === " ") {
|
|
||||||
e.preventDefault();
|
|
||||||
choose();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
...press.handlers,
|
...press.handlers,
|
||||||
}}
|
}}
|
||||||
icon={
|
icon={
|
||||||
|
|
@ -114,7 +121,19 @@ export function AgentCard({
|
||||||
) : null}
|
) : null}
|
||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
name={<span class="ui-agent-card-name">{row.name}</span>}
|
name={
|
||||||
|
selecting ? (
|
||||||
|
<span class="ui-agent-card-name">{row.name}</span>
|
||||||
|
) : (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="ui-agent-card-name ui-agent-card-name-button"
|
||||||
|
aria-current={selected ? "true" : undefined}
|
||||||
|
>
|
||||||
|
{row.name}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
status={
|
status={
|
||||||
<>
|
<>
|
||||||
{row.freshness !== "fresh" ? (
|
{row.freshness !== "fresh" ? (
|
||||||
|
|
|
||||||
|
|
@ -125,9 +125,13 @@ export function AgentsPage() {
|
||||||
if (was === null || selected !== null) return;
|
if (was === null || selected !== null) return;
|
||||||
const inPane = document.activeElement?.closest("[inert]") != null;
|
const inPane = document.activeElement?.closest("[inert]") != null;
|
||||||
if (inPane || document.activeElement === document.body) {
|
if (inPane || document.activeElement === document.body) {
|
||||||
document
|
// The name is the card's tab stop; while picking, the row is.
|
||||||
.querySelector<HTMLElement>(`[data-agent="${CSS.escape(was)}"]`)
|
const row = document.querySelector<HTMLElement>(
|
||||||
?.focus({ preventScroll: true });
|
`[data-agent="${CSS.escape(was)}"]`,
|
||||||
|
);
|
||||||
|
(
|
||||||
|
row?.querySelector<HTMLElement>(".ui-agent-card-name-button") ?? row
|
||||||
|
)?.focus({ preventScroll: true });
|
||||||
}
|
}
|
||||||
}, [selected]);
|
}, [selected]);
|
||||||
// The PUT response is the hive's whole declaration set (every agent's
|
// The PUT response is the hive's whole declaration set (every agent's
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue