Skip to content

Forms

Radio

tsx
"use client";
import { Field, Radio, RadioGroup } from "@cherry-design-system/react";

export function Plan() {
  return (
    <Field label="Plan">
      <RadioGroup name="plan" defaultValue="pro">
        <Radio value="free" label="Free" />
        <Radio value="pro" label="Pro" />
        <Radio value="team" label="Team" />
      </RadioGroup>
    </Field>
  );
}

Radio is a native <input type="radio">; RadioGroup wraps a set of them (role="radiogroup") and hands each one its name, value, size and state. Use it for one choice out of a few visible options. Use Select when there are many options and ToggleGroup for a view switch outside a form.

Examples

Horizontal

tsx
"use client";
import { Field, Radio, RadioGroup } from "@cherry-design-system/react";

export function Billing() {
  return (
    <Field label="Billing period">
      <RadioGroup name="billing" defaultValue="monthly" orientation="horizontal" size="sm">
        <Radio value="monthly" label="Monthly" />
        <Radio value="yearly" label="Yearly" />
      </RadioGroup>
    </Field>
  );
}

Controlled

tsx
"use client";
import { useState } from "react";
import { Field, Radio, RadioGroup } from "@cherry-design-system/react";

export function Shipping() {
  const [method, setMethod] = useState<string | null>("standard");
  return (
    <Field label="Shipping">
      <RadioGroup value={method} onValueChange={setMethod}>
        <Radio value="standard" label="Standard (3 to 5 days)" />
        <Radio value="express" label="Express (next day)" />
        <Radio value="pickup" label="Pick up in store" disabled />
      </RadioGroup>
    </Field>
  );
}

Required and error

tsx
"use client";
import { Field, Radio, RadioGroup } from "@cherry-design-system/react";

export function Size() {
  return (
    <Field label="Size" required error="Pick a size.">
      <RadioGroup name="size">
        <Radio value="s" label="Small" />
        <Radio value="m" label="Medium" />
        <Radio value="l" label="Large" />
      </RadioGroup>
    </Field>
  );
}

Properties

RadioGroup

namestring

Shared input name. Generated when omitted.

valuestring | null

Controlled selected value.

defaultValuestring | null

Initial value when uncontrolled. Defaults to null.

onValueChange(value: string) => void

Called with the newly selected value.

size"sm" | "md" | "lg"

Size passed to every Radio. Defaults to "md".

orientation"vertical" | "horizontal"

Stack direction. Defaults to "vertical".

invalidboolean

Error state; set automatically inside a <Field error>.

disabledboolean

Disables every option.

requiredboolean

Marks the group as required.

Renders a <div>, forwards its ref and passes through native <div> attributes.

Radio

valuestringrequired

The value submitted, and matched against the group's value.

labelReactNode

Visible label. Omit only when an aria-label is given.

size"sm" | "md" | "lg"

16 / 18 / 20 px. Inherits the group's size.

invalidboolean

Error state. Inherits the group's (or Field's) state.

wrapperClassNamestring

Class for the outer <label> (className goes to the <input>).

The ref and native <input> attributes go to the <input>.

Styling

Radio root class cherry-radio and group class cherry-radio-group. data-size (sm, md, lg) and, on the group, data-orientation (vertical, horizontal). States: data-invalid, data-disabled, :checked, :disabled. Parts: cherry-radio__control, __input, __dot, __label.

Reads --cherry-primary-default for the checked state, --cherry-border-strong, --cherry-danger-solid, --cherry-ring and --cherry-ring-danger.

Accessibility

Native radios in a named radiogroup: arrow keys move and select. Name the group with a Field label (linked through aria-labelledby), aria-label or aria-labelledby.