Skip to content
Toolkit

ADR-0041: The picker that showed every colour but one — ColorPicker, and the palette a design system may not own

Context

Every authoring row since ADR-0035 has been censused before it was designed, on the rule that a remaining row is "a claim to re-check, not a fact." Three turned out to be deletions, one was a kind rather than a name, one was what it said it was, one had half its stylesheet already shipped in Studio, and one had never worked.

ColorPicker is the eighth and the last, and it is two findings at once: it had never worked either — the same three defects, one component later — and it is the first row Studio may not fully own.

The census

ProbeResult
files named ColorPicker1 — apps/web/src/components/ui/ColorPicker.tsx, 151 lines
<ColorPicker in the working tree22 — AdminThemesPage.tsx ×12, BiolinkSettingsPanel.tsx ×7, PwasPage.tsx ×2, BlockSettingsForm.tsx ×1
are all reachable?yes — two Drawer forms, the biolink editor's settings rail, and the block inspector
a test naming itnone, direct or indirect
a storyone, indirectly — BlockSettingsForm.stories.tsx's HeadingBlock reaches it through a kind: 'color' field spec

Twenty-two call sites, four files. The row survives — and it is the largest blast radius of any row in the phase 01 queue.

Of seven declared props, three were ever passed

ADR-0026 counts what is reachable. value, onChange at all 22 sites and label at 21. error, presets, className and disabled have zero call sites — so the is-invalid branch, the danger-text error <span> and the className pass-through were unreachable code, and presets being unreachable means all 22 pickers showed the same fifteen hard-coded colours.

The one site with no label is BlockSettingsForm.tsx:122, the block inspector, which draws its own <label> beside the control — a <label> with no htmlFor over a control with no id, so that picker's only accessible name was the hex value it was showing.

The three defects, and none of them is new

ADR-0040 found a two-column calendar, a selected-state class that matched no rule, and an absolutely positioned panel with nothing positioned above it. This component has the same three, in the same proportions. It is not a coincidence: the two files are the same template with different contents.

1. The colour chip was a zero-by-zero box

<span
  className="shrink-0"
  style={{ backgroundColor: isValidHex(hex) ? hex : '#CCCCCC' }}
/>

.shrink-0 is patterns.css:92, and it is one declaration: flex-shrink: 0. Nothing else in the app's ~4,600 lines of CSS matches that span — not .control span, not .row > span, not a bare span rule; the whole sheet was searched. It is an empty inline-level element inside a display: flex row with no width, no height and no content, so it is a 0×0 box and its background paints nothing.

A colour picker showed a hex string and never a colour, at all 22 call sites. The state was carried by text alone.

2. The panel had never been visible

.popover-panel (components.css:877) is:

.popover-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: var(--z-menu);
}

Its parent in the markup is a bare <div> with no class, so it declares no position. The containing block is therefore whatever is positioned above it, and top: calc(100% + 6px) resolves against that box's height — not the trigger's. At every call site the result is the same kind of nowhere:

Call sitesContaining blockClipped byWhere the panel lands
14 (AdminThemesPage, PwasPage).lk-drawer__panel — position: relative, full viewport height.lk-drawer__body, overflow-y: auto6px below the bottom of the drawer, outside the body's clip
7 (BiolinkSettingsPanel).card.ed-panel — a filled panel-rise animation ends at translateY(0), and a non-none transform is a containing block.settings-scroll (overflow-y: auto) and .card (overflow: hidden)below the bottom of a 280px rail that hides its overflow
1 (BlockSettingsForm).card.ed-panel.is-inspector, same.insp-scroll and .ed-panelthe same, in a 320px rail

left: 0 compounds it: every picker in a drawer would have opened at the drawer's left edge regardless of which one was clicked, if any of them had opened anywhere visible.

There is no configuration of this component in this application in which its panel could be seen. It is the ADR-0040 defect again, and this time without even the mitigation that two of the five sites merely clipped it.

3. The palette was two columns wide

Fifteen swatches, laid out with .form-grid — repeat(2, minmax(0, 1fr)) (patterns.css:97), collapsing to one column below 640px (patterns.css:130). Inside a 224px .panel-w-sm, fifteen 32px swatches drew as an eight-row two-wide strip 368px tall, or on a phone a fifteen-row strip 704px tall — in a panel with no max-height and no scroll.

