@spectrum-web-components/checkbox 1.5.1-beta.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +111 -23
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
##
|
|
1
|
+
## Overview
|
|
2
2
|
|
|
3
3
|
`<sp-checkbox>` allow users to select multiple items from a list of independent
|
|
4
4
|
options, or to mark an individual option as selected.
|
|
@@ -12,30 +12,36 @@ instead of selecting.
|
|
|
12
12
|
[](https://bundlephobia.com/result?p=@spectrum-web-components/checkbox)
|
|
13
13
|
[](https://webcomponents.dev/edit/collection/fO75441E1Q5ZlI0e9pgq/jeIGAXHMUrTp6hGMquoD/src/index.ts)
|
|
14
14
|
|
|
15
|
-
```
|
|
15
|
+
```bash
|
|
16
16
|
yarn add @spectrum-web-components/checkbox
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
Import the side effectful registration of `<sp-checkbox>` via:
|
|
20
20
|
|
|
21
|
-
```
|
|
21
|
+
```ts
|
|
22
22
|
import '@spectrum-web-components/checkbox/sp-checkbox.js';
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
When looking to leverage the `Checkbox` base class as a type and/or for extension purposes, do so via:
|
|
26
26
|
|
|
27
|
-
```
|
|
27
|
+
```ts
|
|
28
28
|
import { Checkbox } from '@spectrum-web-components/checkbox';
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
### Anatomy
|
|
32
|
+
|
|
33
|
+
A checkbox consists of a box that can be checked or unchecked, and a label that describes its purpose. The checkbox can also be in an indeterminate state, which is visually distinct from both checked and unchecked states.
|
|
34
|
+
|
|
35
|
+
### Options
|
|
36
|
+
|
|
37
|
+
#### Sizes
|
|
32
38
|
|
|
33
39
|
<sp-tabs selected="m" auto label="Size Attribute Options">
|
|
34
40
|
<sp-tab value="s">Small</sp-tab>
|
|
35
41
|
<sp-tab-panel value="s">
|
|
36
42
|
|
|
37
|
-
```html
|
|
38
|
-
<sp-field-group>
|
|
43
|
+
```html
|
|
44
|
+
<sp-field-group horizontal label="Small Checkboxes">
|
|
39
45
|
<sp-checkbox size="s">Small</sp-checkbox>
|
|
40
46
|
<sp-checkbox size="s" checked>Small Checked</sp-checkbox>
|
|
41
47
|
<sp-checkbox size="s" indeterminate>Small Indeterminate</sp-checkbox>
|
|
@@ -46,8 +52,8 @@ import { Checkbox } from '@spectrum-web-components/checkbox';
|
|
|
46
52
|
<sp-tab value="m">Medium</sp-tab>
|
|
47
53
|
<sp-tab-panel value="m">
|
|
48
54
|
|
|
49
|
-
```html
|
|
50
|
-
<sp-field-group>
|
|
55
|
+
```html
|
|
56
|
+
<sp-field-group horizontal label="Medium Checkboxes">
|
|
51
57
|
<sp-checkbox size="m">Medium</sp-checkbox>
|
|
52
58
|
<sp-checkbox size="m" checked>Medium Checked</sp-checkbox>
|
|
53
59
|
<sp-checkbox size="m" indeterminate>Medium Indeterminate</sp-checkbox>
|
|
@@ -59,7 +65,7 @@ import { Checkbox } from '@spectrum-web-components/checkbox';
|
|
|
59
65
|
<sp-tab-panel value="l">
|
|
60
66
|
|
|
61
67
|
```html demo
|
|
62
|
-
<sp-field-group>
|
|
68
|
+
<sp-field-group horizontal label="Large Checkboxes">
|
|
63
69
|
<sp-checkbox size="l">Large</sp-checkbox>
|
|
64
70
|
<sp-checkbox size="l" checked>Large Checked</sp-checkbox>
|
|
65
71
|
<sp-checkbox size="l" indeterminate>Large Indeterminate</sp-checkbox>
|
|
@@ -71,7 +77,7 @@ import { Checkbox } from '@spectrum-web-components/checkbox';
|
|
|
71
77
|
<sp-tab-panel value="xl">
|
|
72
78
|
|
|
73
79
|
```html demo
|
|
74
|
-
<sp-field-group>
|
|
80
|
+
<sp-field-group horizontal label="Extra Large Checkboxes">
|
|
75
81
|
<sp-checkbox size="xl">Extra Large</sp-checkbox>
|
|
76
82
|
<sp-checkbox size="xl" checked>Extra Large Checked</sp-checkbox>
|
|
77
83
|
<sp-checkbox size="xl" indeterminate>Extra Large Indeterminate</sp-checkbox>
|
|
@@ -81,15 +87,17 @@ import { Checkbox } from '@spectrum-web-components/checkbox';
|
|
|
81
87
|
</sp-tab-panel>
|
|
82
88
|
</sp-tabs>
|
|
83
89
|
|
|
84
|
-
|
|
90
|
+
#### Variants
|
|
85
91
|
|
|
86
|
-
|
|
92
|
+
<sp-tabs selected="standard" auto label="Checkbox Variants">
|
|
93
|
+
<sp-tab value="standard">Standard Checkboxes</sp-tab>
|
|
94
|
+
<sp-tab-panel value="standard">
|
|
87
95
|
|
|
88
96
|
Standard checkboxes are the default style for checkboxes. They are optimal for
|
|
89
97
|
application panels where all visual elements are monochrome in order to direct
|
|
90
98
|
focus to the content.
|
|
91
99
|
|
|
92
|
-
```html
|
|
100
|
+
```html
|
|
93
101
|
<div style="display: flex; justify-content: space-between;">
|
|
94
102
|
<div style="display: flex; flex-direction: column;">
|
|
95
103
|
<h4 class="spectrum-Heading--subtitle1">Default</h4>
|
|
@@ -114,15 +122,17 @@ focus to the content.
|
|
|
114
122
|
</div>
|
|
115
123
|
```
|
|
116
124
|
|
|
117
|
-
|
|
125
|
+
</sp-tab-panel>
|
|
126
|
+
<sp-tab value="emphasized">Emphasized Checkboxes</sp-tab>
|
|
127
|
+
<sp-tab-panel value="emphasized">
|
|
118
128
|
|
|
119
129
|
Emphasized checkboxes are a secondary style for checkboxes. The blue color
|
|
120
130
|
provides a visual prominence that is optimal for forms, settings, lists or grids
|
|
121
131
|
of assets, etc. where the checkboxes need to be noticed.
|
|
122
132
|
|
|
123
|
-
```html
|
|
133
|
+
```html
|
|
124
134
|
<div style="display: flex; justify-content: space-between;">
|
|
125
|
-
<div style="display: flex; flex-direction: column;
|
|
135
|
+
<div style="display: flex; flex-direction: column;">
|
|
126
136
|
<h4 class="spectrum-Heading--subtitle1">Default</h4>
|
|
127
137
|
<sp-checkbox emphasized>Web component</sp-checkbox>
|
|
128
138
|
<sp-checkbox emphasized checked>Web component</sp-checkbox>
|
|
@@ -133,32 +143,110 @@ of assets, etc. where the checkboxes need to be noticed.
|
|
|
133
143
|
<h4 class="spectrum-Heading--subtitle1">Invalid</h4>
|
|
134
144
|
<sp-checkbox emphasized invalid>Web component</sp-checkbox>
|
|
135
145
|
<sp-checkbox emphasized checked invalid>Web component</sp-checkbox>
|
|
136
|
-
<sp-checkbox emphasized indeterminate invalid>
|
|
146
|
+
<sp-checkbox emphasized indeterminate invalid>
|
|
147
|
+
Web component
|
|
148
|
+
</sp-checkbox>
|
|
137
149
|
</div>
|
|
138
150
|
|
|
139
151
|
<div style="display: flex; flex-direction: column;">
|
|
140
152
|
<h4 class="spectrum-Heading--subtitle1">Disabled</h4>
|
|
141
153
|
<sp-checkbox emphasized disabled>Web component</sp-checkbox>
|
|
142
154
|
<sp-checkbox emphasized checked disabled>Web component</sp-checkbox>
|
|
143
|
-
<sp-checkbox emphasized indeterminate disabled>
|
|
155
|
+
<sp-checkbox emphasized indeterminate disabled>
|
|
156
|
+
Web component
|
|
157
|
+
</sp-checkbox>
|
|
144
158
|
</div>
|
|
145
159
|
</div>
|
|
146
160
|
```
|
|
147
161
|
|
|
148
|
-
|
|
162
|
+
</sp-tab-panel>
|
|
163
|
+
</sp-tabs>
|
|
164
|
+
|
|
165
|
+
### States
|
|
166
|
+
|
|
167
|
+
#### Invalid
|
|
168
|
+
|
|
169
|
+
The `invalid` attribute indicates that the checkbox's value is invalid. When set, appropriate ARIA attributes will be automatically applied.
|
|
170
|
+
|
|
171
|
+
```html
|
|
172
|
+
<sp-checkbox invalid>Invalid</sp-checkbox>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### Disabled
|
|
176
|
+
|
|
177
|
+
The `disabled` attribute prevents the checkbox from receiving focus or events. The checkbox will appear faded.
|
|
178
|
+
|
|
179
|
+
```html
|
|
180
|
+
<sp-checkbox disabled>Disabled</sp-checkbox>
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
#### Indeterminate
|
|
184
|
+
|
|
185
|
+
The `indeterminate` attribute sets the checkbox to an indeterminate state, visually distinct from both checked and unchecked states.
|
|
186
|
+
|
|
187
|
+
```html
|
|
188
|
+
<sp-checkbox indeterminate>Indeterminate</sp-checkbox>
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
#### Read-only
|
|
192
|
+
|
|
193
|
+
Checkboxes have a `readonly` attribute for when they’re in the disabled state but still need their labels to be shown. This allows for content to be copied, but not interacted with or changed.
|
|
194
|
+
|
|
195
|
+
```html
|
|
196
|
+
<sp-checkbox readonly>Read-only</sp-checkbox>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Behaviors
|
|
200
|
+
|
|
201
|
+
#### Handling events
|
|
149
202
|
|
|
150
203
|
Event handlers for clicks and other user actions can be registered on an `<sp-checkbox>` as they would a standard `<input type="checkbox">` element.
|
|
151
204
|
|
|
152
205
|
```html
|
|
153
206
|
<sp-checkbox
|
|
154
207
|
id="checkbox-example"
|
|
155
|
-
onclick="spAlert(this, '<sp-
|
|
208
|
+
onclick="spAlert(this, '<sp-checkbox> clicked!')"
|
|
156
209
|
>
|
|
157
|
-
|
|
210
|
+
Check this box to see an onclick alert.
|
|
158
211
|
</sp-checkbox>
|
|
159
212
|
```
|
|
160
213
|
|
|
161
|
-
|
|
214
|
+
### Accessibility
|
|
162
215
|
|
|
163
216
|
Checkboxes are accessible by default, rendered in HTML using the `<input type="checkbox">` element. When the checkbox is set as `indeterminate` or
|
|
164
217
|
`invalid`, the appropriate ARIA state attribute will automatically be applied.
|
|
218
|
+
|
|
219
|
+
#### Include a label
|
|
220
|
+
|
|
221
|
+
Every checkbox must have a label that clearly describes its purpose. The label can be provided as content within the `<sp-checkbox>` element.
|
|
222
|
+
|
|
223
|
+
```html
|
|
224
|
+
<sp-checkbox>Send me text messages.</sp-checkbox>
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
#### Label groups of related checkboxes
|
|
228
|
+
|
|
229
|
+
Sets of checkboxes should always have a clear label that describes what the list of options represents and guides users what to do. This is important for accessibility, since a screen reader will read the label before each option. (See [field group's label documentation](/field-group/#label) for more information.)
|
|
230
|
+
|
|
231
|
+
```html
|
|
232
|
+
<sp-field-group label="Select your toppings">
|
|
233
|
+
<sp-checkbox>Ketchup</sp-checkbox>
|
|
234
|
+
<sp-checkbox>Mustard</sp-checkbox>
|
|
235
|
+
<sp-checkbox>Pickles</sp-checkbox>
|
|
236
|
+
</sp-field-group>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
#### Keyboard Navigation
|
|
240
|
+
|
|
241
|
+
Checkboxes can be toggled using the <kbd>Space</kbd> key when focused. They follow the standard tab order of the page.
|
|
242
|
+
|
|
243
|
+
#### Screen readers
|
|
244
|
+
|
|
245
|
+
Screen readers interpret checkboxes by announcing their role, label, current state, and role to the user. This allows users relying on assistive technology to understand and interact with the checkbox effectively.
|
|
246
|
+
|
|
247
|
+
When focused, a screen reader will announce:
|
|
248
|
+
|
|
249
|
+
- The label (text provided inside the or associated with it)
|
|
250
|
+
- The state: "checked", "not checked", or "partially checked" (when indeterminate is set)
|
|
251
|
+
- The role: "checkbox"
|
|
252
|
+
- If the checkbox is marked as invalid, it may also announce "invalid entry" depending on the screen reader.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/checkbox",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -72,10 +72,10 @@
|
|
|
72
72
|
"css"
|
|
73
73
|
],
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@spectrum-web-components/base": "1.
|
|
76
|
-
"@spectrum-web-components/icon": "1.
|
|
77
|
-
"@spectrum-web-components/icons-ui": "1.
|
|
78
|
-
"@spectrum-web-components/shared": "1.
|
|
75
|
+
"@spectrum-web-components/base": "1.6.0",
|
|
76
|
+
"@spectrum-web-components/icon": "1.6.0",
|
|
77
|
+
"@spectrum-web-components/icons-ui": "1.6.0",
|
|
78
|
+
"@spectrum-web-components/shared": "1.6.0"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@spectrum-css/checkbox": "10.1.2"
|