Radio Button

Examples

Default

A set of checkable buttons where only one can be checked at a time.

<div class="flex flex-col gap-2">
  <div class="flex items-center space-x-2">
    <%= render "ui/radio_button", id: "erb-r1", name: "erb-plan", value: "free", checked: true %>
    <%= render "ui/label", for: "erb-r1" do %>Free<% end %>
  </div>
  <div class="flex items-center space-x-2">
    <%= render "ui/radio_button", id: "erb-r2", name: "erb-plan", value: "pro" %>
    <%= render "ui/label", for: "erb-r2" do %>Pro<% end %>
  </div>
</div>

With Description

Radio buttons with descriptive text for each option.

Receive all notifications including marketing.

Only receive notifications when mentioned.

Turn off all notifications.

<div class="flex flex-col gap-4">
  <div class="flex items-start space-x-3">
    <%= render "ui/radio_button", id: "erb-notify-all", name: "erb-notifications", value: "all", checked: true %>
    <div class="grid gap-1.5 leading-none">
      <%= render "ui/label", for: "erb-notify-all" do %>All notifications<% end %>
      <p class="text-sm text-muted-foreground">Receive all notifications including marketing.</p>
    </div>
  </div>
  <div class="flex items-start space-x-3">
    <%= render "ui/radio_button", id: "erb-notify-mentions", name: "erb-notifications", value: "mentions" %>
    <div class="grid gap-1.5 leading-none">
      <%= render "ui/label", for: "erb-notify-mentions" do %>Mentions only<% end %>
      <p class="text-sm text-muted-foreground">Only receive notifications when mentioned.</p>
    </div>
  </div>
  <div class="flex items-start space-x-3">
    <%= render "ui/radio_button", id: "erb-notify-none", name: "erb-notifications", value: "none" %>
    <div class="grid gap-1.5 leading-none">
      <%= render "ui/label", for: "erb-notify-none" do %>No notifications<% end %>
      <p class="text-sm text-muted-foreground">Turn off all notifications.</p>
    </div>
  </div>
</div>

Horizontal Layout

Radio buttons arranged horizontally.

<div class="flex gap-6">
  <div class="flex items-center space-x-2">
    <%= render "ui/radio_button", id: "erb-size-sm", name: "erb-size", value: "sm" %>
    <%= render "ui/label", for: "erb-size-sm" do %>Small<% end %>
  </div>
  <div class="flex items-center space-x-2">
    <%= render "ui/radio_button", id: "erb-size-md", name: "erb-size", value: "md", checked: true %>
    <%= render "ui/label", for: "erb-size-md" do %>Medium<% end %>
  </div>
  <div class="flex items-center space-x-2">
    <%= render "ui/radio_button", id: "erb-size-lg", name: "erb-size", value: "lg" %>
    <%= render "ui/label", for: "erb-size-lg" do %>Large<% end %>
  </div>
</div>

Features

  • Custom styling with Tailwind classes
  • Disabled state support
  • ARIA attributes for accessibility

API Reference

Radio Button

Parameters

NameTypeDefaultDescription
nameStringnilForm field name
idStringnilHTML id attribute
valueStringnilThe current value
checkedBooleanfalseWhether the element is checked
disabledBooleanfalseWhether the element is disabled
requiredBooleanfalseThe required

Accessibility

Implements the WAI-ARIA Radio Group pattern with proper roles, states, and keyboard navigation.