The same rule, misused the same way, one component apart.

And the rest of the file

  • No keyboard model. No role, no aria-expanded, no aria-haspopup, no Escape, no arrow keys. Fifteen swatch buttons were fifteen tab stops, each named by title={color} — six hex digits read out one character at a time.
  • The label was a <span className="small medium muted"> over a <button> with no id, so 21 of the 22 pickers were announced by their own value and the 22nd by nothing.
  • error set is-invalid and no aria-invalid, and the error <span> had no id for anything to point at — moot, since no call site could reach it.
  • A draft could outlive its edit. handleHexInput set local state unconditionally and called onChange only on a valid parse, with no revert. A field left holding #GG stayed that way, showing one colour and meaning another, with no way back but retyping.
  • className={['control', '', 'row', '', …].join(' ')} — the empty slots are the residue of deleted class names, and they emit doubled spaces. Select.tsx in the same folder uses .filter(Boolean).
  • nativeRef was assigned and never read.

Decision

Studio gains ColorPicker; Studio does not gain a palette

This is the part that is new, and it is a rule rather than a detail.

Studio's lint rule E1 forbids raw colour literals — hex, rgb(), hsl() — anywhere outside the token layer. It is not a style preference: it is what keeps tokens/studio.tokens.json the one place colour is decided, and it is the rule AGENTS.md's second non-negotiable is about. A swatch palette is fifteen raw colours. A design system that obeys its own rule cannot ship one.

The check fired, correctly, on the first draft: a PRESETS array in overlays.jsx is fifteen E1 errors, and a single '#000000' fallback for the unset colour well is one more. Neither has a semantic token to consume, because neither is chrome. They are the colours a biolink's background may be, which is Cardsite's data.

So the split is:

  • Studio owns the control — the trigger, the anchored dialog, the hex field, the platform colour surface, the keyboard model, the layer. presets is a prop with no default, and a picker given none is the platform surface plus a hex field, which is a complete control.
  • Cardsite owns the palette, in apps/web/src/lib/colorPresets.ts. This is ADR-0037's reasoning one domain over: the IANA zone list stayed app-side when TimezonePicker became Combobox, because a design system should not carry platform data. A brand palette is the same shape of thing.

The unset colour well gets no literal either. React is handed '', and HTML's own value sanitisation supplies whatever an unset well shows — which is the right authority for a colour Studio has no opinion about.

Two things the census turned up in that palette are recorded in the new module rather than fixed, being palette decisions and not this conversion's:

  • Six of the fifteen are Tailwind's 500 steps, in an application that ships no Tailwind and whose own palette is authored in OKLCH. They agree with nothing else on the page. (ADR-0034 already records four *:col-span-* Tailwind class names in this app for the same reason.)
  • The lime that was the default colour of every unset picker is a stale hand-copy of Studio's, three revisions behind the token — the exact failure mode AGENTS.md names: "that is how the app ended up running on a stale hand-copy of the token file." Nothing defaults to a colour now; an unset picker draws a diagonal rule, because "no colour" drawn as a colour is indistinguishable from that colour.

The control raises five things

Per ADR-0019, an authored component raises the contract it replaces.

  1. The chip is a box — 20px, --r-sm, and a hairline so #ffffff on a light surface is still a swatch and not a hole.
  2. The panel is portalled and measured, through useAnchoredPosition and createPortal, joining the shared anchored-overlay block with .lk-menu--anchored, .lk-popover and .lk-datetime__panel. It cannot be clipped and it cannot anchor to the wrong box.
  3. The palette is a listbox — five fixed columns, one tab stop, ←/→ a swatch, ↑/↓ a row, Home/End the ends, Enter/Space chooses. Each swatch is named in words.
  4. The value is one normalised form. '#abc', 'abcdef' and '#ABCDEF' are all accepted; what onChange emits is always lower-case #rrggbb, which is the only form <input type="color"> will hold, so a value that has been through the control round-trips through the platform surface unchanged. The three surfaces used to emit three forms and what the API stored depended on which one you used.
  5. A draft is a draft. #ab does not emit, is marked aria-invalid, and is replaced by the committed colour when the cursor leaves.

