Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: dropdowns open a themed list of their own instead of the browser's

SelectField and the refresh-interval picker are built on a new Listbox, a
select-only combobox: a button that keeps focus and a listbox in the top
layer, so it works the same in every current browser, is not clipped by a
scrolling ancestor and shows above a modal dialog. Keys, type-ahead and
placement are pure functions with tests. required becomes aria-required, as a
button has no native form validation.
This commit is contained in:
iris 2026-10-25 17:15:04 +01:00
commit a2e8a2bda0
2 changed files with 653 additions and 66 deletions

View file

@ -13,7 +13,6 @@
border-radius: 0.4em;
color: var(--muted);
font-size: 0.9em;
cursor: pointer;
}
.ui-refresh-picker:hover,
.ui-refresh-picker:focus-within {
@ -21,22 +20,21 @@
background: var(--bg);
color: var(--fg);
}
/* The select drives the interaction (native listbox, keyboard, a11y) but
contributes no chrome of its own — its own box is invisible, sized to
just its selected option's text, and its default arrow is stripped
since the chevron span stands in for it. */
.ui-refresh-picker-select {
appearance: none;
/* The Listbox contributes only its value and chevron: its own box is
invisible and as wide as the value, so the picker's border is the one
that shows. */
.ui-refresh-picker .ui-listbox {
width: auto;
}
.ui-refresh-picker-select.ui-form-control {
width: auto;
min-height: 2.5em;
padding: 0;
border: none;
background: none;
color: inherit;
font: inherit;
padding: 0;
margin: 0;
cursor: pointer;
}
.ui-refresh-picker-icon,
.ui-refresh-picker-chevron {
.ui-refresh-picker-icon {
font-size: 0.85em;
line-height: 1;
}

View file

@ -14,18 +14,17 @@
// passive-until-touched setting that lives in a panel's title row
// (`Panel`'s `actions` slot), not a form. Visually quiet (no border/
// fill until hovered/focused) the same way `LinksMenu`'s header button
// is, so it reads as chrome rather than another input to fill in. A
// native `<select>` still drives it (no custom dropdown/listbox to
// reinvent) — `appearance: none` strips its default arrow so the
// chevron span can stand in for it, and the visible "value" text is
// just whichever `<option>` the browser is already rendering as
// selected, not a second copy of the label kept in sync by hand.
// is, so it reads as chrome rather than another input to fill in. The
// dropdown is the shared `Listbox` (its list is themed, not the browser's),
// restyled to have no chrome of its own: the chevron is the Listbox's, and the
// visible value is its selected option.
//
// The hook, not the picker, owns re-fetch safety: a caller passes its
// own fetch callback, and it's the CALLER's job to make sure that
// callback doesn't clobber an input the operator is mid-edit on — this
// hook only decides *when* to call it.
import { useEffect, useRef } from "preact/hooks";
import { Listbox } from "../select-field/Listbox.js";
import "./RefreshInterval.css";
// `null` means "off" throughout this module — no separate boolean, so
@ -51,37 +50,23 @@ export function RefreshIntervalPicker({
}) {
const current = PRESETS.find((p) => p.value === value) ?? PRESETS[0];
return (
// A `<label>` wrapper (not a bare `<span>`) so the icon/chevron
// padding is part of the click/tap target too, not just the native
// select box itself — same touch-target-floor reasoning as the rest
// of the kit, just without a visible label string to hang it off
// of (hence the `aria-label` on the `<select>` for the accessible
// name a sighted-only icon+chevron can't supply).
<label class="ui-refresh-picker" for={id}>
<div class="ui-refresh-picker">
<span class="ui-refresh-picker-icon" aria-hidden="true">
🕐
</span>
<select
<Listbox
id={id}
class="ui-refresh-picker-select"
aria-label="refresh interval"
ariaLabel="refresh interval"
value={current.label}
onChange={(e) => {
const label = (e.target as HTMLSelectElement).value;
options={PRESETS.map((p) => ({ value: p.label, label: p.label }))}
minListWidth={96}
onChange={(label) => {
const preset = PRESETS.find((p) => p.label === label);
if (preset) onChange(preset.value);
}}
>
{PRESETS.map((p) => (
<option key={p.label} value={p.label}>
{p.label}
</option>
))}
</select>
<span class="ui-refresh-picker-chevron" aria-hidden="true">
⌄
</span>
</label>
/>
</div>
);
}