SegmentedButton
Segmented button groups combine buttons into a single control. It can present options, switch views, or sort items.
Usage
Import the component:
import 'mdui/components/segmented-button-group.js';
import 'mdui/components/segmented-button.js';
Import the TypeScript type:
import type { SegmentedButtonGroup } from 'mdui/components/segmented-button-group.js';
import type { SegmentedButton } from 'mdui/components/segmented-button.js';
Example:
<mdui-segmented-button-group>
<mdui-segmented-button>Day</mdui-segmented-button>
<mdui-segmented-button>Week</mdui-segmented-button>
<mdui-segmented-button>Month</mdui-segmented-button>
</mdui-segmented-button-group>Examples
Full Width
To make the component take up the full width of its container, add the full-width attribute to the <mdui-segmented-button-group> component.
Single Selection
To enable single selection mode, set the selects attribute of the <mdui-segmented-button-group> component to single. In this mode, the value property of <mdui-segmented-button-group> reflects the value property of the currently selected <mdui-segmented-button>.
Multiple Selection
To enable multiple selection mode, set the selects attribute of the <mdui-segmented-button-group> component to multiple. In this mode, the value property of <mdui-segmented-button-group> is an array consisting of the value properties of the currently selected <mdui-segmented-button> components.
When multiple selection is enabled, the value property of <mdui-segmented-button-group> is an array and can only be accessed and updated in JavaScript.
Icons
To add Material Icons on the left and right sides of the button, use the icon and end-icon attributes on the <mdui-segmented-button> element. Alternatively, use the icon and end-icon slots to add elements on the left and right sides of the button.
To set the Material Icon for the selected state, use the selected-icon attribute on the <mdui-segmented-button> element. Alternatively, use the selected-icon slot.
Link
To turn the button into a link, use the href attribute on the <mdui-segmented-button> component. The download, target, and rel attributes are available for link-related functionality.
Disabled and Loading States
To disable the entire segmented button group, add the disabled attribute to the <mdui-segmented-button-group> element.
To disable specific buttons, add the disabled attribute to the <mdui-segmented-button> element. To make a button enter the loading state, add the loading attribute.
mdui-segmented-button-group API
Properties
| Attribute | Property | Reflect | Type | Default |
|---|---|---|---|---|
full-width | fullWidth | boolean | false | |
If set, the segmented button group expands to fill the width of its container. | ||||
selects | selects | 'single' | 'multiple' | - | |
Controls whether the segmented button group can be selected. By default, it is not selectable. Possible values:
| ||||
disabled | disabled | boolean | false | |
Disables the segmented button group. | ||||
required | required | boolean | false | |
Requires a selection when the form is submitted. | ||||
form | form | string | - | |
Associates the segmented button group with a This lets the segmented button group work with any form in the document, not just the one it is nested in. | ||||
name | name | string | '' | |
The name of the segmented button group, which is submitted with form data. | ||||
value | value | string | string[] | '' | |
The value of the selected Note: The HTML attribute always accepts a string and can only be used as an initial value when | ||||
defaultValue | string | string[] | '' | ||
The default selected value. The group resets to this state when the form is reset. JavaScript only. | ||||
validity | ValidityState | - | ||
A | ||||
validationMessage | string | - | ||
Validation message. Empty string when valid. | ||||
Methods
| Name | Parameters | Returns |
|---|---|---|
checkValidity | boolean | |
Checks the validity of the form field. If it is invalid, it triggers an | ||
reportValidity | boolean | |
Checks the validity of the form field. If it is invalid, it triggers an | ||
setCustomValidity |
| void |
Sets a custom error message. If the message is non-empty, the field is considered invalid. | ||
CSS Custom Properties
| Name |
|---|
--shape-corner |
The corner radius of the component. You can use a specific pixel value, but it is recommended to reference design tokens. |
mdui-segmented-button API
Properties
| Attribute | Property | Reflect | Type | Default |
|---|---|---|---|---|
icon | icon | string | - | |
Specifies the Material Icons name for the left icon. Alternatively, use | ||||
end-icon | endIcon | string | - | |
Specifies the Material Icons name for the right icon. Alternatively, use | ||||
selected-icon | selectedIcon | string | - | |
Specifies the Material Icons name for the selected state. Alternatively, use | ||||
href | href | string | - | |
The URL for the link. When set, the component renders as an | ||||
download | download | string | - | |
Downloads the linked URL. Note: Only available when | ||||
target | target | '_blank' | '_parent' | '_self' | '_top' | - | |
Controls where the linked URL opens. Possible values:
Note: Only available when | ||||
rel | rel | 'alternate' | 'author' | 'bookmark' | 'external' | 'help' | 'license' | 'me' | 'next' | 'nofollow' | 'noreferrer' | 'opener' | 'prev' | 'search' | 'tag' | - | |
Specifies the relationship of the linked URL as space-separated link types. Possible values:
Note: Only available when | ||||
autofocus | autofocus | boolean | false | |
Whether the element is focused when the page loads. | ||||
tabindex | tabIndex | number | - | |
The element's tab order when navigating with the Tab key. | ||||
disabled | disabled | boolean | false | |
Disables the element. | ||||
loading | loading | boolean | false | |
Indicates that the element is in a loading state. | ||||
name | name | string | '' | |
The button name submitted with form data. Note: Only available when | ||||
value | value | string | '' | |
The button value submitted with form data. Note: Only available when | ||||
type | type | 'submit' | 'reset' | 'button' | 'button' | |
Specifies the button's default action. Default:
Note: Only available when | ||||
form | form | string | - | |
Associates the button with a This lets the button target any form in the document, not just the one it is nested in. Note: Only available when | ||||
formaction | formAction | string | - | |
Specifies the URL that processes the button's submitted information. Overrides the Note: Only available when | ||||
formenctype | formEnctype | 'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/plain' | - | |
Specifies how to encode the form data. Possible values:
Overrides the Note: Only available when | ||||
formmethod | formMethod | 'post' | 'get' | - | |
Specifies the HTTP method for form submission. Possible values:
Overrides the Note: Only available when | ||||
formnovalidate | formNoValidate | boolean | false | |
Specifies that the form should not be validated on submission. Overrides the Note: Only available when | ||||
formtarget | formTarget | '_self' | '_blank' | '_parent' | '_top' | - | |
Specifies where to open the response after form submission. Possible values:
Overrides the Note: Only available when | ||||
validity | ValidityState | - | ||
A | ||||
validationMessage | string | - | ||
The validation message. Returns an empty string when the element is valid. | ||||
Methods
| Name | Parameters | Returns |
|---|---|---|
click | void | |
Simulates a mouse click on the element. | ||
focus |
| void |
Sets focus on the element. An optional object parameter may include a | ||
blur | void | |
Removes focus from the element. | ||
checkValidity | boolean | |
Checks the validity of the form field. If it is invalid, it triggers an | ||
reportValidity | boolean | |
Checks the validity of the form field. If it is invalid, it triggers an | ||
setCustomValidity |
| void |
Sets a custom error message. If the message is non-empty, the field is considered invalid. | ||
Slots
| Name |
|---|
| (default) |
Text content. |
icon |
Left icon. |
selected-icon |
Icon for the selected state. |
end-icon |
Right icon. |