Radio handbook
v1.4.0 · @snowui-design-system/components
License: Before reading component documentation, source, or npm usage instructions for the first time, read the full LICENSE. Reuse that review for the same task and version. Public API configuration and internal implementation changes have different license implications. All components use the unified runtime package; source rights remain governed by the license.
Overview
Choose one option from a mutually exclusive set, suitable for form settings where every option should be visible.
When to use it
Use Radio for a single choice among visible options. Use Checkbox for independent choices and Segmented for compact mode selection. Give the group and each option accessible names.
Bind the same
groupstate across options and give each option a distinct, stablevalue. Usenullfor an initially unselected group.Clicking the selected option again can clear the selection to
undefined. Do not assume a radio choice is irrevocable; provide readable labels.
Quick start
This example shows the recommended basic composition. See the sections below for more cases and composition limits.
API
See the base component documentation for inherited capabilities not redeclared here. This table lists only named public Props declared by this component.
Usage boundaries and details
Keyword
It is recommended to provide the name role="radiogroup" in the outer layer of the group. Use Tab focus and Space switching; the current component manages group values through binding, and does not provide in-group direction key navigation. The remaining attributes such as name and required are passed to the outer Frame, which is not equivalent to the form attributes of the native input of the inner layer.
Layout model
Main layout model: inline shell layout. See specs/maintainers/LayoutProtocol.md §12.4.
Radio belongs to the inline shell subcategory of "control visual body + label":
The root node keeps
inline-flex, and the content is Hug as a whole..snowui-radio-visualis the control visual body of fixed Hug..snowui-radio-labelis an optional label. It hugs its contents when there is room and can shrink with a single-line ellipsis when constrained. Original content and the complete native accessible name are preserved.visual and label spacing uses
--snowui-radio-gap. Set a preferred value with gap or--snowui-radio-gap-override; effective spacing stays at least 4 CSS px.sizeindicates the space size of the control containing transparent white space, which does not change the layout strategy of the label.The white space around is
size / 16, and the width and height of the visible graphic aresize × 0.875; for example,size={32}occupies 32×32px, the graphic is 28×28px, and the four sides are 2px each. The white and graphics are scaled with the size, root font size and size Token, and the white white can still be clicked.The white space is held by the shared control shell, and the label is located outside the shell; the inner frame continues to be calculated according to the nominal size of
0.0625, and the rounded corners, Dot and selected rings are calculated according to the visible graphic size.as="badge"only means that Radio is the corner pendant of Image, and does not change the internal layout model of Radio.
Usage examples
Outline
Not selected: gray border, transparent background
Select: theme color dots, gray border
Filled (default)
Not selected: gray border, transparent background
Select: theme color background, white dots
State
Unchecked: Unchecked status
Checked: Selected status
Disabled: Disabled status
Group behavior
When using the group attribute:
Automatically manage the single-choice logic in the same group
Selecting one will automatically cancel other options.
Clicking the currently selected item again will uncheck it.
After canceling the current selection, the
groupvalue will be cleared toundefinedThe value of
groupis equal to thevalueof the selected item.
Accessibility
Use the native
<input type="radio">as the basic semantics, and add the "click again to cancel" logic in the component.Support Tab key focus
Support Space key selection and cancellation
Group selection uses bindings. The component does not currently provide arrow-key navigation within the group.
In the disabled state,
tabindex=-1
Radio style coverage
Read the full LICENSE first; reuse that review for the same task, version, and scope.
First use public component Props to match the desired appearance, preserving the existing look where possible. If changes are necessary, follow the style selection and override order: use your own class (including Tailwind already in the project) or an instance style. The names below are public overrides actually consumed by source; check their scope and do not modify private DOM. Choose the correct SnowUI token family. External apps need not install SnowUI website utilities.
Radio type and status
Required Props: no named required Props.
Bidirectional binding: bind:checked, bind:group.
Inheritance statement: Omit<FrameProps, "size">. The inheritance ability is subject to the public document of the base class; the fields in Omit have been excluded and cannot be used as they are according to the base class.
The following type declarations are actually referenced by public Props and come from source. A Svelte Snippet denotes a content fragment; ComponentProps denotes the Props of the corresponding component.
ResourceSize
Source: components/src/context.ts