noora
Sign in

Button group

Joins related buttons into one control, typically to switch between views or options.

Sizes

Medium is the default.

<.button_group size="small">
  <.button_group_item label="Builds" data-selected />
  <.button_group_item label="Tests" />
  <.button_group_item label="Cache" />
</.button_group>
<.button_group size="medium">
  <.button_group_item label="Builds" data-selected />
  <.button_group_item label="Tests" />
  <.button_group_item label="Cache" />
</.button_group>
<.button_group size="large">
  <.button_group_item label="Builds" data-selected />
  <.button_group_item label="Tests" />
  <.button_group_item label="Cache" />
</.button_group>

With icons

Icons sit before or after the label.

<.button_group size="large">
  <.button_group_item label="Previous" data-selected>
    <:icon_left><.chevron_left /></:icon_left>
  </.button_group_item>
  <.button_group_item label="Next">
    <:icon_right><.chevron_right /></:icon_right>
  </.button_group_item>
</.button_group>

Icon only

For options whose icons are unambiguous. Every item needs an aria-label .

<.button_group size="large">
  <.button_group_item icon_only data-selected aria-pressed="true" aria-label="System theme">
    <.device_desktop />
  </.button_group_item>
  <.button_group_item icon_only aria-pressed="false" aria-label="Light theme">
    <.sun_high />
  </.button_group_item>
  <.button_group_item icon_only aria-pressed="false" aria-label="Dark theme">
    <.moon />
  </.button_group_item>
</.button_group>
<.button_group size="large">
  <.button_group_item icon_only data-selected aria-label="Grid view">
    <.layout_grid />
  </.button_group_item>
  <.button_group_item icon_only aria-label="List view">
    <.menu_2 />
  </.button_group_item>
</.button_group>

Guidelines

  • Use a button group for a small set of mutually exclusive options, such as Line and Scatter plot, or Grid and List view.
  • The group does not track selection. Set data-selected on the active item from your own state. On this page, choosing an item selects it.
  • Pass href , navigate , or patch when each option is a separate page. The item then renders a link with the same appearance.
  • Icon-only items need an aria-label , and an aria-pressed value when they act as toggles, as the theme switcher does.
  • Keep labels to one or two words so the group stays compact.

API reference

<.button_group>

Attribute Type Default Description
size
string
"medium"
The size of the button group "small""medium""large"

Also accepts global attributes.

Slot Description
inner_block Required
Button group items to be rendered

<.button_group_item>

Attribute Type Default Description
href
any
nil
Uses traditional browser navigation to the new location
icon_only
boolean
false
Determines if the button is icon only
label
string
nil
The label of the button group item. Not required when icon_only is set.
navigate
string
nil
Navigates to a LiveView
patch
string
nil
Patches the current LiveView

Also accepts global attributes.

Slot Description
:icon_left
Icon displayed on the left of an item
:icon_right
Icon displayed on the right of an item
inner_block
Inner block that renders HEEx content