Skip to content

Commit 6b94ddd

Browse files
asynclizcopybara-github
authored andcommitted
docs(checkbox): add documentation
PiperOrigin-RevId: 507528898
1 parent 1ddba0c commit 6b94ddd

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed

docs/components/checkbox.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Checkbox
2+
3+
<!--*
4+
# Document freshness: For more information, see go/fresh-source.
5+
freshness: { owner: 'lizmitchell' reviewed: '2023-01-25' }
6+
*-->
7+
8+
<!-- go/md-checkbox -->
9+
10+
<!-- [TOC] -->
11+
12+
[Checkboxes](https://m3.material.io/components/checkbox)<!-- {.external} --> allow users
13+
to select one or more items from a set. Checkboxes can turn an option on or off.
14+
15+
There's one type of checkbox in Material. Use this selection control when the
16+
user needs to select one or more options from a list.
17+
18+
![A list of burger additions represented with checkboxes](images/checkbox/hero.png "Checkboxes in a list of items.")
19+
20+
* [Design article](https://m3.material.io/components/checkbox) <!-- {.external} -->
21+
* API Documentation (*coming soon*)
22+
* [Source code](https://github.com/material-components/material-web/tree/master/checkbox)
23+
<!-- {.external} -->
24+
25+
## Usage
26+
27+
Checkboxes may be standalone, pre-checked, or indeterminate.
28+
29+
![Three checkboxes in a row that are unselected, selected, and indeterminate](images/checkbox/usage.png "Unselected, selected, and indeterminate checkboxes.")
30+
31+
```html
32+
<md-checkbox></md-checkbox>
33+
<md-checkbox checked></md-checkbox>
34+
<md-checkbox indeterminate></md-checkbox>
35+
```
36+
37+
### Label
38+
39+
Associate a label with a checkbox using the `<label>` element.
40+
41+
![Two checkboxes with labels](images/checkbox/usage-label.png "Labeled checkboxes.")
42+
43+
```html
44+
<label>
45+
<md-checkbox></md-checkbox>
46+
Checkbox one
47+
</label>
48+
49+
<md-checkbox id="checkbox-two"></md-checkbox>
50+
<label for="checkbox-two">Checkbox two</label>
51+
```
52+
53+
## Accessibility
54+
55+
Add an
56+
[`aria-label`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label)<!-- {.external} -->
57+
attribute to checkboxes without labels or checkboxes whose labels need to be
58+
more descriptive.
59+
60+
```html
61+
<md-checkbox aria-label="Select all checkboxes"></md-checkbox>
62+
63+
<label>
64+
<md-checkbox aria-label="Agree to terms and conditions"></md-checkbox>
65+
Agree
66+
</label>
67+
```
68+
69+
## Theming
70+
71+
Checkbox supports [Material theming](../theming.md) and can be customized in
72+
terms of color and shape.
73+
74+
### Tokens
75+
76+
Token | Default value
77+
---------------------------------------- | -----------------------------------
78+
`--md-checkbox-unselected-outline-color` | `--md-sys-color-on-surface-variant`
79+
`--md-checkbox-selected-container-color` | `--md-sys-color-primary`
80+
`--md-checkbox-selected-icon-color` | `--md-sys-color-on-primary`
81+
`--md-checkbox-container-shape` | `2px`
82+
83+
* [All tokens](https://github.com/material-components/material-web/blob/master/tokens/v0_152/_md-comp-checkbox.scss#L28-L135)
84+
<!-- {.external} -->
85+
86+
### Example
87+
88+
![Image of a checkbox with a different theme applied](images/checkbox/theming.png "Checkbox theming example.")
89+
90+
```html
91+
<style>
92+
:root {
93+
--md-sys-color-primary: #006A6A;
94+
--md-sys-color-on-primary: #FFFFFF;
95+
--md-sys-color-on-surface-variant: #3F4948;
96+
--md-checkbox-container-shape: 0px;
97+
}
98+
</style>
99+
100+
<md-checkbox></md-checkbox>
101+
<md-checkbox checked></md-checkbox>
102+
```
27.2 KB
Loading
1.11 KB
Loading
9.51 KB
Loading
1.78 KB
Loading

0 commit comments

Comments
 (0)