Repository navigation
feat(radio): add standalone RadioControl primitive; RadioListItem composes it - #4724
freddymeta wants to merge 4 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsRadioList (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 serious. RadioList - 1 issue(s)
Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
A single radio can't be un-selected by clicking it (native radio behavior), which made the standalone demo feel inert. Drive the Default story's checked state off onClick so it flips on and off interactively; the ControlledGroup story still demonstrates real radio-group deselect semantics.
…ce of truth) Mixing onChange (fires only when the radio becomes checked) with onClick desynced the demo toggle after the first cycle. Drive checked purely from onClick with a no-op onChange so it toggles reliably on every click.
cixzhang
left a comment
There was a problem hiding this comment.
🔴 Blocking — public API-convention violations on new surface in packages/core/src/RadioList/RadioControl.tsx (name/checked/keepFocusableWhenDisabled diverge from siblings in the same directory), an interactive element that can render with no accessible name, and xstyle applied to a zero-opacity node. Also carries new public API from a contributor → needs:code-review.
Triage: new API surface · non-breaking to existing consumers · high blast radius (net-new export from @astryxdesign/core) → deep path
The refactor itself is clean and the RadioListItem invariance claim checks out. Everything below is about the new RadioControl surface.
🔴 1. Prop names contradict conventions this directory already sets
API Conventions → HTML Attribute Collisions is explicit: htmlName?: string; // maps to <input name="...">. RadioListProps.htmlName (RadioList.tsx:127) already does exactly this, for exactly this attribute, one file over.
API Conventions → Booleans: "Always prefix with is or has." Both violations are shipped under eslint-disable:
// RadioControl.tsx:175
// eslint-disable-next-line @astryx/boolean-prop-naming
checked: boolean;
// RadioControl.tsx:219
// eslint-disable-next-line @astryx/boolean-prop-naming
keepFocusableWhenDisabled?: boolean;internal/eslint-plugin-astryx/boolean-prop-naming.js has checked: 'isChecked' hardcoded in NATIVE_BOOLEAN_SUGGESTIONS — the rule is naming the fix. Per the blocking criteria, "a lint-suppressed hardcode is still a blocker … Do not let a documented eslint-disable soften a bright-line violation into advisory." (The only other two disables of this rule in packages/core are on a hook options type in useResizable.ts, not a public *Props interface.)
keepFocusableWhenDisabled is a second problem beyond naming: it exposes an internal mechanism as public API. RadioList and CheckboxInput both express this capability as disabledMessage?: string — one prop that supplies the reason and keeps the control focusable. RadioListItem.tsx:123 derives keepsFocusableForMessage from exactly that. Per "Adding a new prop — converge, don't diverge": reuse the sibling shape.
| Current | Sibling convention | Source |
|---|---|---|
name: string (required) |
htmlName?: string |
RadioListProps:127, CheckboxInputProps |
checked: boolean |
isChecked |
wiki Booleans; eslint rule suggestion |
keepFocusableWhenDisabled?: boolean |
disabledMessage?: string |
RadioListProps:131, CheckboxInputProps |
label?: string → aria-label, never rendered |
label: string (required, always rendered) + isLabelHidden?: boolean |
RadioListProps, RadioListItemProps, CheckboxInputProps |
The label row is the one I'd push hardest on. <RadioListItem label="Email"> renders visible text; <RadioControl label="Email"> renders none. Same word, opposite behavior, same directory. The system's answer for "labelled but not visible" is already label + isLabelHidden — please use it.
🔴 2. A standalone RadioControl can ship with no accessible name
label is optional and the JSDoc/.doc.mjs actively tell you to omit it. Rendered with no label and no external <label htmlFor>:
<input id="_r_c_" class="…" type="radio" value="email" name="notify">No aria-label, no aria-labelledby, and the visible circle is aria-hidden="true". A screen reader announces an unnamed radio. Blocking criteria: "an interactive element without an accessible name." Note both siblings make label required — API Conventions → Required vs Optional lists `label` (interactive elements) as required. Making it required + isLabelHidden resolves this and finding #1 together.
🔴 3. xstyle / className / style land on the invisible input, not the root
// RadioControl.tsx:308-326 — xstyle merged into styles.input
{...mergeProps(
stylex.props(styles.input, wrapperSizeStyles[size], isDisabled && styles.inputDisabled, xstyle),
className, style,
)}styles.input is position: absolute; opacity: 0. Verified by rendering with xstyle={{marginInlineStart: 40, outlineColor: 'red'}}:
ROOT class: RadioControl__styles.radioWrapper x1n2onr6 … (no probe atoms)
INPUT class: RadioControl__styles.input … __scratch_review__overrides.probe x11hdunq xbutuof
CIRCLE class: astryx-radio md … (no probe atoms)
input computed opacity: 0 / position: absolute
So <RadioControl xstyle={styles.spacing} /> silently does nothing visible. RadioListItem puts xstyle on its container (RadioListItem.tsx:158) — the root — which is the convention. Fix: move xstyle/className/style to the wrapper <div> and keep ref on the input.
🔴 4. The standalone control has no hover state — radioScope never reaches it
All four hover rules are gated on an ancestor marker:
// RadioControl.tsx:77, 83, 91, 97
[stylex.when.ancestor(':hover', radioScope)]: { '@media (hover: hover)': … }radioScope is applied in exactly one place in the repo — RadioListItem.tsx:158, stylex.props(styles.container, !isDisabled && radioScope, xstyle). Verified ancestor chains:
in a RadioList: .astryx-radio ← .radioWrapper ← Item.startContent ← .astryx-item
← astryx-radio-list-item … xklqth5 ← the marker
standalone: .astryx-radio ← .radioWrapper (root, no ancestors, no marker)
So the advertised primary use case — "works outside a RadioList" — renders a radio with zero hover feedback, on desktop, permanently. That contradicts the PR's "self-contained control" framing and Design Conventions → State representation ("every relevant state … is designed"). radio.markers.stylex.ts's own docstring still says "Scoped marker for RadioListItem ancestor selectors" — the ownership boundary moved but the marker didn't. Fix: apply radioScope on RadioControl's own wrapper (and let RadioListItem keep applying it on the row so row-hover still drives the circle).
🔴 5. New API surface from a contributor — not approvable by review alone
Per .github/instructions/packages.instructions.md: "If a PR adds a new prop or otherwise changes API surface … the AI reviewer must not approve or merge it — even if it's clean, additive, and passing CI."
- No linked spec issue. New public component surface must link an issue that ran the Component Specification Protocol. Please add one before the API is judged on its merits.
- Whether the right primitive is
RadioControlat all, vs. relaxingRadioListItem's "must be used within a RadioList" throw, is a maintainer call. Route naming disputes to API Arbitration. - New surface should be vibe-tested.
🟡 6. keepFocusableWhenDisabled produces a focusable control with no focus ring
styles.radioWrapperFocus is gated on !isDisabled (RadioControl.tsx:294), but the focusable-disabled path is isDisabled. Verified class lists:
keepFocusable ROOT: …radioWrapper x1n2onr6 … xxk0z11 ← no focus atoms
enabled ROOT: …radioWrapper x1n2onr6 … xxk0z11 …radioWrapperFocus
x1a2a7pz x1irc7jg x1wfwxd8 xdjuwb3 x16rqkct
So a keyboard user tabs into it and sees nothing (WCAG 2.4.7). This is pre-existing — RadioListItem had the identical !isDisabled && guard on main, and it fires today whenever a RadioList is disabled with a disabledMessage. Filing it advisory rather than blocking because the PR didn't introduce it — but the PR promotes it into documented public API, which is the moment to fix it. Suggest gating on !isDisabled || keepsFocusable.
🟡 7. {...rest} is spread last and can clobber the a11y wiring
{...rest} (RadioControl.tsx:327) comes after type, checked, disabled, aria-disabled, form, required, and aria-label. Verified:
<RadioControl label="Email" … aria-label="OVERRIDDEN" role="button" aria-disabled="true" />
// → aria-label: OVERRIDDEN | role: button | aria-disabled: trueA consumer can silently destroy the radio role and the disabled semantics. API Conventions → Composed Component Prop Forwarding, rule 1: "Never let {...rest} overwrite explicitly-set props." Rule 4 offers {...rest}-first as the alternative. Weight: RadioListItem already spreads rest last onto its container, so this is a repo-wide pattern rather than a new sin — but on an <input> the blast radius is a11y-critical, not cosmetic.
🟡 8. onChange drops the event
onChange: (value: string) => void matches RadioListProps.onChange, so it's family-consistent. But the closest control-level sibling is CheckboxInputProps.onChange?: (checked, e: ChangeEvent<HTMLInputElement>) => void. A control-level primitive that never hands back the event can't support preventDefault, modifier keys, or currentTarget. Worth deciding deliberately for a primitive, not inheriting the group's shape by default.
🟡 9. The Default story teaches a broken pattern (and is the autodocs canonical example)
// RadioControl.stories.tsx:74-84
onChange={() => {}}
onClick={() => setChecked(c => !c)}The story is in a low-risk area (apps/storybook/** never gates), but tags: ['autodocs'] makes this the first example a consumer reads for the new component, and it teaches "stub the required onChange, drive state from onClick." Keyboard selection in a real radio group fires change, not click, so a consumer copying this gets a control that doesn't respond to the keyboard. I'd also read the fact that a working single-radio demo needed an onClick workaround as evidence about the API (see #8), not just about the story. Also: the 7-line narration comment above it is more than "comment why, not what" asks for.
🟡 10. Smaller notes
RadioControl.doc.mjshas nothemingblock, so a standalone consumer can't discoverastryx-radio/astryx-radio-dotfrom the component's own docs.themingTargets.test.tsdoesn't catch this — it only reads<dir>.doc.mjs, i.e.RadioList.doc.mjs. Not a dropped surface, just an undiscoverable one.- The PR body lists
aria-describedby?as part of the API;.doc.mjsdoesn't. It only works via the...restpassthrough. - The verbatim-moved raw dimensions (
20/24/8/10,2px solid,borderRadius: '50%',opacity: 0.5) are pre-existing, not introduced here, so not blocking on them — but they're now sitting in a brand-new file, which is when "semantic tokens only" is cheapest to satisfy.
🟢 Verified clean
What was confirmed rather than assumed
| Claim | Result |
|---|---|
| Themeable surface preserved | ✅ themeProps('radio', {size, checked, disabled}) + themeProps('radio-dot', {size}) moved verbatim; RadioList.doc.mjs theming.targets (L13–17) untouched; no target pinned or dropped |
themingTargets guard |
✅ 277/277 pass (guard scans the whole RadioList/ dir, so the cross-file move is invisible to it) |
RadioListItem API + output identical |
✅ 44 existing tests pass untouched; props forwarded 1:1; the if (isDisabled) return guard is semantically equivalent |
| New tests | ✅ 8/8 pass; 52/52 for the directory |
| Typecheck | ✅ tsc -p packages/core --noEmit clean |
check:changesets / check:sync / sync:exports:check |
✅ all pass |
| Changeset conventions | ✅ [feat] category, @freddymeta line, patch bump, @astryxdesign/core — correct, and correctly not [breaking] |
| No hardcoded colors | ✅ every color is a colorVars token or a color-mix() of tokens; CanvasText under forced-colors is a system color, correct usage |
| No raw CSS / StyleX workarounds | ✅ stylex.when.ancestor, :has(:focus-visible), @media (hover: hover) all used natively |
| Component surface complete | ✅ .tsx + .test.tsx + .doc.mjs + story + index.ts export |
displayName, exported prop types |
✅ RadioControl.displayName, RadioControlProps, RadioControlSize all exported |
ref pattern |
✅ ref?: React.Ref<HTMLInputElement> matches the repo (147 files use it; only 2 still use forwardRef) |
@example fence untagged |
✅ plain ``` |
| Public-repo leak | ✅ none in committed text |
Thanks for this — the extraction itself is careful work, and the invariance claim held up under a real check, which is not the common case. #1–#4 are the bright-line ones with concrete fixes; #5 means that even once they're fixed, a maintainer signs off on whether RadioControl should exist in this shape. Please link a spec issue when you pick it back up.
|
Thanks for the thorough review — the convergence points are right, and the "same word, opposite behavior, same directory" call on Two responses: On #5 (new API surface needs a spec + maintainer judgment): opened #4755 as the spec. It runs the problem statement, prior art (
I lead with B because it makes every shared prop mean the same thing across the checkbox and radio families, which resolves #1–#4 structurally rather than prop-by-prop. But which shape (and name) ships is a maintainer call — that's the point of the issue. Happy to vibe-test A/B/C with naive prompts across the use cases before locking it. On #1–#4, #6–#10 (convergence): these apply to whichever shape wins, and I've captured them all in the issue's "Convergence Requirements" section — Holding the implementation here until the shape is settled in #4755, so I don't converge to A and then have to re-converge to B. Will push the rewrite to this PR once it's decided. |
Address the review on #4724 by aligning the RadioControl primitive with the control-level conventions the RadioList/CheckboxInput siblings already set, and settle its shape as a bare control (RadioControl, not RadioInput) per the spec issue: '*Input' names a labeled form field, and a lone radio has no valid standalone-field use — the missing piece is the composition primitive (the circle), which is what RadioControl is. API convergence: - htmlName? (was name), isChecked (was checked), onChange(value, e) (hands back the event, matching CheckboxInput), disabledMessage? (replaces the internal keepFocusableWhenDisabled boolean — the control reads RadioListContext directly, like CheckboxInput reads CheckboxListContext). - label is now required and applied as aria-label, following the icon-only Button convention (control with no visible text) — a standalone control can no longer ship unnamed. No eslint-disable for @astryx/boolean-prop-naming. Behavior/a11y fixes: - xstyle/className/style land on the root wrapper (not the zero-opacity input). - radioScope applied on the control's own wrapper so a standalone control has a hover state (RadioListItem still applies it on the row for row-hover). - Focus ring shows on the disabled-with-reason path (!isDisabled || isFocusableDisabled), not just when enabled. - {...rest} spread before the contract props (type/name/checked/aria-*/onChange) so a consumer can't clobber the radio semantics. - A lone control still generates a group name when htmlName is omitted so it behaves as its own group. RadioListItem composes it unchanged (public API + rendered behavior stable); it adapts the control's (value, e) callback to the group's value-only onChange. Docs gain a theming block (astryx-radio / astryx-radio-dot) discoverable from the primitive's own page; the story teaches grouping via shared htmlName and drops the lone-toggle anti-pattern. Tests: 332 pass (11 RadioControl incl. new xstyle-root / rest-precedence / disabledMessage-focusable coverage, 44 RadioList unchanged, 277 themingTargets).
|
Pushed the convergence ( Blockers
Advisories Unchanged: Still your call on the API surface per the contributor gate — the shape and convergence are now settled against the conventions; happy to adjust. |
|
Heads up on the red checks on
A re-run should clear them — I don't have permission to re-trigger the workflow as a contributor (same reason "Re-request blocking reviewers" / "Flag review signals" show failure). Flagging rather than treating it as a code failure. Happy to push a trivial no-op commit to re-trigger if you'd prefer that over a re-run. |
|
All 10 points from the review are addressed in Point-by-point🔴 #1 — Prop names converged:
🔴 #2 — Always has an accessible name: 🔴 #3 — 🔴 #4 — 🟡 #5 — Spec issue linked: #4755. Shape settled (A=bare control), arbitration run (C eliminated, A chosen over B), awaiting maintainer API-surface sign-off. 🟡 #6 — Focus ring on disabled-with-reason: gated on 🟡 #7 — 🟡 #8 — 🟡 #9 — Story fixed: Default story is gone (was the lone-toggle anti-pattern); replaced with Sizes, Disabled, DisabledWithReason, and ControlledGroup (grouping via shared htmlName). The story teaches the real use case, not a broken demo. 🟡 #10 — Doc theming block: Verified clean
|
|
Closing — superseded. Won't merge. |
What
Adds a standalone
RadioControlprimitive — the radio input + its visual dot (astryx-radio/astryx-radio-dot) — that takes everything as props and works outside aRadioList.RadioListItemnow composes it.Today
RadioListItemreadsRadioListContextforname/value/onChange/size/isDisabled/isRequiredand throws if rendered outside aRadioList:So there was no way to render a single radio control (e.g. a bespoke layout, a cell, a custom grouping) without building a whole
RadioList.RadioControlcloses that gap: it's the self-contained control, andRadioListItembecomes a thin composition of it (context → props), keeping its label/description/row layout.API
checked,onChange(value),value,name,size?(sm/md),isDisabled?,isRequired?,id?,aria-describedby?label?— accessible name for a standalone control (applied asaria-label). Omit it when an external<label htmlFor>already names the input, asRadioListItemdoes — so there's no double-naming.keepFocusableWhenDisabled?— preserves the group-disabled-with-message behavior (aria-disabled+ detachedforminstead of nativedisabled, so a reason tooltip stays keyboard-reachable).Unchanged behavior
RadioListItem's public API and rendered output are identical — its existing test suite (44 tests) passes untouched, including theastryx-radio/astryx-radio-dottargets, checked/disabled data-attrs, the focusable-disabled path, and the<label htmlFor>wiring. ThethemeProps('radio')/themeProps('radio-dot')calls moved verbatim intoRadioControl(same directory, same targets), so the theming surface is unchanged.Testing
RadioControl.test.tsx(8): renders a working standalone radio with an accessible name (no throw outside a RadioList),checkedreflects the prop, click firesonChange(value), disabled blocks it, rendersastryx-radio+astryx-radio-dot(dot only when checked), and thekeepFocusableWhenDisabledpath stays focusable while blocking selection.RadioList.test.tsx(44) unchanged and green;themingTargetsguard green. Typecheck + lint clean.RadioControl.doc.mjs+ aRadioControlStorybook story (standalone + a small controlled group). Changeset included.