ADR-0155 — A component's own attributes go over rest when they are the contract
Status: Accepted · Date: 2026-08-31 · Track: 002 close-out (LEDGER drain, row 62) · Supersedes: nothing · Builds on: ADR-0026, ADR-0037
Context
Every Studio component spreads {...rest} onto its own element, and where in
the attribute list it does so decides who wins a collision. Spread last, a
caller's prop replaces the component's; spread first, the component's
replaces the caller's. ADR-0037 fixed this twice inside one component
(Combobox, for handlers and then for the ARIA family), and open item 62 has
carried it as "worth one sweep" since.
The sweep's first finding is that the file already disagrees with itself.
Combobox, MultiSelect, DateTimePicker, ColorPicker, Tabs, TabPanel,
CodeEditor, IconButton and PasswordInput spread first, four of them with a
comment saying why. Button, Chip, SearchField, Toggle and Segmented
spread last. Nothing distinguishes the two groups except which of them had a
defect found in it.
The second finding is worse: two of the types already promise what the runtime
does not keep. ToggleProps has omitted type and role since it was
written, and SegmentedProps has omitted role — but with rest spread last,
a caller who wrote either anyway (through a spread bag, a wrapper component, or
as any) got it, and the switch quietly became a checkbox styled like one. An
omission the runtime does not enforce is a comment with a type's syntax.
Decision
A component's own attributes are spread over rest when they are its
contract, and under it when they are a default.
The contract is what the component exists to guarantee: the element's type,
its role, the accessible name it derives from a prop of its own, and any
attribute that states a fact about the component's own state. Those go after
{...rest}. Everything else — id, style, data-*, title, handlers the
component does not declare — still lands, which is the reason rest is spread
at all.
Applied here to the three components whose contract is ARIA and which have a suite to prove it:
Toggle—type="checkbox",role="switch"and the name fromlabel. These are what make it a switch rather than a checkbox that is drawn like one, and its type has said so all along.Segmented—role="group"and the name fromlabel. Same, one component over.Button—aria-busy, which is a statement aboutloading. Spread last, a caller could announce a busy button that was not disabled, or the reverse.typeanddisabledare already destructured props, sorestnever carried them.
What deliberately keeps spreading last is the other kind: Input, Textarea,
NativeSelect, Choice, ChoiceGroup, Field and SelectBox's root. Each
is a bare element whose only own attribute is a class — Input is documented
as "the bare control", and a caller must be able to set everything on it. There
is no contract to defend there, so inverting the order would buy nothing and
cost the escape hatch.
The types state the inversion wherever they can. ToggleProps and
SegmentedProps gain 'aria-label' beside the omissions they already carried,
and ButtonProps gains 'aria-busy'. Where the attribute is hyphenated that
omission is documentation rather than enforcement — TypeScript does not reject
a hyphenated JSX attribute (LEDGER row 90) — which is precisely why the runtime
has to be the thing that keeps it.
Consequences
Three assertions land, one per component, each in the suite that component
already had, and each asserting both halves: the contract survives a caller
sending the same attribute, and what the component does not declare still
reaches the element. The second half is not decoration — an inverted spread
that also swallowed id would pass the first half alone.
Two of the three are pinned from the type side as well, with
@ts-expect-error on an omitted attribute, which tsc -b fails when it goes
unused. One mechanic is worth recording, because it produced an unused
directive on the first attempt: TypeScript reports a single error for a JSX
element's whole attribute object and names only its first offending property,
so a second directive on the same element has nothing to suppress. One element
per omission is what makes each directive carry its own weight.
Chip and SearchField are the remaining two and are a slice of their own:
Chip's aria-pressed/aria-current and SearchField's type="search" are
the same kind of contract, but neither component has a suite, and neither is
typed at all — Chip is polymorphic on as and wants ADR-0152's
discrimination before it gets a props type. Flipping a spread with nothing to
prove it is how the first version of this defect shipped.
This does not settle what a handler collision means. Tabs already refuses
one outright (its onKeyDown is the tablist keyboard model), while Combobox
composes rather than replacing — it calls the caller's handler and stands down
if the default was prevented. Both are right for their component and neither
generalises yet; a component with a handler that is genuinely its contract
should compose, as Combobox does, rather than silently win.
Source: docs/decisions/0155-a-components-own-attributes-go-over-rest-when-they-are-the-contract.md