@spectrum-web-components/checkbox 1.11.1 → 1.11.2

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.
Files changed (2) hide show
  1. package/README.md +122 -10
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -108,9 +108,14 @@ focus to the content.
108
108
 
109
109
  <div style="display: flex; flex-direction: column;">
110
110
  <h4 class="spectrum-Heading--subtitle1">Invalid</h4>
111
- <sp-checkbox invalid>Web component</sp-checkbox>
112
- <sp-checkbox checked invalid>Web component</sp-checkbox>
113
- <sp-checkbox indeterminate invalid>Web component</sp-checkbox>
111
+ <sp-field-group vertical label="Select an option" invalid>
112
+ <sp-checkbox invalid>Web component</sp-checkbox>
113
+ <sp-checkbox checked invalid>Web component</sp-checkbox>
114
+ <sp-checkbox indeterminate invalid>Web component</sp-checkbox>
115
+ <sp-help-text slot="negative-help-text" icon>
116
+ This selection is invalid.
117
+ </sp-help-text>
118
+ </sp-field-group>
114
119
  </div>
115
120
 
116
121
  <div style="display: flex; flex-direction: column;">
@@ -141,11 +146,16 @@ of assets, etc. where the checkboxes need to be noticed.
141
146
 
142
147
  <div style="display: flex; flex-direction: column;">
143
148
  <h4 class="spectrum-Heading--subtitle1">Invalid</h4>
144
- <sp-checkbox emphasized invalid>Web component</sp-checkbox>
145
- <sp-checkbox emphasized checked invalid>Web component</sp-checkbox>
146
- <sp-checkbox emphasized indeterminate invalid>
147
- Web component
148
- </sp-checkbox>
149
+ <sp-field-group vertical label="Select an option" invalid>
150
+ <sp-checkbox emphasized invalid>Web component</sp-checkbox>
151
+ <sp-checkbox emphasized checked invalid>Web component</sp-checkbox>
152
+ <sp-checkbox emphasized indeterminate invalid>
153
+ Web component
154
+ </sp-checkbox>
155
+ <sp-help-text slot="negative-help-text" icon>
156
+ This selection is invalid.
157
+ </sp-help-text>
158
+ </sp-field-group>
149
159
  </div>
150
160
 
151
161
  <div style="display: flex; flex-direction: column;">
@@ -168,8 +178,22 @@ of assets, etc. where the checkboxes need to be noticed.
168
178
 
169
179
  The `invalid` attribute indicates that the checkbox's value is invalid. When set, appropriate ARIA attributes will be automatically applied.
170
180
 
