Radio Group
A set of options where exactly one can be selected.
import { RadioGroup, RadioGroupItem } from "@dapplelight/signet-ui/components/radio-group"
const plans = [
{ value: "starter", label: "Starter" },
{ value: "team", label: "Team" },
{ value: "scale", label: "Scale" },
]
export function Demo() {
return (
<RadioGroup defaultValue="team" aria-label="Plan">
{plans.map((p) => (
<label key={p.value} className="flex items-center gap-2 text-sm">
<RadioGroupItem value={p.value} />
{p.label}
</label>
))}
</RadioGroup>
)
}Installation
npm i @dapplelight/signet-uiUsage
import { RadioGroup, RadioGroupItem } from "@dapplelight/signet-ui/components/radio-group"
<RadioGroup defaultValue="team" aria-label="Plan">
<label className="flex items-center gap-2">
<RadioGroupItem value="team" />
Team
</label>
</RadioGroup>Built on UI SDK's radio: one tab stop, and arrow keys move and check.
Examples
Controlled
Selected: starter
import { useState } from "react"
import { RadioGroup, RadioGroupItem } from "@dapplelight/signet-ui/components/radio-group"
const [plan, setPlan] = useState("starter")
<RadioGroup value={plan} onValueChange={(v) => setPlan(v ?? "")} aria-label="Plan">
<label className="flex items-center gap-2 text-sm">
<RadioGroupItem value="starter" /> Starter
</label>
<label className="flex items-center gap-2 text-sm">
<RadioGroupItem value="team" /> Team
</label>
</RadioGroup>Disabled item
import { RadioGroup, RadioGroupItem } from "@dapplelight/signet-ui/components/radio-group"
<RadioGroup defaultValue="card" aria-label="Payment method">
<label className="flex items-center gap-2 text-sm">
<RadioGroupItem value="card" /> Card
</label>
<label className="flex items-center gap-2 text-sm opacity-50">
<RadioGroupItem value="wire" disabled /> Wire transfer
</label>
</RadioGroup>In a form
import { Label } from "@dapplelight/signet-ui/components/label"
import { RadioGroup, RadioGroupItem } from "@dapplelight/signet-ui/components/radio-group"
import { onSubmit } from "./actions"
<form onSubmit={onSubmit}>
<Label id="radio-delivery">Delivery</Label>
<RadioGroup name="delivery" defaultValue="standard" required aria-labelledby="radio-delivery">
<label className="flex items-center gap-2 text-sm">
<RadioGroupItem value="standard" /> Standard (3 to 5 days)
</label>
<label className="flex items-center gap-2 text-sm">
<RadioGroupItem value="express" /> Express (next day)
</label>
</RadioGroup>
</form>API Reference
RadioGroup
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | null | - | Controlled selected value. null selects nothing. |
| defaultValue | string | null | - | Initial value when uncontrolled. |
| onValueChange | (value: string | null, details) => void | - | Called when the selection changes. |
| name | string | - | Form field name for the hidden native radio. |
| disabled | boolean | false | Disable every item. |
| readOnly | boolean | false | Show the value without allowing changes. |
| required | boolean | false | Require a choice in a form. |
| form | string | - | id of a form to attach the hidden radio to. |
| loop | boolean | true | Whether arrow keys wrap from the last item to the first. |
| controller | RadioGroupController | - | Read and drive the group from outside (createRadioGroupController()). |
| className | string | - | Merged with grid gap-2. |
RadioGroupItem
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | This option's value. |
| disabled | boolean | false | Disable this option. |
| className | string | - | Class on the radio. Wrap it with its text in a label, or give it aria-label. |