Selection does not follow focus, and that is a product constraint

APG's radio-group pattern checks on arrow. This is a listbox instead, with manual selection, for a reason the pattern cannot see: every one of the 22 call sites writes through to a server on change — commitSetting, set() — so a keyboard user arrowing across a palette under the radio rule would issue one write per press. The listbox model keeps focus and aria-selected on the same object, which is what mattered, without that.

That co-location is deliberate and is the answer to an open item ADR-0040 left: there, the roving tab stop is on a <button> inside a <td role="gridcell"> that carries aria-selected, so a reader hears the chosen day named exactly like every other. Here they are one element.

Tab cycles inside the panel

SelectBox's documented house rule is that Tab closes, and DateTimePicker inherited it. That is right for a listbox, where the panel holds one collection and leaving it means leaving the control. It is wrong for a panel holding three surfaces: with Tab closing, two of them are reachable by pointer only. This panel is a role="dialog", and a dialog's Tab stays inside it; Escape is what leaves.

DateTimePicker has the same three-surface shape and the listbox rule, so its time field and Clear button are keyboard-unreachable today. That is recorded as its own row rather than swept in here.

Consequences

What the app lost

apps/web/src/components/ui/ColorPicker.tsx is archived, with a register row. The barrel loses the name, as MultiSelect's and CodeEditor's did.

App CSS deleted on the same commit (ADR-0021), each verified at zero remaining emitters by the ADR-0037 counter:

RuleEmitters beforeNote
.popover-panel1the defect itself
.panel-w-sm1
.control.is-focused1a focus ring painted from a boolean rather than from focus — and the panel it signalled had never been visible
.swatch, .swatch:hover, .swatch.is-selected1.p-swatch in editor.css is a separate inspector family and is untouched
.color-swatch-input2the second was the preview page's ColorPicker card

That last one is ADR-0036's .checkbox trap for the third time, and it was cleared the way ADR-0039 cleared the .code-editor-* family: the preview card was retired on the same commit. .panel-w-md stays — it had zero emitters before this item too, so it is pre-existing dead and belongs to the .framed-head sweep.

Surviving counts, and one correction: .field was 2, not 3. SESSION.md's "3 → 2" came from a \bfield\b grep that also matched .field-label, plus prose in a comment. It is 2 → 1 (Select alone). This is SESSION.md open item 129 for the fourth time, and the counter used here fixes ADR-0038's comment bug by stripping comments before scanning — which is worth ten hex literals on the other ratchet, below.

The ratchets

Hex colours 88 → 83 (−5), derived per file over both trees: ui/ColorPicker.tsx 19 → 0, blocks/BlockSettingsForm.tsx 1 → 0, lib/colorPresets.ts 0 → 15. The fifteen moved; the −5 is the four literals the component's own machinery no longer needs, plus one fallback.

i18n 1971 → 1991 (+20), and every one of the +20 is the same string written twice. Field names the trigger through <label for>; ColorPicker names the role="dialog" panel, which is announced as nothing without a name; and Field cannot expose the id of the <label> it renders, so the string has to be passed again. Twenty-one call sites × 2, less the retired title="Pick color".

That is SESSION.md open item 141, and this is the second component to pay it. ADR-0040 paid +5 at five call sites. The running cost is 25 duplicated strings, and every further picker adds its own call-site count. The fix named in the item — a labelId on Field's function-child props — is a change to every Field consumer in the application and is not this conversion's to make, but it is now the most expensive open row in the ledger and should be the next one taken.

Verification

npm run verify green. 98 assertions in apps/web/src/components/ColorPicker.test.tsx, including the ADR-0023 completeness check in its mechanical form — the class list is read out of the component's source rather than typed into the test, so a class added to the markup and not to the layer fails it.

89 mutations, 84 killed. Every mutation scoped to the component's own region of overlays.jsx and its own block of the stylesheet, because a bare String.replace takes the first occurrence and this file holds a second move, a second close and a second onPanelKeyDown — the trap SESSION.md records twice already, and which this harness hit on its first run.