181
+ When a checkbox is in an invalid state, provide help text to explain the error and guide the user toward a solution. Wrap the checkbox in an [`<sp-field-group>`](../field-group) to associate the help text with the checkbox. (See [help text](#help-text) for more information.)
182
+
183
+ **Important:** Both the `<sp-field-group>` and its child `<sp-checkbox>` elements must be marked as `invalid` for the complete invalid state to display correctly:
184
+
185
+ - The `invalid` attribute on `<sp-field-group>` controls help text visibility (showing the `negative-help-text` slot).
186
+ - The `invalid` attribute on each `<sp-checkbox>` controls the visual invalid styling on the checkbox itself.
187
+
188
+ Setting only one creates a sync hazard where either the help text won't display or the checkboxes won't show invalid styling.
189
+
171
190
  ```html
172
- <sp-checkbox invalid>Invalid</sp-checkbox>
191
+ <sp-field-group vertical label="Terms and conditions" invalid>
192
+ <sp-checkbox invalid>I accept the terms and conditions</sp-checkbox>
193
+ <sp-help-text slot="negative-help-text" icon>
194
+ You must accept the terms to continue.
195
+ </sp-help-text>
196
+ </sp-field-group>
173
197
  ```
174
198
 
175
199
  #### Disabled
@@ -196,6 +220,86 @@ Checkboxes have a `readonly` attribute for when they’re in the disabled state
196
220
  <sp-checkbox readonly>Read-only</sp-checkbox>
197
221
  ```
198
222
 
223
+ ### Help text
224
+
225
+ Help text can be accessibly associated with checkboxes by using the `help-text` or `negative-help-text` slots on an `<sp-field-group>` element. When using the `negative-help-text` slot, `<sp-field-group>` will self manage the presence of this content based on the value of the `invalid` property on your `<sp-field-group>` element. Content within the `help-text` slot will be shown by default. When your `<sp-field-group>` should receive help text based on state outside of the complexity of `invalid` or not, manage the content addressed to the `help-text` from above to ensure that it displays the right messaging and possesses the right `variant`.
226
+
227
+ Read more about using [help text](../help-text).
228
+
229
+ <sp-tabs selected="self" auto label="Help text usage with checkboxes">
230
+ <sp-tab value="self">Self managed</sp-tab>
231
+ <sp-tab-panel value="self">
232
+
233
+ ```html
234
+ <sp-field-group
235
+ vertical
236
+ id="self"
237
+ label="Notification preferences"
238
+ onchange="
239
+ const checkboxes = this.querySelectorAll('sp-checkbox');
240
+ const noneChecked = ![...checkboxes].some(cb => cb.checked);
241
+ this.invalid = noneChecked;
242
+ "
243
+ >
244
+ <sp-checkbox value="email">Email notifications</sp-checkbox>
245
+ <sp-checkbox value="sms">SMS notifications</sp-checkbox>
246
+ <sp-checkbox value="push" checked>Push notifications</sp-checkbox>
247
+ <sp-help-text slot="help-text">
248
+ Choose how you'd like to be notified.
249
+ </sp-help-text>
250
+ <sp-help-text slot="negative-help-text" icon>
251
+ Select at least one notification method.
252
+ </sp-help-text>
253
+ </sp-field-group>
254
+ ```
255
+
256
+ </sp-tab-panel>
257
+ <sp-tab value="above">Managed from above</sp-tab>
258
+ <sp-tab-panel value="above">
259
+
260
+ ```html
261
+ <sp-field-label for="above">Notification preferences</sp-field-label>
262
+ <sp-field-group
263
+ vertical
264
+ id="above"
265
+ onchange="
266
+ const checkboxes = this.querySelectorAll('sp-checkbox');
267
+ const noneChecked = ![...checkboxes].some(cb => cb.checked);
268
+ const helpText = this.querySelector(`[slot='help-text']`);
269
+ helpText.icon = noneChecked;
270
+ helpText.textContent = noneChecked ? 'Select at least one notification method.' : 'Choose how you\'d like to be notified.';
271
+ helpText.variant = noneChecked ? 'negative' : 'neutral';
272
+ "
273
+ >
274
+ <sp-checkbox value="email">Email notifications</sp-checkbox>
275
+ <sp-checkbox value="sms">SMS notifications</sp-checkbox>
276
+ <sp-checkbox value="push" checked>Push notifications</sp-checkbox>
277
+ <sp-help-text slot="help-text">
278
+ Choose how you'd like to be notified.
279
+ </sp-help-text>
280
+ </sp-field-group>
281
+ ```
282
+
283
+ </sp-tab-panel>
284
+ <sp-tab value="single">Single checkbox</sp-tab>
285
+ <sp-tab-panel value="single">
286
+
287
+ When a single checkbox requires validation, wrap it in an `<sp-field-group>` to associate help text:
288
+
289
+ ```html
290
+ <sp-field-group vertical label="Agreement" invalid>
291
+ <sp-checkbox invalid>
292
+ I have read and accept the terms of service
293
+ </sp-checkbox>
294
+ <sp-help-text slot="negative-help-text" icon>
295
+ You must accept the terms of service to continue.
296
+ </sp-help-text>
297
+ </sp-field-group>
298
+ ```
299
+
300
+ </sp-tab-panel>
301
+ </sp-tabs>
302
+
199
303
  ### Behaviors
200
304
 
201
305
  #### Handling events
@@ -226,7 +330,7 @@ Every checkbox must have a label that clearly describes its purpose. The label c
226
330
 
227
331
  #### Label groups of related checkboxes
228
332
 
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.)
333
+ 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
334
 
231
335
  ```html
232
336
  <sp-field-group label="Select your toppings">
@@ -236,6 +340,14 @@ Sets of checkboxes should always have a clear label that describes what the list
236
340
  </sp-field-group>
237
341
  ```
238
342
 
343
+ #### Provide help text in the correct location
344
+
345
+ Checkbox groups should use help text for error messaging and descriptions. Descriptions are valuable for giving context about a selection or for clarifying the options.
346
+
347
+ It is [not currently possible](https://w3c.github.io/webcomponents-cg/#cross-root-aria) to provide accessible ARIA references between elements in different shadow roots. To ensure proper association between elements, help text must be included via the `slot="help-text"` or `slot="negative-help-text"` on the parent `<sp-field-group>`.
348
+
349
+ See [help text](../help-text) for more information.
350
+
239
351
  #### Keyboard Navigation
240
352
 
241
353
  Checkboxes can be toggled using the <kbd>Space</kbd> key when focused. They follow the standard tab order of the page.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/checkbox",
3
- "version": "1.11.1",
3
+ "version": "1.11.2",
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.11.1",
76
- "@spectrum-web-components/icon": "1.11.1",
77
- "@spectrum-web-components/icons-ui": "1.11.1",
78
- "@spectrum-web-components/shared": "1.11.1"
75
+ "@spectrum-web-components/base": "1.11.2",
76
+ "@spectrum-web-components/icon": "1.11.2",
77
+ "@spectrum-web-components/icons-ui": "1.11.2",
78
+ "@spectrum-web-components/shared": "1.11.2"
79
79
  },
80
80
  "types": "./src/index.d.ts",
81
81
  "customElements": "custom-elements.json",