GooseUI

Components

Radio

New

Radio is a native input for choosing one option from a group. It works in forms without JavaScript and submits the selected value. Give radios the same name to make a group. Use the arrow keys to move between options.

Browser Support

appearance

Customizes the native radio appearance while retaining its browser behavior.

Your browser:

Preview

Choose a plan

Installation

npx shadcn@latest add @gooseui/radio
pnpm dlx shadcn@latest add @gooseui/radio
yarn dlx shadcn@latest add @gooseui/radio
bunx --bun shadcn@latest add @gooseui/radio

Usage

import { Radio } from "@/components/ui/radio"
import { Label } from "@/components/ui/label"

<fieldset>
  <legend>Choose a plan</legend>
  <div><Radio id="basic" name="plan" value="basic" defaultChecked /><Label htmlFor="basic">Basic</Label></div>
  <div><Radio id="pro" name="plan" value="pro" /><Label htmlFor="pro">Pro</Label></div>
</fieldset>

Examples

Disabled

<Radio id="disabled" disabled />
<Label htmlFor="disabled">Unavailable</Label>

With a description

Arrives in three to five days.

<Radio id="delivery" name="delivery" aria-describedby="delivery-description" defaultChecked />
<Label htmlFor="delivery">Standard delivery</Label>
<p id="delivery-description">Arrives in three to five days.</p>

Invalid state

Choose an option to continue.

<Radio id="choice" aria-invalid="true" aria-describedby="error" />
<Label htmlFor="choice">Choose an option</Label>
<p id="error">Choose an option to continue.</p>

In a form

Choose a plan
<form>
  <fieldset>
  <legend>Choose a plan</legend>
  <div><Radio id="basic" name="plan" value="basic" defaultChecked /><Label htmlFor="basic">Basic</Label></div>
  <div><Radio id="pro" name="plan" value="pro" /><Label htmlFor="pro">Pro</Label></div>
</fieldset>
  <Button type="submit">Submit</Button>
</form>

Props

PropTypeDefaultDescription
namestring-Shared name for the group and form field.
valuestring-Value submitted when selected.
checked / defaultCheckedboolean-Controlled or initial selection.
disabledboolean-Disables the input.
requiredboolean-Requires a selection in the group.
aria-invalidboolean | string-Marks the input as invalid.
...propsInputHTMLAttributes<HTMLInputElement>-Other native input attributes, including onChange and aria attributes.