MDUIDocs
Copy llms.txt linkCopy llms-full.txt linkView this page in MarkdownDiscuss this page with ChatGPTDiscuss full project docs with ChatGPT
Preset Colors
Custom Color
Extract from Wallpaper
Please select a wallpaper
Getting Started
AI-Assisted Development
Styles
Integration with Frameworks
Components
Avatar Badge BottomAppBar Button ButtonIcon Card Checkbox Chip CircularProgress Collapse Dialog Divider Dropdown Fab Icon Layout LinearProgress List Menu NavigationBar NavigationDrawer NavigationRail Radio RangeSlider Select SegmentedButton Slider Snackbar Switch Tabs TextField Tooltip TopAppBar
Functions
Libraries

Checkbox

Checkboxes allow users to select one or more options from a set. Each checkbox can toggle between checked and unchecked states.

Usage

Import the component:

import 'mdui/components/checkbox.js';

Import the TypeScript type:

import type { Checkbox } from 'mdui/components/checkbox.js';

Example:

Checkbox
<mdui-checkbox>Checkbox</mdui-checkbox>

Examples

Checked State

The checked property is true when the checkbox is checked. Add the checked attribute to set the checkbox to the checked state by default.

Disabled State

Use the disabled attribute to disable the checkbox.

Indeterminate State

The indeterminate attribute sets the checkbox to an indeterminate state.

Icons

Use the unchecked-icon, checked-icon, and indeterminate-icon attributes to set the Material Icons for the checkbox in unchecked, checked, and indeterminate states, respectively. Alternatively, use the corresponding slots to set the icons.

API

Properties

AttributePropertyReflectTypeDefault
disableddisabledbooleanfalse

Disables the checkbox.

checkedcheckedbooleanfalse

Sets the checkbox to the checked state.

defaultCheckedbooleanfalse

Sets the default checked state. The checkbox resets to this state when the form is reset. JavaScript only.

indeterminateindeterminatebooleanfalse

Sets the checkbox to an indeterminate state.

requiredrequiredbooleanfalse

The checkbox must be checked to submit the form.

formformstring-

Associates the checkbox with a <form> element. Set this to the id of a <form> in the same document. If omitted, the checkbox uses its parent <form>, if any.

This lets the checkbox work with any form in the document, not just the one it is nested in.

namenamestring''

Sets the checkbox's name, which is submitted with form data.

valuevaluestring'on'

Sets the checkbox's value, which is submitted with form data.

unchecked-iconuncheckedIconstring-

Sets the Material Icons name for the unchecked state. Alternatively, use slot="unchecked-icon".

checked-iconcheckedIconstring-

Sets the Material Icons name for the checked state. Alternatively, use slot="checked-icon".

indeterminate-iconindeterminateIconstring-

Sets the Material Icons name for the indeterminate state. Alternatively, use slot="indeterminate-icon".

validityValidityState-

A ValidityState object that represents the element's validity states.

validationMessagestring-

Validation message. Empty string when valid.

autofocusautofocusbooleanfalse

Whether the element is focused when the page loads.

tabindextabIndexnumber-

The element's tab order when navigating with the Tab key.

Methods

NameParametersReturns
checkValidity
boolean

Checks the validity of the form field. If it is invalid, it triggers an invalid event and returns false. If valid, it returns true.

reportValidity
boolean

Checks the validity of the form field. If it is invalid, it triggers an invalid event, returns false, and displays a validation message. If valid, it returns true.

setCustomValidity
  • message: string
void

Sets a custom error message. If the message is non-empty, the field is considered invalid.

click
void

Simulates a mouse click on the element.

focus
  • options: FocusOptions (Optional)
void

Sets focus on the element. An optional object parameter may include a preventScroll property. If preventScroll is set to true, the page will not scroll to bring the focused element into view.

blur
void

Removes focus from the element.

Events

Name
focus

Emitted when the checkbox gains focus.

blur

Emitted when the checkbox loses focus.

change

Emitted when the checked state changes.

input

Emitted when the checked state changes.

invalid

Emitted when the form control's validity is checked and it does not meet the constraints.

Slots

Name
(default)

Text.

unchecked-icon

Icon for the unchecked state.

checked-icon

Icon for the checked state.

indeterminate-icon

Icon for the indeterminate state.

CSS Parts

Name
control

Container for the left icon.

unchecked-icon

Icon for the unchecked state.

checked-icon

Icon for the checked state.

indeterminate-icon

Icon for the indeterminate state.

label

Text.

On this page