Toggle group
Mutually exclusive choices with keyboard navigation and form values.
Usage
After the one-time setup, call the helper directly from ERB. No component import is needed.
<%= lc_toggle_group label: "View", value: "month" do %>
<%= lc_toggle_group_item "Week", value: "week" %>
<%= lc_toggle_group_item "Month", value: "month", selected: true %>
<%= lc_toggle_group_item "Year", value: "year" %>
<% end %>
Examples
Mutually exclusive choices
<%= lc_toggle_group label: "View", value: "month" do %>
<%= lc_toggle_group_item "Week", value: "week" %>
<%= lc_toggle_group_item "Month", value: "month", selected: true %>
<%= lc_toggle_group_item "Year", value: "year" %>
<% end %>
Navigation links
<%= lc_toggle_group label: "Period", as: :nav do %>
<%= lc_toggle_group_item "Month", href: "/components/toggle_group.html", current: true %>
<%= lc_toggle_group_item "Quarter", href: "/components/toggle.html" %>
<%= lc_toggle_group_item "Year", href: "/components/tabs.html" %>
<% end %>
Pills, wrapping or in one scrolling row
<%= lc_stack do %>
<%= lc_toggle_group label: "Category", name: "category", value: "", variant: :pills do %>
<%= lc_toggle_group_item "Leave unchanged", value: "" %>
<%= lc_toggle_group_item "Food", value: "food" %>
<%= lc_toggle_group_item "Transport", value: "transport" %>
<%= lc_toggle_group_item "Lodging", value: "lodging" %>
<% end %>
<%= lc_toggle_group label: "Paid by", name: "payer", value: "ana", variant: :pills, scroll: true do %>
<% %w[Ana Bruno Chiara Daisuke Emeka Farah Gustav].each do |name| %>
<%= lc_toggle_group_item name, value: name.downcase %>
<% end %>
<% end %>
<% end %>
Form values, native radios and reset
<form class="flex flex-col items-center gap-4">
<%= lc_toggle_group label: "Billing", name: "billing", value: "monthly" do %>
<%= lc_toggle_group_item "Monthly", value: "monthly" %>
<%= lc_toggle_group_item "Annual", value: "annual" %>
<%= lc_toggle_group_item "Custom", value: "custom", disabled: true %>
<% end %>
<%= lc_inline role: "radiogroup", aria: { label: "Heard about us" } do %>
<%= lc_toggle "A friend", name: "source", value: "friend", size: :sm %>
<%= lc_toggle "Search", name: "source", value: "search", size: :sm %>
<% end %>
<%= lc_button "Reset", type: :reset, variant: :ghost, size: :sm %>
</form>
Icons, stacked and adaptive layouts
<%= lc_stack gap: :inset, class: "w-full max-w-md" do %>
<%= lc_toggle_group label: "View", as: :nav do %>
<%= lc_toggle_group_item "List", href: "/components/toggle_group.html", current: true, icon: "list-bullet", icon_only: true %>
<%= lc_toggle_group_item "Calendar", href: "/components/toggle.html", icon: "calendar-days", icon_only: true %>
<% end %>
<%= lc_toggle_group label: "Who can open it", name: "access", value: "link", layout: :stacked, class: "w-full" do %>
<%= lc_toggle_group_item "Anyone with the link", value: "link", icon: "link" %>
<%= lc_toggle_group_item "Members", value: "members", icon: "user-group" %>
<%= lc_toggle_group_item "Only me", value: "private", icon: "lock-closed" %>
<% end %>
<%= lc_toggle_group label: "Split", value: "equal", layout: :adaptive do %>
<%= lc_toggle_group_item "Equally", value: "equal", selected: true, icon: "equals" %>
<%= lc_toggle_group_item "Shares", value: "shares", icon: "chart-pie" %>
<%= lc_toggle_group_item "Amounts", value: "exact", icon: "banknotes" %>
<% end %>
<% end %>
A scrolling track
<div class="w-full max-w-xs">
<%= lc_toggle_group label: "Date range", as: :nav, scroll: true do %>
<% %w[Week Month Quarter Year All\ time].each_with_index do |range, index| %>
<%= lc_toggle_group_item range, href: "/components/toggle_group.html##{range.parameterize}", current: index.zero? %>
<% end %>
<% end %>
</div>
API reference
Helpers render semantic HTML and include their interaction wiring. Pass native attributes through class:, data:, aria: and the usual Rails options. Blocks use captured ERB content.
lc_toggle_group
lc_toggle_group(label:, name: nil, value: nil, as: :div, variant: :segmented, size: :md, layout: :inline, scroll: false, **attributes, &block)
| Input | Default | Values |
|---|---|---|
| label | Required | Accessible name, visible where applicable |
| name | nil | — |
| value | nil | — |
| as | :div | — |
| variant | :segmented | — |
| size | :md | — |
| layout | :inline | — |
| scroll | false | true · false |
| attributes | {} | Native HTML attributes; class:, data: and aria: merge with defaults |
| block | Captured block | Captured Rails ERB content |
lc_toggle_group_item
lc_toggle_group_item(label = nil, value: nil, selected: nil, checked: nil, href: nil, current: nil, input: {}, icon: nil, icon_only: false, **attributes, &block)
| Input | Default | Values |
|---|---|---|
| label | nil | Accessible name, visible where applicable |
| value | nil | — |
| selected | nil | — |
| checked | nil | — |
| href | nil | — |
| current | nil | — |
| input | {} | — |
| icon | nil | Heroicon name; spacing is handled automatically |
| icon_only | false | true · false |
| attributes | {} | Native HTML attributes; class:, data: and aria: merge with defaults |
| block | Captured block | Captured Rails ERB content |
The examples also use lc_stack, lc_inline, lc_toggle, and lc_button. Each is documented on its own page.
Styling and extension
Use class: to merge utilities, native attributes for application behavior, and the theming guide for the shared palette. For custom markup, the advanced class helpers expose the same styles, including glass surfaces and class merging.