Button Group

A container that groups related buttons together with consistent styling and shared borders.

Examples

Default

A container that groups related buttons together with consistent styling.

<%= render "ui/button_group" do %>
  <%= render "ui/button", variant: :outline do %>Archive<% end %>
  <%= render "ui/button", variant: :outline do %>Report<% end %>
<% end %>

Orientation

Change the button group layout with the orientation prop.

<%= render "ui/button_group", orientation: :vertical, classes: "h-fit" do %>
  <%= render "ui/button", variant: :outline, size: :icon do %>
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/><path d="M12 5v14"/></svg>
  <% end %>
  <%= render "ui/button", variant: :outline, size: :icon do %>
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/></svg>
  <% end %>
<% end %>

Size

Control the size of buttons using the size prop on individual buttons.

<div class="flex flex-col items-start gap-4">
  <%= render "ui/button_group" do %>
    <%= render "ui/button", variant: :outline, size: :sm do %>Small<% end %>
    <%= render "ui/button", variant: :outline, size: :sm do %>Button<% end %>
    <%= render "ui/button", variant: :outline, size: :sm do %>Group<% end %>
  <% end %>

  <%= render "ui/button_group" do %>
    <%= render "ui/button", variant: :outline do %>Default<% end %>
    <%= render "ui/button", variant: :outline do %>Button<% end %>
    <%= render "ui/button", variant: :outline do %>Group<% end %>
  <% end %>

  <%= render "ui/button_group" do %>
    <%= render "ui/button", variant: :outline, size: :lg do %>Large<% end %>
    <%= render "ui/button", variant: :outline, size: :lg do %>Button<% end %>
    <%= render "ui/button", variant: :outline, size: :lg do %>Group<% end %>
  <% end %>
</div>

Nested

Nest button groups to create spacing between groups.

<%= render "ui/button_group" do %>
  <%= render "ui/button_group" do %>
    <%= render "ui/button", variant: :outline, size: :sm do %>1<% end %>
    <%= render "ui/button", variant: :outline, size: :sm do %>2<% end %>
    <%= render "ui/button", variant: :outline, size: :sm do %>3<% end %>
    <%= render "ui/button", variant: :outline, size: :sm do %>4<% end %>
    <%= render "ui/button", variant: :outline, size: :sm do %>5<% end %>
  <% end %>

  <%= render "ui/button_group" do %>
    <%= render "ui/button", variant: :outline, size: :"icon-sm" do %>
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m12 19-7-7 7-7"/><path d="M19 12H5"/></svg>
    <% end %>
    <%= render "ui/button", variant: :outline, size: :"icon-sm" do %>
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/><path d="m12 5 7 7-7 7"/></svg>
    <% end %>
  <% end %>
<% end %>

With Separator

The separator visually divides buttons. Use for non-outline variants to improve visual hierarchy.

<%= render "ui/button_group" do %>
  <%= render "ui/button", variant: :secondary, size: :sm do %>Copy<% end %>
  <%= render "ui/button_group/separator" %>
  <%= render "ui/button", variant: :secondary, size: :sm do %>Paste<% end %>
<% end %>

Split Button

Create a split button group by adding two buttons separated by a separator.

<%= render "ui/button_group" do %>
  <%= render "ui/button", variant: :secondary do %>Button<% end %>
  <%= render "ui/button_group/separator" %>
  <%= render "ui/button", size: :icon, variant: :secondary do %>
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/><path d="M12 5v14"/></svg>
  <% end %>
<% end %>

With Dropdown Menu

Create a split button with a dropdown menu. Use as_child on the dropdown menu to attach it to the button group.

<%= render "ui/dropdown_menu", as_child: true do |dropdown_attrs| %>
  <%= render "ui/button_group", **dropdown_attrs do %>
    <%= render "ui/button", variant: :outline do %>Follow<% end %>
    <%= render "ui/dropdown_menu/trigger", as_child: true do |trigger_attrs| %>
      <%= render "ui/button", variant: :outline, size: :icon, attributes: trigger_attrs do %>
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>
      <% end %>
    <% end %>
    <%= render "ui/dropdown_menu/content", align: "end" do %>
      <%= render "ui/dropdown_menu/item" do %>
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 18a1 1 0 0 0 1 1h18a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v2z"/><path d="M10 10V5a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v5"/><path d="M4 15v-3a6 6 0 0 1 6-6h0"/><path d="M14 6h0a6 6 0 0 1 6 6v3"/></svg>
        Mute Conversation
      <% end %>
      <%= render "ui/dropdown_menu/item" do %>
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="m4.9 4.9 14.2 14.2"/></svg>
        Block User
      <% end %>
      <%= render "ui/dropdown_menu/separator" %>
      <%= render "ui/dropdown_menu/item", variant: :destructive do %>
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/></svg>
        Unfollow
      <% end %>
    <% end %>
  <% end %>
<% end %>

With Input

Wrap an input component with buttons.

<%= render "ui/button_group" do %>
  <%= render "ui/input", type: "text", placeholder: "Search..." %>
  <%= render "ui/button", variant: :outline do %>
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>
  <% end %>
<% end %>

With Text

Display text within a button group.

USD
<%= render "ui/button_group" do %>
  <%= render "ui/button_group/text" do %>
    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2v20M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/></svg>
    USD
  <% end %>
  <%= render "ui/button", variant: :outline do %>Button<% end %>
<% end %>

Features

  • Custom styling with Tailwind classes
  • Horizontal and vertical orientations
  • Automatic border radius handling for grouped elements
  • ARIA group role for accessibility

API Reference

Button Group

A container that groups related buttons together with consistent styling.

Parameters

NameTypeDefaultDescription
orientationSymbol:horizontalOrientation of the group (horizontal or vertical)

Data Attributes

AttributeValuesDescription
data-slotIdentifies this element as a button group
data-orientationThe current orientation of the group

Separator

A visual separator between buttons within the group.

Parameters

NameTypeDefaultDescription
orientationSymbol:horizontalOrientation of the separator (horizontal or vertical)

Data Attributes

AttributeValuesDescription
data-slotIdentifies this element as a button group separator
data-orientationThe current orientation of the separator

Text

A styled text element for use within button groups.

Accessibility

Uses role="group" to semantically group related buttons together.

ARIA Attributes