SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

RadioGroup

A set of mutually exclusive options built from native <input type="radio"> controls sharing one grouping name, rendered as a role="radiogroup" host wrapping a run of RadioGroup.Radio instances.

Shipping method
Gift wrapping
View code
tsx
<div mix={[vstack({ gap: 6, align: "stretch" })]}>
	<div mix={[vstack({ gap: 2, align: "stretch" })]}>
		<Header mix={[m(0)]}>Shipping method</Header>
		<RadioGroup aria-label="Shipping method" name="shippingMethod">
			{METHODS.map((method) => (
				<RadioGroup.Radio
					key={method.value}
					value={method.value}
					required
					defaultChecked={method.value === "express"}
					disabled={method.disabled}
					mix={[
						p(3),
						rounded("md"),
						border({ color: "neutral.border", width: 1 }),
						has("input:checked", [border("brand.ring"), bg("brand.tint")]),
					]}
				>
					<span mix={[vstack({ gap: 0.5, align: "start" })]}>
						<span mix={[text("sm"), weight("medium")]}>
							{method.label} · {method.price}
						</span>
						<span mix={[text("xs")]}>{method.eta}</span>
					</span>
				</RadioGroup.Radio>
			))}
		</RadioGroup>
	</div>

	<div mix={[vstack({ gap: 2, align: "stretch" })]}>
		<Header mix={[m(0)]}>Gift wrapping</Header>
		<RadioGroup aria-label="Gift wrapping" name="giftWrap" orientation="horizontal">
			<RadioGroup.Radio value="none" defaultChecked>
				None
			</RadioGroup.Radio>
			<RadioGroup.Radio value="paper">
				Paper
			</RadioGroup.Radio>
			<RadioGroup.Radio value="box">
				Gift box
			</RadioGroup.Radio>
		</RadioGroup>
	</div>
</div>

Installation

An ordinary dependency: install it, import the theme once, and import the component where it is used.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Or copy it into your project to edit it:

Terminal
sdxc ui add radio-group

Usage

typescript
import { RadioGroup } from "@sdxc/ui";

Renders the group host: a role="radiogroup" <div> laying its RadioGroup.Radio options in a column, or a row when orientation is "horizontal", giving every option a shared, stable name.

Composition

The parts the component publishes, each a static property of the host.

  • RadioGroup
  • RadioGroup.RadioRenders a single option: a <label> pairing a hidden native <input type="radio"> with an indicator driven by its checked, focus and disabled state.

Examples

Horizontal

View code
tsx
<RadioGroup aria-label="Instance size" orientation="horizontal">
	<RadioGroup.Radio value="sm">Small</RadioGroup.Radio>
	<RadioGroup.Radio value="md" defaultChecked>Medium</RadioGroup.Radio>
	<RadioGroup.Radio value="lg">Large</RadioGroup.Radio>
</RadioGroup>

Props

Read from the component's own types, so every prop, every default and every allowed value is listed.

PropTypeDefaultRequiredDescription
namestring—NoNative grouping name shared by every RadioGroup.Radio nested inside. Defaults to the group's own stable instance id so options group correctly without a consumer setting one.
orientation"horizontal" | "vertical"—NoLayout axis. Defaults to DEFAULT_ORIENTATION.

Also accepts everything in TagProps<"div">.

RadioGroup.Radio

PropTypeDefaultRequiredDescription
valuestring—YesValue submitted with the enclosing form when this option is selected.
namestring—NoNative grouping name for this option's underlying input. Defaults to the name provided by the nearest ancestor RadioGroup — set this only to opt a single option out of its group's shared name.
defaultCheckedboolean—NoWhether this option starts selected, for a form that leaves selection tracking to the browser.
checkedboolean—NoWhether this option is selected, for a form that tracks selection itself.
disabledboolean—NoWhether this option is inert and excluded from the group's tab order.
requiredboolean—NoMarks the enclosing native radio group as requiring one option selected.
childrenRemixNode—NoThe option's visible label text, associated with the input by native nesting.

Also accepts everything in Omit<TagProps<"label">, "children">.

Types

NameValuesWhat it decides
Orientation"horizontal" | "vertical"Axis a group's options lay out along: a single column, or a single row.
@sdxc/ui

Can’t find it? Contact us