Skip to content
Toolkit

ADR-0043: The prop that could not be a prop — Field's labelId, and the object that is spread

Context

This is the first item in the workstream that is not a conversion. It is a debt row — open item 141 — opened by ADR-0040 and doubled by ADR-0041, and it was promoted to the top of Next because it had become the most expensive open row in the ledger and because both bills were already paid.

Field is Studio's only way to label a control. It renders the <label>, generates the id, and hands its function-child an object to spread onto the control:

children({ id, 'aria-describedby': …, 'aria-invalid': … })

That contract is complete for a control that needs one accessible name. It is one short for a control that needs two.

An anchored picker is two objects: a trigger, and a portalled role="dialog" panel. The <label for> names the trigger. Nothing names the panel — and a dialog with no accessible name is announced as nothing, which is Popover's rule and its reason. So ADR-0040 and ADR-0041 both made the panel take the string:

<Field label="Background color">
  {(a) => <ColorPicker {...a} label="Background color" … />}
</Field>

Written twice. Once rendered, once announced. Both ADRs recorded the same row and both declined to fix it, because the fix lands on every Field consumer in the application and neither conversion was going to widen that far.

The census

ProbeResult
<Field in the working tree369 — of which 7 are docstring lines
real JSX call sites362
passing a function child361
passing an element child1 — Textarea.test.tsx:166, the @ts-expect-error negative test
call sites writing their label twice26 — ColorPicker ×21, DateTimePicker ×5
ColorPicker call sites not inside a Field1 — BlockSettingsForm.tsx, an inspector row with a hand-rolled <label>
CSS classes or states this change adds0
emitters of .lk-field in apps/web/src/styles/*.css0 — the app has never styled it

Twenty-six duplicated strings — where the ledger row said twenty-five. The row was not wrong, it was reading the wrong number: ADR-0041's ratchet delta was +20, correct as arithmetic, because twenty-one duplicates arrived and one unrelated title retired with the old file in the same commit. The row then carried that net figure forward as a count of duplicated strings, and a net delta is not a census. The repo settled it: 21 + 5 = 26, and the ratchet moved by exactly that.

The finding: the ledger asked for a prop, and a prop is the one thing it could not be

The open-item row named the fix precisely — "a labelId on Field's function-child props" — and that is the natural reading: add a fourth key beside id.

It does not work, and the reason is the object's whole purpose. That object is spread onto a DOM element at every one of the 361 function-child call sites (<Input {...a} />, <Textarea {...a} />, and the Studio components that pass their own ...rest down to one). id, aria-describedby and aria-invalid are all DOM attributes. labelId is not.

Probed rather than assumed, on the real runner:

CALLS: ["Warning: React does not recognize the `%s` prop on a DOM element.
        If you intentionally want it to appear in the DOM as a custom
        attribute, spell it as lowercase `%s` instead. …"]
ATTRS: id,labelid

A warning once per render, and a stray labelid="" in the markup — at 361 call sites, to serve 26. The declared type would have compiled; every test would have passed; the console would have filled up.

The object is spread, so the object is an attribute list. Anything that is not an attribute cannot live in it, however much it belongs to the same component. FieldControlProps' docstring already said so — "Spread it, whole" — and that sentence is a constraint, not a convenience.

So labelId travels beside it, as a second argument:

<Field label="Background color">
  {(a, f) => <ColorPicker {...a} labelledBy={f.labelId} … />}
</Field>

361 call sites ignore the second argument and did not move. The one that needs it takes it explicitly, which is also the only place it is legible.

The second finding: the guarantee that could not survive the fix

label was required on both pickers. That was deliberate and it was load-bearing: it made "this dialog has an accessible name" a compile-time guarantee rather than a review habit.

labelledBy has to make it optional — a call site cannot be made to pass both. The obvious repair is a union demanding exactly one:

type Named = { label: string; labelledBy?: never }
            | { label?: never; labelledBy: string }

It rejects the very call it exists for. f.labelId is string | undefined, honestly: a Field need not have a label, and when it does not there is no element to point at — an aria-labelledby naming a missing id names nothing while reading as wired, which is the exact trap Field's element-child branch is kept as a warning about (ADR-0032's family, and the same shape DropdownMenu comments on at its anchor id). So labelledBy={f.labelId} cannot satisfy labelledBy: string, and the union fails the good call while permitting the bad one through the other branch.

The alternatives were each worse:

  • Type labelId as string. A lie. The label-less field hands out undefined and the type would say otherwise, which is how an aria-labelledby pointing at nothing ships.
  • Always render the <label>. Turns an optional prop into a required one across 362 call sites, to buy a type.
  • Make Field generic over whether label is present. Inference from an absent optional prop does not yield undefined; the narrowing would be decorative.
  • Object.defineProperty(…, { enumerable: false }) so the key exists but does not spread. It works, and nothing at the call site explains why. A reader cannot see the rule from the code, which is the property the two-argument form has and this does not.

The guarantee therefore moved from the type to a test, and that is a real loss, recorded as a ledger row rather than hidden. What replaces it is narrower than what it replaces: the tests pin that labelledBy names the dialog and that aria-label is dropped beside it, but nothing now rejects a picker given neither. Both pickers' docstrings and both prop docs say so in the place a caller reads.

This is the ADR-0038 shape one level up: TypeScript could not enforce it, so say which mechanism does. There the escape was a hyphenated JSX attribute an Omit cannot reach and the answer was a rest-first spread plus a test. Here it is an honestly-optional id and the answer is a test and a docstring. In both, the ADR's job is to stop the next reader assuming the type is the guarantee.

Decision

  1. Field gives its <label> an id, derived ${id}-label from the id already in hand — the ${id}-help idiom, and DropdownMenu's.

  2. It hands that id to the function-child as a second argument, { labelId }, and only when there is a label to point at. The first object is unchanged and stays spread-safe. The two-argument form is the mechanism; the reason is written in the docstring, next to it.

  3. DateTimePicker and ColorPicker take labelledBy — the name Modal, Drawer and SelectBox already use — and drop aria-label when they have it. Two names on one element is one name too many: aria-labelledby wins the computation, so a stale aria-label beside it is a string nothing announces and nothing catches.

  4. label becomes optional on both, for a picker outside a Field, and the "always named" guarantee becomes a test — a ledger row, not a silent trade.

  5. The 22nd ColorPicker call site spells the wiring out. BlockSettingsForm's inspector row is .prow, not a Field — the density that rail is laid out in, and ADR-0041 declined to re-lay-out it. Its hand-rolled <label> gains an id beside its htmlFor and passes it as labelledBy. No Field, same wiring, written where a reader can see it.

  6. No CSS. The change adds no class and no state, and the app styles none of Field's. This is the first item in the workstream where the emitter count is zero for a reason rather than by luck, and it is worth saying: ADR-0021's rule is delete the app CSS you replace, not touch CSS.

Consequences

i18n 1991 → 1965, the whole −26. Nothing became translatable and nothing left the UI: 26 second spellings of 26 strings that are each still rendered exactly once. The ratchet fails on a decrease as well as an increase, so this is arithmetic the commit had to carry.

Fifteen new assertions, ten mutations, ten killed. Eight against the source and two against the @ts-expect-error probes — tsc -b runs in verify and rejects a directive that has stopped being an error, so a type probe is mutation-testable in the same sense a runtime assertion is.

The mutation that matters is the one that folds labelId back into the spread object. It is killed by an assertion on that object's exact key list, not by a rendered-output check — because the rendered output of that mistake is a console warning and a stray attribute, and a test that looked only at the DOM would have to know to look for labelid. The key list is the assertion that survives someone tidying two arguments back into one, which is exactly the change a future reader will be tempted to make.

A probe that asserted nothing shipped to main and ran in every suite. ZZProbe.test.tsx, left behind by ADR-0041's conversion: three tests, two asserting expect(true).toBe(true) and one asserting nothing at all, each printing to the console on every run, in a file named to sort last. It is deleted here. The workstream mutation-tests every new assertion precisely so a vacuous one cannot survive — and this file was never in scope for that discipline, because nothing in it was ever claimed as an assertion. The gate row it opens: a test file that asserts nothing is not caught by a rule about assertions.

Every further picker is now free. The cost of an anchored dialog was its call-site count in duplicated strings, which is what made this row compound. It is zero now, and phase 03's p-* inspector set can add anchored controls without paying it.

What this does not fix. Field's element-child branch still exists (open item 20). BlockSettingsForm's other fourteen hand-rolled label rows still have no wiring at all (the ADR-0041 row). And the dialog-naming guarantee is a test now, not a type (the row this ADR opens).

Source: docs/decisions/0043-the-prop-that-could-not-be-a-prop.md

Library