Skip to Content

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-ui

Usage

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

PropTypeDefaultDescription
valuestring | null-Controlled selected value. null selects nothing.
defaultValuestring | null-Initial value when uncontrolled.
onValueChange(value: string | null, details) => void-Called when the selection changes.
namestring-Form field name for the hidden native radio.
disabledbooleanfalseDisable every item.
readOnlybooleanfalseShow the value without allowing changes.
requiredbooleanfalseRequire a choice in a form.
formstring-id of a form to attach the hidden radio to.
loopbooleantrueWhether arrow keys wrap from the last item to the first.
controllerRadioGroupController-Read and drive the group from outside (createRadioGroupController()).
classNamestring-Merged with grid gap-2.

RadioGroupItem

PropTypeDefaultDescription
valuestring-This option's value.
disabledbooleanfalseDisable this option.
classNamestring-Class on the radio. Wrap it with its text in a label, or give it aria-label.