Skip to content

Checkbox

BsCheckbox is a component that let users select one or more items from a list, or turn an item on or off.

Overview

BsCheckbox component mimics the HTML5 <input type="checkbox"> element. This means that you can add attributes like required, 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.

Value:

Checkbox Group

BsCheckboxGroup is a collection of BsCheckbox. Rather than create multiple <bs-checkbox>, it's better to create single <bs-checkbox-group>. <bs-checkbox-group> can be integrated with external validator plugin such as Vuelidate.

Selected colors: []


Selected fruits: []

INFO

<bs-checkbox-group> will be displayed in one column if the media query matches (max-width: 575px). And if the media query matches (min-width: 576px) it will try to fit up to four columns.

Multi Column

With <bs-checkbox-group>, collection of <bs-checkbox> can be arranged in multi-columns. When the number of <bs-checkbox> exceed the number of maximum columns, then the remaining <bs-checkbox> will be placed on the next row.

Updated on v2.0.0
Selected items: []

INFO

Multi columns are closely tied to the bootstrap class col-lg-*. Which means if the media query matches (min-width: 992px), it will be displayed correctly. And if the media query matches (min-width: 768px), it will be displayed in two columns only.

Colors

Use color property to change <bs-checkbox> or <bs-checkbox-group> color appearance. Additionally, you can set each checkbox of <bs-checkbox-group> to have different color.


TIP

Any MDBootstrap Color variants and Material Color variants can be applied to the color property.

Custom Checkbox

The following is an example that demonstrate how to customize checkbox appearance via css variables.

Added since v2.0.7
Value:

CSS Variables

Added since v2.0.0
scss
--md-checkbox-disabled-bg: transparent;
--md-checkbox-disabled-opacity: calc(var(--md-field-disabled-opacity) - .2);
--md-checkbox-border-radius: .25rem;
--md-checkbox-margin: .5rem 1rem .5rem 0;
--md-checkbox-size: 20px;
--md-checkbox-stroke: 2px;
--md-checkbox-touch-size: 40px;
--md-checkbox-indeterminate-width: 12px;
--md-checkbox-checkmark-height: 13px; 
--md-checkbox-checkmark-width: 7px; 
--md-checkbox-checkmark-pos-x: 4px; 
--md-checkbox-checkmark-pos-y: 0;

--md-checkbox-bg: #{$color};             // background color when checked
--md-checkbox-color: #{$checked-color};  // border color when checked
--md-checkbox-state-bg: transparent;     // background color when checked or un-checked
--md-checkbox-state-color: currentColor; // border color when checked or un-checked

API Reference

BsCheckbox

BsCheckboxGroup

TCheckboxProps

The TCheckboxProps has properties as described below:

PropertyTypeDescription
value requiredString/NumberThe <bs-checkbox> value.
label requiredStringThe <bs-checkbox> label.
colorStringThe <bs-checkbox> color appearance.
disabledBooleanCreate <bs-checkbox> in disabled state.
readonlyBooleanCreate <bs-checkbox> in readonly state.
idStringSets the <bs-checkbox> element ID attribute. This property value is auto generates.
nameBooleanSets the <bs-checkbox> element name attribute.
indeterminateBooleanSets an indeterminate state for the <bs-checkbox>.

Released under the BSD-3-Clause License.