The pass found seven real defects that the green suite had not:

  • The cursor did not start on the chosen swatch. Placing it in an effect keyed on open raced the focus effect in the same commit: the focus effect read the cursor from before the placement, so focus landed on swatch 0 and the highlight then moved out from under it. Moved into the open handler.
  • Two vacuous assertions. The {Home} case and the clamp case both used a fixture whose chosen swatch was index 0, so Home had nowhere to go and a mutant that wrapped instead of clamping came back to 0 by another route. Both rewritten against a fixture that opens on index 4, and the clamp split into two one-press cases.
  • Two CSS assertions were answering out of the wrong rule. rulesFor uses indexOf, and the shared anchored block's selector list ends \n.lk-color__panel { — so asking it for the component's own panel rule found the shared one instead, and mutations that emptied the component's rule survived on it. Both now anchor on a head whose preceding character is not a comma. DateTimePicker.test.tsx had the same latent hole the moment a fourth panel joined that list, and is fixed with it.
  • A dead htmlFor. The colour well's <label> wraps its input, so the association is implicit; a mutation that deleted the attribute survived, and the attribute and its useId went.
  • The roving stop was clamped where it was set, not where it was used. presets is a prop, so a consumer can shorten it while the panel is open — and an index left past the end matches no swatch, so tabIndex={i === cursor} is -1 on every one of them and the whole palette silently leaves the tab order while remaining visible and clickable. It also strands focus on <body> inside an open dialog, because the element focus was on has left the DOM. Both fixed: the index is clamped at use, and a focus that has fallen to <body> under an open panel is recovered to the roving stop — only from <body>, since anything else is someone's deliberate position. Unreachable at all 22 call sites here, which pass a module constant; reachable by the next consumer, which is what makes it a Studio defect rather than an app one.
  • Closing by clicking the trigger skipped the refocus. Only Chrome focuses a <button> on a mouse click, so on Safari and Firefox focus could still be inside the panel about to unmount and would fall to <body>. userEvent.click focuses first, which is why the suite could not see it; the regression test fires a raw click instead.
  • The hex field committed a three-digit form on sight. Accepting '#abc' is right, but a three-digit hex is also a prefix of a six-digit one, so typing #66d632 emitted #6666dd at the third character and corrected it at the sixth — a wasted server write at every call site, all of which save on change, and a wrong colour on the preview in between. The keystroke path now commits six digits only; the short form commits on blur, which is when it stops being a prefix. Found on a re-read, not by the harness, and pinned by three new tests.

Five survivors stand, and none is a test gap worth filling:

  1. The chip's style guard. style={{ background: null }} and no style are the same DOM — React drops a null property. Equivalent.
  2. shown = open && !disabled. A disabled <button> fires neither click nor keydown, so nothing a user or a harness can do reaches the term. It guards the single frame between disabled going up and the effect that closes the panel — the same category as ADR-0038's !loading survivor.
  3. The panel's own padding. Nothing asserts it, deliberately: pinning every declaration is how a suite fills with assertions that cannot fail for the right reason.
  4. Two partial unclampings of the roving stop — mutating only the tabIndex comparison, or only the arrow keys' base. Each leaves the other clamp in place, and the component then self-heals through data-cursor and the swatch's onFocus, which writes a valid index back to cursor on the next render. Removing the clamp outright is killed, which is the behaviour that matters; these two are equivalent mutants produced by a second, redundant path being genuinely redundant.

One harness bug is worth recording, because it produced a false survivor: the mutation that removes .lk-color__panel from the shared anchored block edits a region above the component's own block, and the harness mutated the built stylesheet only from the component block down — so the file the test reads was never changed. Run against the whole file it is killed. That is the third time this workstream's mutation tooling has reported a result the tooling itself caused, after the first-occurrence bug (ADR-0038) and the false-survivor pair (ADR-0040).

The parity gate

check:studio-parity moves 116 React / 5 app-side / 5 awaiting authoring → 117 / 4 / 4, and the four that remain are all not-planned. The phase 01 authoring queue is empty: Select and Switch are dispositioned to SelectBox/NativeSelect and Toggle, DisplayRulesEditor is product domain, and TimezonePicker was resolved app-side by ADR-0037. Twelve rows entered the queue; three were deletions, four were dispositions, and five were authored.

Source: docs/decisions/0041-the-picker-that-showed-every-colour-but-one.md

Library