On this page Button Group Button Group

The m3e-button-group component arranges multiple into a unified, expressive layout.

Installation
npm i @m3e/button-group
Usage

This section outlines usage examples and configuration guidance for the components in this package.

Variants

There are two appearance variants: standard (default) and connected. Use the variant attribute to change the appearance.

Standard button groups add interaction between adjacent buttons

<m3e-button-group>
  <m3e-icon-button>
    <m3e-icon name="arrow_back"></m3e-icon>
  </m3e-icon-button>
  <m3e-icon-button>
    <m3e-icon name="arrow_forward"></m3e-icon>
  </m3e-icon-button>
  <m3e-icon-button width="wide" variant="filled">
    <m3e-icon name="add"></m3e-icon>
  </m3e-icon-button>
  <m3e-icon-button>
    <m3e-icon name="picture_in_picture"></m3e-icon>
  </m3e-icon-button>
  <m3e-icon-button>
    <m3e-icon name="more_vert"></m3e-icon>
  </m3e-icon-button>
</m3e-button-group>

Connected button groups behave similarly to standard groups, except they don't affect adjacent buttons and fill available space.

Start Directions Share
<m3e-button-group variant="connected">
  <m3e-button variant="tonal" toggle>Start</m3e-button>
  <m3e-button variant="tonal" toggle>Directions</m3e-button>
  <m3e-button variant="tonal" toggle>Share</m3e-button>
</m3e-button-group>

Icon buttons will also grow to fill available space.

Sizes

There are five size variants used to control spacing between button: extra-small, small (default), medium, large, and extra-large. Use the size attribute control spacing. To create buttons with a uniform size, set each button's size to the same size as the button group.

<m3e-button-group size="large">
  <m3e-icon-button size="large">
    <m3e-icon name="arrow_back"></m3e-icon>
  </m3e-icon-button>
  <m3e-icon-button size="large">
    <m3e-icon name="arrow_forward"></m3e-icon>
  </m3e-icon-button>
  <m3e-icon-button size="large" width="wide" variant="filled">
    <m3e-icon name="add"></m3e-icon>
  </m3e-icon-button>
  <m3e-icon-button size="large">
    <m3e-icon name="picture_in_picture"></m3e-icon>
  </m3e-icon-button>
  <m3e-icon-button size="large">
    <m3e-icon name="more_vert"></m3e-icon>
  </m3e-icon-button>
</m3e-button-group>

Connected button groups always have the same spacing between buttons, regardless of size.

Start Directions Share
<m3e-button-group size="large" variant="connected">
  <m3e-button variant="tonal" size="large" toggle>Start</m3e-button>
  <m3e-button variant="tonal" size="large" toggle>Directions</m3e-button>
  <m3e-button variant="tonal" size="large" toggle>Share</m3e-button>
</m3e-button-group>
Selection

Button groups containing toggle buttons support both single-select and multi-select modes. Use the multi attribute to allow multiple toggle buttons to be selected simultaneously.

<m3e-button-group multi>
  <m3e-icon-button variant="tonal" toggle>
    <m3e-icon name="format_bold"></m3e-icon>
  </m3e-icon-button>
  <m3e-icon-button variant="tonal" toggle>
    <m3e-icon name="format_italic"></m3e-icon>
  </m3e-icon-button>
  <m3e-icon-button variant="tonal" toggle>
    <m3e-icon name="format_underlined"></m3e-icon>
  </m3e-icon-button>
</m3e-button-group>
Accessibility

By default, button groups are given the ARIA role group, indicating a set of related user interface elements that are grouped together. For a single-select group containing one or more toggle buttons, button groups are given the ARIA role radiogroup and buttons are given the role radio.

Always provide an accessible label via aria-label or aria-labelledby for each button group.

Native module support

This package uses JavaScript Modules. To use it directly in a browser without a bundler, use a module script similar to the following.

<script type="module" src="/node_modules/@m3e/button-group/dist/index.js"></script>

You also need a module script for @m3e/button and @m3e/icon-button due to being a dependency.

<script type="module" src="/node_modules/@m3e/button/dist/index.js"></script>
<script type="module" src="/node_modules/@m3e/icon-button/dist/index.js"></script>

In addition, you must use an import map to include additional dependencies.

<script type="importmap">
  {
    "imports": {
      "lit": "https://cdn.jsdelivr.net/npm/lit@3.3.0/+esm",
      "@m3e/core": "/node_modules/@m3e/core/dist/index.js"
    }
  }
</script>

For production, use index.min.js for faster load times.

API

This package includes a Custom Elements Manifest (custom-elements.json), which documents the properties, attributes, slots, events and CSS custom properties of each component.

You can explore the API below, or integrate the manifest into your own tooling.