Segmented Button for M3E
npm install @m3e/segmented-buttonm3e-segmented-button and m3e-button-segment components allows users to select one or more options from a horizontal group. Each segment behaves like a toggle-able button, supporting icon and label content, selection state, and accessibility roles. Built with Material Design 3 principles, it adapts shape, color, and ripple feedback based on interaction state and input modality. Segments are visually unified but independently interactive.
bash
npm install @m3e/segmented-button
`
π» Editor Integration
This package includes a Custom Elements Manifest to support enhanced editor tooling and developer experience.
$3
To enable autocomplete and hover documentation for @m3e/segmented-button, install the Custom Elements Manifest Language Server extension. It will automatically detect the manifest bundled with this package and surface tag names, attributes, slots, and events in supported files.
Alternately, you can explicitly reference the html-custom-data.json and css-custom-data.json in your workspace settings:
`json
{
"html.customData": ["./node_modules/@m3e/segmented-button/dist/html-custom-data.json"],
"css.customData": ["./node_modules/@m3e/segmented-button/dist/css-custom-data.json"]
}
`
π 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.
`html
`
In addition, you must use an import map to include dependencies.
`html
`
> For production, use index.min.js, a11y.min.js and bidi.min.js for faster load times.
ποΈ Elements
- m3e-segmented-button β A button that allows a user to select from a limited set of options.
- m3e-button-segment β A option that can be selected within a segmented button.
π§ͺ Example
The following example illustrates a single-select segmented button with four segments.
`html
8 oz
12 oz
16 oz
20 oz
`
π API Reference
$3
This section details the attributes, slots, events and CSS custom properties available for the m3e-segmented-button component.
#### π οΈ Attributes
| Attribute | Type | Default | Description |
| -------------------------- | --------- | ------- | ------------------------------------------------------------------------- |
| disabled | boolean | false | Whether the element is disabled. |
| hide-selection-indicator | boolean | false | Whether to hide the selection indicator. |
| multi | boolean | false | Whether multiple options can be selected. |
| name | string | | The name that identifies the element when submitting the associated form. |
#### π Events
| Event | Description |
| -------- | ---------------------------------------------------- |
| input | Emitted when the checked state of a segment changes. |
| change | Emitted when the checked state of a segment changes. |
#### π§© Slots
| Slot | Description |
| ----------- | ----------------------------------- |
| _(default)_ | Renders the segments of the button. |
#### ποΈ CSS Custom Properties
| Property | Description |
| ------------------------------------ | ---------------------------------------------------------- |
| --m3e-segmented-button-start-shape | Border radius for the first segment in a segmented button. |
| --m3e-segmented-button-end-shape | Border radius for the last segment in a segmented button. |
$3
This section details the attributes, slots, events and CSS custom properties available for the m3e-button-segment component.
#### π οΈ Attributes
| Attribute | Type | Default | Description |
| ---------- | --------- | ------- | ----------------------------------------------- |
| checked | boolean | false | Whether the element is checked. |
| disabled | boolean | false | Whether the element is disabled. |
| value | string | "on" | A string representing the value of the segment. |
#### π Events
| Event | Description |
| -------- | --------------------------------------- |
| input | Emitted when the checked state changes. |
| change | Emitted when the checked state changes. |
#### π§© Slots
| Slot | Description |
| ----------- | ------------------------------------------ |
| _(default)_ | Renders the label of the option. |
| icon | Renders an icon before the option's label. |
#### ποΈ CSS Custom Properties
| Property | Description |
| --------------------------------------------------------- | --------------------------------------------------- |
| --m3e-segmented-button-height | Total height of the segmented button. |
| --m3e-segmented-button-outline-thickness | Thickness of the buttonβs border. |
| --m3e-segmented-button-outline-color | Color of the buttonβs border. |
| --m3e-segmented-button-padding-start | Padding on the leading edge of the button content. |
| --m3e-segmented-button-padding-end | Padding on the trailing edge of the button content. |
| --m3e-segmented-button-spacing | Horizontal gap between icon and label. |
| --m3e-segmented-button-font-size | Font size of the label text. |
| --m3e-segmented-button-font-weight | Font weight of the label text. |
| --m3e-segmented-button-line-height | Line height of the label text. |
| --m3e-segmented-button-tracking | Letter spacing of the label text. |
| --m3e-segmented-button-with-icon-padding-start | Leading padding when an icon is present. |
| --m3e-segmented-button-icon-size | Font size of the icon. |
| --m3e-segmented-button-selected-container-color | Background color of a selected segment. |
| --m3e-segmented-button-selected-container-hover-color | Hover state-layer color for selected segments. |
| --m3e-segmented-button-selected-container-focus-color | Focus state-layer color for selected segments. |
| --m3e-segmented-button-selected-ripple-color | Ripple color for selected segments. |
| --m3e-segmented-button-selected-label-text-color | Label text color for selected segments. |
| --m3e-segmented-button-selected-icon-color | Icon color for selected segments. |
| --m3e-segmented-button-unselected-container-hover-color | Hover state-layer color for unselected segments. |
| --m3e-segmented-button-unselected-container-focus-color | Focus state-layer color for unselected segments. |
| --m3e-segmented-button-unselected-ripple-color | Ripple color for unselected segments. |
| --m3e-segmented-button-unselected-label-text-color | Label text color for unselected segments. |
| --m3e-segmented-button-unselected-icon-color | Icon color for unselected segments. |
| --m3e-segmented-button-disabled-outline-color | Base color for disabled segment borders. |
| --m3e-segmented-button-disabled-outline-opacity | Opacity applied to disabled segment borders. |
| --m3e-segmented-button-disabled-label-text-color | Base color for disabled label text. |
| --m3e-segmented-button-disabled-label-text-opacity | Opacity applied to disabled label text. |
| --m3e-segmented-button-disabled-icon-color | Base color for disabled icons. |
| --m3e-segmented-button-disabled-icon-opacity | Opacity applied to disabled icons. |
π€ Contributing
See the root monorepo CONTRIBUTING.md` for guidelines on contributing to this package.