Skip to content

Toggle Button ​

BsToggleButton is a group of buttons with toggle capability. It is primarily used to visualize options with different approaches, such as selecting options, switching views, or sorting elements.

Updated in v2.2.0

Overview ​

BsToggleButton component shares the same style variants as BsButton and use BsButton internally. And if you like Google Material Design 3 - Segmented Button style, you can choose a style variant that meet the Material Design 3 - Segmented Button specifications.

BsToggleButton component is like HTML5 <input> element. This means that you can add attributes like readonly, or disabled and it will react to them to give the best experience. You can also use v-model directive to create two-way data bindings on the model-value property. This is useful to control or maintain the model-value property.

What are you drinking?

IMPORTANT

  • The <bs-button-toggle> tag still works, but has been deprecated since v2.0.0.
  • Never assign a single datasource to multiple <bs-toggle-button>. It may cause unwanted bug or duplicate ID attribute.

INFO

Since v2.2.0, the bundle only provide contextual color variants. It is located at dist/theme-light.css and dist/theme-dark.css files. If the component style and color doesn't suit to your needs, you can customize it using the component's CSS variables or use the provided SASS mixins.

Checked Icon ​

With the help of slot icon you can add dynamic checked icon.

Added in v2.0.1

Multiple Selection ​

BsToggleButton also support multiple selection mode. Use and define the multiple property explicitly to enable multiple selection mode.

Updated in v2.2.1

Style Variants ​

You can style the <bs-toggle-button> component to your own preference or use a style variant based on Google Material Design 3 specifications. Example below show various built-in style variants and demonstrate how to put an icon inside the <bs-toggle-button> and change the icon dynamically like a segmented buttons behaves.

Updated in v2.2.0
How is the weather today?

Combination ​

How is the weather today?

INFO

Since v2.1.0, Google Material Icons are replaced with Google Material Symbols.

Usage Example ​

The following is an example that demonstrate more advanced use of the <bs-toggle-button>.

21st Century Strangers
68 MB
New Name
72 MB
Not Me
58 MB
Mutter
68 MB
True Love
68 MB

CSS Variables ​

The component CSS variables are inherited from BsButton CSS variables.

Updated in v2.2.0

API Reference ​

TInputOptionItem ​

PropertyTypeDescription
value requiredString|NumberThe item value.
label requiredStringThe item label.
idStringHtml <input> element ID.
nameStringHtml <input> element name. It is used when multiple is true.
disabledBooleanHtml <input> element state.
readonlyBooleanHtml <input> element state.
iconString
The icon to display inside the button.

Use any valid android icon name from Google Material Symbols with or without a suffix. Valid suffixes are: _outlined, _rounded, _sharp, _filled, _outlined_filled, _rounded_filled, and _sharp_filled.

Suffix will take precedence over iconVariant property.
iconFlipStringFlip the icon. Valid values are: horizontal, vertical, both.
iconPulseBooleanApply pulse animation to the icon.
iconSizeNumberRender the icon at predefined size in pixel.
iconSpinBooleanApply spin animation to the icon.
iconRotationNumberRotate the icon. Valid values are: 90, 180, 270.
iconVariantStringUse predefined icon style variant. Valid values are: outlined, rounded, sharp, filled, outlined_filled, rounded_filled, and sharp_filled. v2.1.0

Released under the BSD-3-Clause License.