a11y-elements 0.2.0 → 0.3.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 +259 -16
- package/dist/a11y.css +200 -0
- package/dist/browser/components/anchor/define.js +13 -1
- package/dist/browser/components/anchor/define.js.map +1 -1
- package/dist/browser/components/avatar/define.js +13 -1
- package/dist/browser/components/avatar/define.js.map +1 -1
- package/dist/browser/components/checkbox/define.js +13 -1
- package/dist/browser/components/checkbox/define.js.map +1 -1
- package/dist/browser/components/checkbox-group/define.js +394 -0
- package/dist/browser/components/checkbox-group/define.js.map +1 -0
- package/dist/browser/components/file-input/define.js +1069 -0
- package/dist/browser/components/file-input/define.js.map +1 -0
- package/dist/browser/components/focusable/define.js +13 -1
- package/dist/browser/components/focusable/define.js.map +1 -1
- package/dist/browser/components/input/define.js +34 -6
- package/dist/browser/components/input/define.js.map +1 -1
- package/dist/browser/components/label/define.js +13 -1
- package/dist/browser/components/label/define.js.map +1 -1
- package/dist/browser/components/picture/define.js +171 -3
- package/dist/browser/components/picture/define.js.map +1 -1
- package/dist/browser/components/progress/define.js +13 -1
- package/dist/browser/components/progress/define.js.map +1 -1
- package/dist/browser/components/radio-group/define.js +15 -1
- package/dist/browser/components/radio-group/define.js.map +1 -1
- package/dist/browser/components/select/define.js +13 -1
- package/dist/browser/components/select/define.js.map +1 -1
- package/dist/browser/components/skeleton/define.js +13 -1
- package/dist/browser/components/skeleton/define.js.map +1 -1
- package/dist/browser/components/spinner/define.js +13 -1
- package/dist/browser/components/spinner/define.js.map +1 -1
- package/dist/browser/components/switch/define.js +13 -1
- package/dist/browser/components/switch/define.js.map +1 -1
- package/dist/browser/components/textarea/define.js +34 -6
- package/dist/browser/components/textarea/define.js.map +1 -1
- package/dist/browser/components/visually-hidden/define.js +13 -1
- package/dist/browser/components/visually-hidden/define.js.map +1 -1
- package/dist/browser/overlays/blocking-loader/define.js +13 -1
- package/dist/browser/overlays/blocking-loader/define.js.map +1 -1
- package/dist/browser/overlays/context-menu/define.js +19 -3
- package/dist/browser/overlays/context-menu/define.js.map +1 -1
- package/dist/browser/overlays/drawer/define.js +18 -2
- package/dist/browser/overlays/drawer/define.js.map +1 -1
- package/dist/browser/overlays/dropdown/define.js +19 -3
- package/dist/browser/overlays/dropdown/define.js.map +1 -1
- package/dist/browser/overlays/emergency-dialog/define.js +18 -2
- package/dist/browser/overlays/emergency-dialog/define.js.map +1 -1
- package/dist/browser/overlays/modal/define.js +18 -2
- package/dist/browser/overlays/modal/define.js.map +1 -1
- package/dist/browser/overlays/notification-banner/define.js +13 -1
- package/dist/browser/overlays/notification-banner/define.js.map +1 -1
- package/dist/browser/overlays/popover/define.js +18 -2
- package/dist/browser/overlays/popover/define.js.map +1 -1
- package/dist/browser/overlays/snackbar/define.js +13 -1
- package/dist/browser/overlays/snackbar/define.js.map +1 -1
- package/dist/browser/overlays/tooltip/define.js +18 -2
- package/dist/browser/overlays/tooltip/define.js.map +1 -1
- package/dist/components/checkbox-group/checkbox-group.element.d.ts +51 -0
- package/dist/components/checkbox-group/checkbox-group.element.js +189 -0
- package/dist/components/checkbox-group/checkbox-group.element.js.map +1 -0
- package/dist/components/checkbox-group/define.d.ts +8 -0
- package/dist/components/checkbox-group/define.js +8 -0
- package/dist/components/checkbox-group/define.js.map +1 -0
- package/dist/components/file-input/define.d.ts +9 -0
- package/dist/components/file-input/define.js +9 -0
- package/dist/components/file-input/define.js.map +1 -0
- package/dist/components/file-input/file-input.element.d.ts +95 -0
- package/dist/components/file-input/file-input.element.js +471 -0
- package/dist/components/file-input/file-input.element.js.map +1 -0
- package/dist/components/label/label.element.d.ts +1 -1
- package/dist/components/label/label.element.js +1 -1
- package/dist/components/picture/define.d.ts +1 -0
- package/dist/components/picture/define.js.map +1 -1
- package/dist/components/picture/picture.element.d.ts +72 -6
- package/dist/components/picture/picture.element.js +201 -9
- package/dist/components/picture/picture.element.js.map +1 -1
- package/dist/components/radio-group/radio-group.element.js +4 -0
- package/dist/components/radio-group/radio-group.element.js.map +1 -1
- package/dist/core/a11y-field-element.d.ts +17 -7
- package/dist/core/a11y-field-element.js +25 -5
- package/dist/core/a11y-field-element.js.map +1 -1
- package/dist/core/focus-trap.d.ts +8 -0
- package/dist/core/focus-trap.js +13 -1
- package/dist/core/focus-trap.js.map +1 -1
- package/dist/core/strings.d.ts +24 -0
- package/dist/core/strings.js +12 -0
- package/dist/core/strings.js.map +1 -1
- package/dist/overlays/core/a11y-menu-overlay-element.js +2 -2
- package/dist/overlays/core/a11y-menu-overlay-element.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@ Framework-agnostic accessibility Custom Elements (Web Components). A behavior la
|
|
|
4
4
|
|
|
5
5
|
Every element is Light DOM only (no Shadow DOM), so you always style real markup with your own CSS.
|
|
6
6
|
|
|
7
|
+
See a [demo of the elements](https://nutin.org/a11y-elements/elements) - See a [demo of the overlays](https://nutin.org/a11y-elements/overlays)
|
|
8
|
+
|
|
7
9
|
## Usage
|
|
8
10
|
|
|
9
11
|
### Zero-build
|
|
@@ -73,6 +75,16 @@ setStrings({
|
|
|
73
75
|
| `characterCount` | `{count} / {max}` | the visible text of an `<a11y-counter>` | — |
|
|
74
76
|
| `charactersRemaining` | `{count} characters remaining` | what an `<a11y-counter>` announces near the limit | — |
|
|
75
77
|
| `characterRemaining` | `{count} character remaining` | the same, with one character left | — |
|
|
78
|
+
| `selectAll` | `Select all` | the generated checkbox of `<a11y-checkbox-group select-all>` | `select-all-label` |
|
|
79
|
+
| `browseFiles` | `Browse files` | the browse button of `<a11y-file-input>` | `browse-label` |
|
|
80
|
+
| `dropFiles` | `or drop files here` | the drag & drop prompt of `<a11y-file-input>` | `drop-label` |
|
|
81
|
+
| `selectedFiles` | `Selected files` | the name of `<a11y-file-input>`'s file list | — |
|
|
82
|
+
| `remove` / `removeFile` | `Remove` / `Remove {name}` | the visible text / accessible name of each remove button of `<a11y-file-input>` | — |
|
|
83
|
+
| `fileAdded` / `filesAdded` | `{name} added` / `{count} files added` | what `<a11y-file-input>` announces after a pick or a drop | — |
|
|
84
|
+
| `fileRemoved` | `{name} removed` | what `<a11y-file-input>` announces after a removal | — |
|
|
85
|
+
| `fileTypeRejected` | `{name} wasn’t added: this type of file isn’t allowed` | a file `accept` rules out | `type-rejected-message` |
|
|
86
|
+
| `fileSizeRejected` | `{name} wasn’t added: it’s larger than {maxSize}` | a file over `max-size` | `size-rejected-message` |
|
|
87
|
+
| `fileCountRejected` | `{name} wasn’t added: too many files (maximum {max})` | a file past `max-files` | `count-rejected-message` |
|
|
76
88
|
|
|
77
89
|
* An instance attribute wins over `setStrings()`, which wins over the default. Keys you leave out keep their current value.
|
|
78
90
|
* Elements already on the page update right away, so calling it again on a language switch is enough.
|
|
@@ -80,9 +92,11 @@ setStrings({
|
|
|
80
92
|
|
|
81
93
|
## Elements
|
|
82
94
|
|
|
83
|
-
Each section shows an example, the element's own attributes/properties/methods, and its CSS variables (collapsed).
|
|
95
|
+
Each section shows an example, the element's own attributes/properties/methods, and its CSS variables (collapsed).
|
|
96
|
+
|
|
97
|
+
Behavior shared by overlays is described once, in [Common to all overlays](#common-to-all-overlays).
|
|
84
98
|
|
|
85
|
-
**Accessibility components:** [`<a11y-anchor>`](#a11y-anchor) · [`<a11y-avatar>`](#a11y-avatar) · [`<a11y-checkbox>`](#a11y-checkbox) · [`<a11y-focusable>`](#a11y-focusable) · [`<a11y-input>`](#a11y-input) · [`<a11y-label>`](#a11y-label) · [`<a11y-picture>`](#a11y-picture) · [`<a11y-progress>`](#a11y-progress) · [`<a11y-radio-group>`](#a11y-radio-group) · [`<a11y-select>`](#a11y-select) · [`<a11y-skeleton>`](#a11y-skeleton) · [`<a11y-spinner>`](#a11y-spinner) · [`<a11y-switch>`](#a11y-switch) · [`<a11y-textarea>`](#a11y-textarea) · [`<a11y-visually-hidden>`](#a11y-visually-hidden)
|
|
99
|
+
**Accessibility components:** [`<a11y-anchor>`](#a11y-anchor) · [`<a11y-avatar>`](#a11y-avatar) · [`<a11y-checkbox>`](#a11y-checkbox) · [`<a11y-checkbox-group>`](#a11y-checkbox-group) · [`<a11y-file-input>`](#a11y-file-input) · [`<a11y-focusable>`](#a11y-focusable) · [`<a11y-input>`](#a11y-input) · [`<a11y-label>`](#a11y-label) · [`<a11y-picture>`](#a11y-picture) · [`<a11y-progress>`](#a11y-progress) · [`<a11y-radio-group>`](#a11y-radio-group) · [`<a11y-select>`](#a11y-select) · [`<a11y-skeleton>`](#a11y-skeleton) · [`<a11y-spinner>`](#a11y-spinner) · [`<a11y-switch>`](#a11y-switch) · [`<a11y-textarea>`](#a11y-textarea) · [`<a11y-visually-hidden>`](#a11y-visually-hidden)
|
|
86
100
|
|
|
87
101
|
**Overlays:** [`<a11y-blocking-loader>`](#a11y-blocking-loader) · [`<a11y-context-menu>`](#a11y-context-menu) · [`<a11y-drawer>`](#a11y-drawer) · [`<a11y-dropdown>`](#a11y-dropdown) · [`<a11y-emergency-dialog>`](#a11y-emergency-dialog) · [`<a11y-modal>`](#a11y-modal) · [`<a11y-notification-banner>`](#a11y-notification-banner) · [`<a11y-popover>`](#a11y-popover) · [`<a11y-snackbar>`](#a11y-snackbar) · [`<a11y-tooltip>`](#a11y-tooltip)
|
|
88
102
|
|
|
@@ -197,6 +211,141 @@ checkbox.onChange = (checked) => console.log('accepted:', checked);
|
|
|
197
211
|
|
|
198
212
|
</details>
|
|
199
213
|
|
|
214
|
+
#### `a11y-checkbox-group`
|
|
215
|
+
|
|
216
|
+
Wraps your checkboxes in a `<fieldset>` with a `<legend>`, styled like `<a11y-checkbox>`. Add `select-all` for a "Select all" checkbox: it's checked when every option is, partly checked when some are, and checks or unchecks them all. It has no `name`, so it's never submitted, and disabled options keep their own state.
|
|
217
|
+
|
|
218
|
+
```html
|
|
219
|
+
<a11y-checkbox-group id="toppings" legend="Toppings" select-all>
|
|
220
|
+
<label><input type="checkbox" name="toppings" value="cheese"> Cheese</label>
|
|
221
|
+
<label><input type="checkbox" name="toppings" value="ham"> Ham</label>
|
|
222
|
+
</a11y-checkbox-group>
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
import 'a11y-elements/components/checkbox-group';
|
|
227
|
+
import type { CheckboxGroupElement } from 'a11y-elements/components/checkbox-group/element';
|
|
228
|
+
|
|
229
|
+
const group = document.getElementById('toppings') as CheckboxGroupElement;
|
|
230
|
+
group.onChange = (values) => console.log('toppings:', values);
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
| Name | Kind | Default | Description |
|
|
234
|
+
| --- | --- | --- | --- |
|
|
235
|
+
| `legend` | attribute | — | Visible group label. |
|
|
236
|
+
| `aria-label` | attribute | — | Group name when there's no `legend`. |
|
|
237
|
+
| `disabled` | attribute | absent | Disables every option (through the fieldset). |
|
|
238
|
+
| `select-all` | attribute | absent | Adds the "Select all" checkbox after the legend. |
|
|
239
|
+
| `select-all-label` | attribute | `Select all` | Its text; also `setStrings({ selectAll })`. |
|
|
240
|
+
| `onChange` | callback | — | `(values: string[]) => void`, called once per user action, a "Select all" click included. |
|
|
241
|
+
| `getValue()` / `setValue(values)` | method | — | Reads the checked values / checks exactly those values. |
|
|
242
|
+
| `selectAll()` / `unselectAll()` | method | — | Checks / unchecks every enabled option. Like `setValue()`, fires no events. |
|
|
243
|
+
|
|
244
|
+
A "Select all" click fires `input` and `change` on every option it changes.
|
|
245
|
+
|
|
246
|
+
Options use the `--a11y-checkbox-*` variables above.
|
|
247
|
+
|
|
248
|
+
<details>
|
|
249
|
+
<summary>CSS variables</summary>
|
|
250
|
+
|
|
251
|
+
| Variable | Default |
|
|
252
|
+
| --- | --- |
|
|
253
|
+
| `--a11y-checkbox-group-color-text-muted` | `#6b7280` |
|
|
254
|
+
| `--a11y-checkbox-group-disabled-opacity` | `0.6` |
|
|
255
|
+
| `--a11y-checkbox-group-legend-font-size` | `0.875rem` |
|
|
256
|
+
| `--a11y-checkbox-group-legend-margin-bottom` | `0.5rem` |
|
|
257
|
+
| `--a11y-checkbox-group-options-gap` | `0.5rem` |
|
|
258
|
+
| `--a11y-checkbox-group-select-all-border` | `1px solid #e5e7eb` |
|
|
259
|
+
| `--a11y-checkbox-group-select-all-padding-bottom` | `0.5rem` |
|
|
260
|
+
|
|
261
|
+
</details>
|
|
262
|
+
|
|
263
|
+
#### `a11y-file-input`
|
|
264
|
+
|
|
265
|
+
A file picker built from a real `<input type="file">`, with the same parts as [`a11y-input`](#a11y-input). Files can be browsed for or dropped onto the element. It only picks files: the input keeps its `name` and submits them with the form, or you read `getValue()` and upload them yourself.
|
|
266
|
+
|
|
267
|
+
```html
|
|
268
|
+
<a11y-file-input max-size="5MB" max-files="3" previews value-missing-message="Add at least one file">
|
|
269
|
+
<a11y-label>Attachments</a11y-label>
|
|
270
|
+
<input type="file" name="attachments" multiple accept=".pdf,image/*" required>
|
|
271
|
+
<a11y-hint>PDF or images, up to 5 MB each.</a11y-hint>
|
|
272
|
+
<a11y-error></a11y-error>
|
|
273
|
+
</a11y-file-input>
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
It adds, after the input, a drop zone with a "Browse files" button, then (after your parts) the list of selected files, the list of files that weren't added, and a status region for announcements.
|
|
277
|
+
|
|
278
|
+
**Accessibility.**
|
|
279
|
+
|
|
280
|
+
* The native input is visually hidden, not removed. It's still the control that gets focus, is announced as a file button, carries `required`, and gets the field's `aria-describedby` and `aria-invalid`. The focus ring shows on "Browse files".
|
|
281
|
+
* "Browse files" is a real `<label>` for the input, so it opens the picker without script, and its text is part of the input's accessible name (voice control users can say "click Browse files").
|
|
282
|
+
* Dragging is a shortcut, never the only way: everything works from the keyboard. The drop prompt is hidden from assistive tech.
|
|
283
|
+
* Each file has a "Remove" button named "Remove report.pdf". After a removal, focus moves to the next file's button, else the previous one, else the input.
|
|
284
|
+
* What was added, removed or not added is announced politely. Files that weren't added are also listed on screen with the reason, until the next change.
|
|
285
|
+
* Errors show with the same timing as `<a11y-input>`, plus right after a drop or a removal: removing the last file of a `required` field shows the error at once.
|
|
286
|
+
|
|
287
|
+
**Rules.** `accept` (checked on drop too, which the browser doesn't do), `max-size` and `max-files` are checked as files come in. A file that fails one is not added, so these rules never make the field invalid. `required` and `validators` still do: validators get the input as their second argument, so they can read `control.files`.
|
|
288
|
+
|
|
289
|
+
With `multiple`, browsing or dropping again adds to the selection (duplicates are skipped) instead of replacing it. Without it, the new file replaces the current one, unless it's rejected.
|
|
290
|
+
|
|
291
|
+
Style the drag-over state with `a11y-file-input:state(dragover)` or `.a11y-file-input__dropzone[data-dragover]`. The `:state(touched)`, `:state(dirty)` and `:state(user-invalid)` states work as on `<a11y-input>`.
|
|
292
|
+
|
|
293
|
+
| Name | Kind | Default | Description |
|
|
294
|
+
| --- | --- | --- | --- |
|
|
295
|
+
| `max-size` | attribute | — | Largest file accepted: `500KB`, `5MB`, `1GB` or bytes (1 KB = 1024 bytes). |
|
|
296
|
+
| `max-files` | attribute | — | Most files the selection can hold, with `multiple`. |
|
|
297
|
+
| `previews` | attribute | `false` | Shows a thumbnail next to image files. |
|
|
298
|
+
| `browse-label` / `drop-label` | attribute | see [strings](#translating-built-in-strings) | Text of the browse button / of the drop prompt. |
|
|
299
|
+
| `type-rejected-message` / `size-rejected-message` / `count-rejected-message` | attribute | see [strings](#translating-built-in-strings) | Why a file wasn't added. `{name}`, `{maxSize}` and `{max}` are filled in. |
|
|
300
|
+
| `value-missing-message`, … | attribute | browser's | As on [`a11y-input`](#a11y-input). |
|
|
301
|
+
| `validators` | property | `[]` | As on `a11y-input`; the second argument is the input. |
|
|
302
|
+
| `onChange` / `onInput` | callback | — | `(files: File[]) => void`, called once per pick, drop or removal. |
|
|
303
|
+
| `getValue()` | method | — | The selected files. |
|
|
304
|
+
| `setValue(files)` | method | — | Replaces the selection, silently: no events, no announcement. The rules still apply. |
|
|
305
|
+
| `addFiles(files)` | method | — | Adds files as a drop would: checked, announced, then `input` and `change` fire. Handy for a paste handler. |
|
|
306
|
+
| `removeFile(fileOrIndex)` / `clear()` | method | — | Removes one file / all of them, silently. |
|
|
307
|
+
| `checkValidity()` / `reportValidity()` | method | — | As on `a11y-input`. |
|
|
308
|
+
|
|
309
|
+
Sizes are formatted with `Intl` in the language of the closest `lang` attribute (`1.5 MB`, `1,5 Mo`, …).
|
|
310
|
+
|
|
311
|
+
<details>
|
|
312
|
+
<summary>CSS variables</summary>
|
|
313
|
+
|
|
314
|
+
| Variable | Default |
|
|
315
|
+
| --- | --- |
|
|
316
|
+
| `--a11y-file-input-button-border-radius` | `4px` |
|
|
317
|
+
| `--a11y-file-input-button-font-weight` | `600` |
|
|
318
|
+
| `--a11y-file-input-button-padding-x` | `1rem` |
|
|
319
|
+
| `--a11y-file-input-button-padding-y` | `0.5rem` |
|
|
320
|
+
| `--a11y-file-input-color-background` | `#ffffff` |
|
|
321
|
+
| `--a11y-file-input-color-border` | `#d1d5db` |
|
|
322
|
+
| `--a11y-file-input-color-disabled-bg` | `#e5e7eb` |
|
|
323
|
+
| `--a11y-file-input-color-disabled-text` | `#9ca3af` |
|
|
324
|
+
| `--a11y-file-input-color-dragover-bg` | `#eff6ff` |
|
|
325
|
+
| `--a11y-file-input-color-error` | `#b91c1c` |
|
|
326
|
+
| `--a11y-file-input-color-primary` | `#2563eb` |
|
|
327
|
+
| `--a11y-file-input-color-text` | `#111827` |
|
|
328
|
+
| `--a11y-file-input-color-text-muted` | `#6b7280` |
|
|
329
|
+
| `--a11y-file-input-dropzone-border-radius` | `8px` |
|
|
330
|
+
| `--a11y-file-input-dropzone-border-width` | `2px` |
|
|
331
|
+
| `--a11y-file-input-dropzone-gap` | `0.5rem` |
|
|
332
|
+
| `--a11y-file-input-dropzone-padding` | `1.5rem 1rem` |
|
|
333
|
+
| `--a11y-file-input-focus-outline-offset` | `2px` |
|
|
334
|
+
| `--a11y-file-input-focus-outline-width` | `2px` |
|
|
335
|
+
| `--a11y-file-input-gap` | `0.25rem` |
|
|
336
|
+
| `--a11y-file-input-item-border-radius` | `4px` |
|
|
337
|
+
| `--a11y-file-input-item-gap` | `0.75rem` |
|
|
338
|
+
| `--a11y-file-input-item-padding` | `0.5rem 0.75rem` |
|
|
339
|
+
| `--a11y-file-input-list-gap` | `0.5rem` |
|
|
340
|
+
| `--a11y-file-input-list-margin-top` | `0.25rem` |
|
|
341
|
+
| `--a11y-file-input-preview-border-radius` | `4px` |
|
|
342
|
+
| `--a11y-file-input-preview-size` | `2.5rem` |
|
|
343
|
+
| `--a11y-file-input-transition-duration` | `0.2s` |
|
|
344
|
+
|
|
345
|
+
The hint and error use the [shared field variables](#a11y-input).
|
|
346
|
+
|
|
347
|
+
</details>
|
|
348
|
+
|
|
200
349
|
#### `a11y-focusable`
|
|
201
350
|
|
|
202
351
|
Makes a non-button element behave like a button: `role="button"`, `tabindex="0"`, and Enter/Space fire a real `click`, so one `click` listener covers mouse and keyboard. Prefer a real `<button>` whenever you can.
|
|
@@ -233,11 +382,42 @@ A text field built from a real `<input>` and optional parts, wired together for
|
|
|
233
382
|
</form>
|
|
234
383
|
```
|
|
235
384
|
|
|
236
|
-
The input stays yours and is never regenerated.
|
|
385
|
+
The input stays yours and is never regenerated.
|
|
386
|
+
|
|
387
|
+
It keeps its `name` and submits its own value, so the form works before the script loads, and native constraints (`required`, `type`, `pattern`, `minlength`, `min`, …) do the validating.
|
|
388
|
+
|
|
389
|
+
Ids you set are kept; missing ones are generated.
|
|
390
|
+
|
|
391
|
+
- **When errors show.**
|
|
392
|
+
|
|
393
|
+
Like `:user-invalid`, a field isn't flagged while it's first being filled in.
|
|
394
|
+
|
|
395
|
+
Its error shows when it's left after an edit, or when a submit attempt finds it invalid.
|
|
237
396
|
|
|
238
|
-
|
|
397
|
+
From then on it updates as the user types, and a form reset hides it again.
|
|
239
398
|
|
|
240
|
-
|
|
399
|
+
While shown, the input has `aria-invalid="true"` and the message is in its `aria-describedby`.
|
|
400
|
+
|
|
401
|
+
- **Submitting.**
|
|
402
|
+
|
|
403
|
+
With an `<a11y-error>`, the message is shown there instead of in the browser's bubble, and the form's first invalid field is focused. Without one, the browser's bubble is left alone.
|
|
404
|
+
|
|
405
|
+
- **Why the submit button stays enabled.**
|
|
406
|
+
|
|
407
|
+
Nothing here disables your submit button while fields are invalid, and doing it yourself is best avoided.
|
|
408
|
+
|
|
409
|
+
A disabled button doesn't say what's wrong, leaves the Tab order (screen reader and keyboard users may not find it at all), is often too faint to read, and makes a form look invalid before anything has been typed.
|
|
410
|
+
|
|
411
|
+
Instead, let the submit happen: it's blocked, each error shows next to its field, and focus moves to the first invalid one.
|
|
412
|
+
|
|
413
|
+
Disabling the button *while a submission is in flight*, to prevent double submits, is a different matter and is fine as long as the busy state is announced.
|
|
414
|
+
|
|
415
|
+
**Empty fields.** Validation follows the browser's rules, which have two consequences:
|
|
416
|
+
|
|
417
|
+
* Every constraint except `required` skips an empty value. `minlength`, `pattern`, `type="email"`, `min`, … all pass on `""`, so a field without `required` is valid when empty: the form submits and no error shows. Add `required` (and `value-missing-message`) when the field must be filled.
|
|
418
|
+
* `minlength` / `maxlength` only flag a value the user typed. A value set from code (`control.value`, `setValue()`) passes them until it's edited.
|
|
419
|
+
|
|
420
|
+
`validators` do run on an empty value. To keep an optional field optional, return `null` for `""`.
|
|
241
421
|
|
|
242
422
|
**Custom rules.** `validators` run in order once the native constraints pass; the first message returned is the error. It goes through `setCustomValidity()`, so it blocks submission like a native one. Set `validators` instead of calling `setCustomValidity()` yourself, which the next validation would clear.
|
|
243
423
|
|
|
@@ -259,7 +439,7 @@ a11y-input:state(dirty) { … } /* edited at least once
|
|
|
259
439
|
|
|
260
440
|
Where `:state()` isn't supported, style `input[aria-invalid="true"]` instead.
|
|
261
441
|
|
|
262
|
-
Checkbox, radio, range, color, file, hidden and button inputs are left alone: use `<a11y-checkbox>`, `<a11y-radio-group>`, … for those.
|
|
442
|
+
Checkbox, radio, range, color, file, hidden and button inputs are left alone: use `<a11y-checkbox>`, `<a11y-checkbox-group>`, `<a11y-radio-group>`, … for those.
|
|
263
443
|
|
|
264
444
|
| Name | Kind | Default | Description |
|
|
265
445
|
| --- | --- | --- | --- |
|
|
@@ -373,7 +553,7 @@ A `*` marks a required field. It's CSS only and hidden from screen readers, whic
|
|
|
373
553
|
|
|
374
554
|
#### `a11y-picture`
|
|
375
555
|
|
|
376
|
-
Wraps a
|
|
556
|
+
Wraps a `<picture>`/`<img>` and optional `<figcaption>`, yours or generated from attributes, as `role="figure"`. An image with `alt=""` and no caption is treated as decorative and hidden from assistive tech (`aria-hidden="true"`).
|
|
377
557
|
|
|
378
558
|
```html
|
|
379
559
|
<a11y-picture>
|
|
@@ -385,7 +565,48 @@ Wraps a real `<picture>`/`<img>` and optional `<figcaption>` as `role="figure"`.
|
|
|
385
565
|
</a11y-picture>
|
|
386
566
|
```
|
|
387
567
|
|
|
388
|
-
|
|
568
|
+
**Several formats.** Instead of writing the markup, give the element a `src` (the fallback image) and it builds the `<picture>` itself: one `<source>` per format, then the `<img>`, plus a `<figcaption>` for `caption`. The browser uses the first source whose `type` it supports, else the fallback, so list the most efficient format first. A source without a `type` is always used, so give each one its type.
|
|
569
|
+
|
|
570
|
+
```html
|
|
571
|
+
<a11y-picture
|
|
572
|
+
src="s.jpg"
|
|
573
|
+
alt="S illustration"
|
|
574
|
+
sources="s.avif image/avif, s.webp image/webp"
|
|
575
|
+
caption="An illustration of S">
|
|
576
|
+
</a11y-picture>
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
The same from JavaScript, in one object:
|
|
580
|
+
|
|
581
|
+
```js
|
|
582
|
+
const base = './assets/images/s';
|
|
583
|
+
document.querySelector('a11y-picture').image = {
|
|
584
|
+
sources: [
|
|
585
|
+
{ src: `${base}.avif`, type: 'image/avif' },
|
|
586
|
+
{ src: `${base}.webp`, type: 'image/webp' },
|
|
587
|
+
],
|
|
588
|
+
fallback: `${base}.jpg`,
|
|
589
|
+
alt: 'S illustration',
|
|
590
|
+
};
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
* The `sources` attribute takes `url type` pairs. For srcset descriptors (`s.avif 1x, s@2x.avif 2x`), `media` or `sizes`, set the `sources` property in JavaScript.
|
|
594
|
+
* Use one way or the other: with a `src`, children you wrote are ignored.
|
|
595
|
+
* The same accessibility rule applies: with `alt=""` and no caption, the figure is hidden. Without any `alt`, the image is treated as decorative and a console warning asks for one.
|
|
596
|
+
|
|
597
|
+
| Name | Kind | Default | Description |
|
|
598
|
+
| --- | --- | --- | --- |
|
|
599
|
+
| `src` | attribute / property | — | The fallback image. Setting it switches to a generated picture. |
|
|
600
|
+
| `alt` | attribute / property | — | The image's text alternative; `""` for a decorative image. |
|
|
601
|
+
| `sources` | attribute | — | `url type` pairs, comma-separated: `"s.avif image/avif, s.webp image/webp"`. |
|
|
602
|
+
| `sources` | property | — | `{ src, type?, media?, sizes? }[]`; `src` can be a full srcset. Wins over the attribute until the attribute changes. |
|
|
603
|
+
| `caption` | attribute / property | — | Text of a generated `<figcaption>`. |
|
|
604
|
+
| `width` / `height` | attribute / property | — | The image's intrinsic size, to avoid layout shift. |
|
|
605
|
+
| `loading` | attribute / property | `lazy` | `lazy` or `eager`. The image is always `decoding="async"`. |
|
|
606
|
+
| `sizes` | attribute | — | `sizes` of the `<img>`. |
|
|
607
|
+
| `image` | property | — | Sets it all at once: `{ sources?, fallback, alt, caption?, width?, height?, loading? }`. |
|
|
608
|
+
|
|
609
|
+
The `PictureSource` and `PictureImage` types are exported with the element.
|
|
389
610
|
|
|
390
611
|
<details>
|
|
391
612
|
<summary>CSS variables</summary>
|
|
@@ -728,6 +949,8 @@ If the bundle loads after rendering, the same query does find it, so the result
|
|
|
728
949
|
* bind events on the overlay element itself, or delegate from it;
|
|
729
950
|
* put final text into the markup before injecting it, rather than in a pass after rendering.
|
|
730
951
|
|
|
952
|
+
<a id="dialogs"></a>
|
|
953
|
+
|
|
731
954
|
##### Dialogs (`<a11y-modal>`, `<a11y-drawer>`, `<a11y-emergency-dialog>`)
|
|
732
955
|
|
|
733
956
|
They also share:
|
|
@@ -744,6 +967,8 @@ They also share:
|
|
|
744
967
|
| `dismissible` | property (read-only) | `true` | Inverse of `non-dismissible`. |
|
|
745
968
|
| `onClose` | callback | — | Called once the close transition has finished. |
|
|
746
969
|
|
|
970
|
+
<a id="anchored-overlays"></a>
|
|
971
|
+
|
|
747
972
|
##### Anchored overlays (`<a11y-popover>`, `<a11y-tooltip>`, `<a11y-dropdown>`, `<a11y-context-menu>`)
|
|
748
973
|
|
|
749
974
|
They are positioned next to an anchor. They flip to the opposite side when there isn't room, and close on a click outside or Escape.
|
|
@@ -756,6 +981,8 @@ They are positioned next to an anchor. They flip to the opposite side when there
|
|
|
756
981
|
| `offset` | attribute | `8` | Gap to the anchor, in px. |
|
|
757
982
|
| `updatePosition()` | method | — | Recomputes the position (it already follows scroll, resize and size changes). |
|
|
758
983
|
|
|
984
|
+
<a id="menus"></a>
|
|
985
|
+
|
|
759
986
|
##### Menus (`<a11y-dropdown>`, `<a11y-context-menu>`)
|
|
760
987
|
|
|
761
988
|
Items are your own children with `role="menuitem"`. Arrow keys, Home and End move between them, and Enter/Space fire a real `click`. The menu closes after an item is clicked or when focus leaves it. Mark an item `aria-disabled="true"` to skip it.
|
|
@@ -794,6 +1021,8 @@ loader.close();
|
|
|
794
1021
|
| --- | --- | --- | --- |
|
|
795
1022
|
| `message` | attribute | — | Visible message, also the spinner's label (`Loading` without it, [translatable](#translating-built-in-strings)). |
|
|
796
1023
|
|
|
1024
|
+
See [Common to all overlays](#common-to-all-overlays) for `open`, `show()` / `close()`, the open/close events and `dismissAllOverlays()`.
|
|
1025
|
+
|
|
797
1026
|
<details>
|
|
798
1027
|
<summary>CSS variables</summary>
|
|
799
1028
|
|
|
@@ -809,7 +1038,7 @@ loader.close();
|
|
|
809
1038
|
|
|
810
1039
|
#### `a11y-context-menu`
|
|
811
1040
|
|
|
812
|
-
A menu that opens at the pointer on right-click of a trigger element, replacing the browser's own menu there. See [Menus](#
|
|
1041
|
+
A menu that opens at the pointer on right-click of a trigger element, replacing the browser's own menu there. See [Menus](#menus) and [Anchored overlays](#anchored-overlays).
|
|
813
1042
|
|
|
814
1043
|
```html
|
|
815
1044
|
<div id="canvas">Right-click me</div>
|
|
@@ -825,6 +1054,8 @@ A menu that opens at the pointer on right-click of a trigger element, replacing
|
|
|
825
1054
|
| `triggerElement` | property | — | The trigger element itself (takes precedence over `trigger`). |
|
|
826
1055
|
| `dispose()` | method | — | Detaches from the trigger for good (`close()` only hides the current menu). |
|
|
827
1056
|
|
|
1057
|
+
Also takes the shared [anchored-overlay](#anchored-overlays) options `placement` and `offset`, measured from the pointer, and `updatePosition()`; not `anchor` / `anchorElement`, since it opens where the `trigger` is right-clicked. Items follow the [menu](#menus) keyboard behavior. See [Common to all overlays](#common-to-all-overlays) for `open`, `show()` / `close()`, the open/close events and `dismissAllOverlays()`.
|
|
1058
|
+
|
|
828
1059
|
<details>
|
|
829
1060
|
<summary>CSS variables</summary>
|
|
830
1061
|
|
|
@@ -843,7 +1074,7 @@ A menu that opens at the pointer on right-click of a trigger element, replacing
|
|
|
843
1074
|
|
|
844
1075
|
#### `a11y-drawer`
|
|
845
1076
|
|
|
846
|
-
A panel that slides in from a screen edge. Behaves like `<a11y-modal>` (see [Dialogs](#
|
|
1077
|
+
A panel that slides in from a screen edge. Behaves like `<a11y-modal>` (see [Dialogs](#dialogs)).
|
|
847
1078
|
|
|
848
1079
|
```html
|
|
849
1080
|
<a11y-drawer id="filters" edge="left">
|
|
@@ -856,6 +1087,8 @@ A panel that slides in from a screen edge. Behaves like `<a11y-modal>` (see [Dia
|
|
|
856
1087
|
| --- | --- | --- | --- |
|
|
857
1088
|
| `edge` | attribute / property (read-only) | `right` | `left`, `right`, `top` or `bottom`. Read when the drawer opens. |
|
|
858
1089
|
|
|
1090
|
+
Also takes the shared [dialog](#dialogs) options: `non-dismissible`, `dialog-label`, `close-label`, `dismissible` and `onClose`. See [Common to all overlays](#common-to-all-overlays) for `open`, `show()` / `close()`, the open/close events and `dismissAllOverlays()`.
|
|
1091
|
+
|
|
859
1092
|
<details>
|
|
860
1093
|
<summary>CSS variables</summary>
|
|
861
1094
|
|
|
@@ -878,7 +1111,7 @@ The close button uses the modal's `--a11y-modal-close-button-size` and `--a11y-m
|
|
|
878
1111
|
|
|
879
1112
|
#### `a11y-dropdown`
|
|
880
1113
|
|
|
881
|
-
A menu attached to a trigger button. The anchor is the trigger: clicking it toggles the menu, and it gets `aria-haspopup`, `aria-controls` and `aria-expanded`. See [Anchored overlays and Menus](#
|
|
1114
|
+
A menu attached to a trigger button. The anchor is the trigger: clicking it toggles the menu, and it gets `aria-haspopup`, `aria-controls` and `aria-expanded`. See [Anchored overlays](#anchored-overlays) and [Menus](#menus).
|
|
882
1115
|
|
|
883
1116
|
```html
|
|
884
1117
|
<button id="actions-btn">Actions</button>
|
|
@@ -889,7 +1122,7 @@ A menu attached to a trigger button. The anchor is the trigger: clicking it togg
|
|
|
889
1122
|
</a11y-dropdown>
|
|
890
1123
|
```
|
|
891
1124
|
|
|
892
|
-
No attributes of its own
|
|
1125
|
+
No attributes of its own. It takes the shared [anchored-overlay](#anchored-overlays) options: `anchor` / `anchorElement`, `placement`, `offset` and `updatePosition()`, so e.g. `placement="top-end" offset="4"` opens it above the trigger, right-aligned, 4px away. Items follow the [menu](#menus) keyboard behavior. See [Common to all overlays](#common-to-all-overlays) for `open`, `show()` / `close()`, the open/close events and `dismissAllOverlays()`.
|
|
893
1126
|
|
|
894
1127
|
<details>
|
|
895
1128
|
<summary>CSS variables</summary>
|
|
@@ -927,7 +1160,7 @@ document.getElementById('stay').addEventListener('click', () => {
|
|
|
927
1160
|
});
|
|
928
1161
|
```
|
|
929
1162
|
|
|
930
|
-
|
|
1163
|
+
From the shared [dialog](#dialogs) options, only `dialog-label` and `onClose` apply. See [Common to all overlays](#common-to-all-overlays) for `open`, `show()` / `close()`, the open/close events and `dismissAllOverlays()`. It uses the modal's CSS variables, plus:
|
|
931
1164
|
|
|
932
1165
|
<details>
|
|
933
1166
|
<summary>CSS variables</summary>
|
|
@@ -940,7 +1173,7 @@ Only `onClose` from the [Dialogs](#common-to-all-overlays) table applies. It use
|
|
|
940
1173
|
|
|
941
1174
|
#### `a11y-modal`
|
|
942
1175
|
|
|
943
|
-
A centered dialog. Your content is its children. See [Dialogs](#
|
|
1176
|
+
A centered dialog. Your content is its children. See [Dialogs](#dialogs).
|
|
944
1177
|
|
|
945
1178
|
```html
|
|
946
1179
|
<button id="open-settings">Open settings</button>
|
|
@@ -965,6 +1198,8 @@ document.getElementById('open-settings').addEventListener('click', () => {
|
|
|
965
1198
|
| --- | --- | --- | --- |
|
|
966
1199
|
| `fullscreen` | attribute | absent | Fills the viewport, without the backdrop gutter. Read when the modal opens. |
|
|
967
1200
|
|
|
1201
|
+
Also takes the shared [dialog](#dialogs) options: `non-dismissible`, `dialog-label`, `close-label`, `dismissible` and `onClose`. See [Common to all overlays](#common-to-all-overlays) for `open`, `show()` / `close()`, the open/close events and `dismissAllOverlays()`.
|
|
1202
|
+
|
|
968
1203
|
`.a11y-modal-buttons` is an optional footer-row class for your own buttons.
|
|
969
1204
|
|
|
970
1205
|
<details>
|
|
@@ -1021,6 +1256,8 @@ window.addEventListener('popstate', () => document.getElementById('banners').dis
|
|
|
1021
1256
|
| `show(message, options)` | method | — | Shows a banner (or queues it). |
|
|
1022
1257
|
| `dismissAll()` | method | — | Closes every banner (calling their `onClose`) and drops the queued ones silently. |
|
|
1023
1258
|
|
|
1259
|
+
It's a page region, not an open/close overlay: it fires no open/close events and `dismissAllOverlays()` leaves it alone. Like every overlay it moves itself to `<body>`; see [Overlays in a framework](#overlays-in-a-framework) for `removeOverlaysWithin()`.
|
|
1260
|
+
|
|
1024
1261
|
`show()` / `showNotificationBanner()` options:
|
|
1025
1262
|
|
|
1026
1263
|
| Option | Default | Description |
|
|
@@ -1050,7 +1287,7 @@ Colors come from the shared `--a11y-color-*` tokens (see [Shared tokens](#shared
|
|
|
1050
1287
|
|
|
1051
1288
|
#### `a11y-popover`
|
|
1052
1289
|
|
|
1053
|
-
Content attached to an anchor, opened from code. With `interactive` it's a `role="dialog"` that traps focus; without it, a `role="region"`. See [Anchored overlays](#
|
|
1290
|
+
Content attached to an anchor, opened from code. With `interactive` it's a `role="dialog"` that traps focus; without it, a `role="region"`. See [Anchored overlays](#anchored-overlays).
|
|
1054
1291
|
|
|
1055
1292
|
```html
|
|
1056
1293
|
<button id="info-btn">Info</button>
|
|
@@ -1071,6 +1308,8 @@ document.getElementById('info-btn').addEventListener('click', () => {
|
|
|
1071
1308
|
| `trap-focus` | attribute | follows `interactive` | Force the focus trap on (`trap-focus`) or off (`trap-focus="false"`). |
|
|
1072
1309
|
| `onClose` | callback | — | Called once it has closed. |
|
|
1073
1310
|
|
|
1311
|
+
Also takes the shared [anchored-overlay](#anchored-overlays) options: `anchor` / `anchorElement`, `placement`, `offset` and `updatePosition()`. See [Common to all overlays](#common-to-all-overlays) for `open`, `show()` / `close()`, the open/close events and `dismissAllOverlays()`.
|
|
1312
|
+
|
|
1074
1313
|
<details>
|
|
1075
1314
|
<summary>CSS variables</summary>
|
|
1076
1315
|
|
|
@@ -1109,6 +1348,8 @@ notify('Copied to clipboard', { position: 'top', duration: 1500 });
|
|
|
1109
1348
|
| `maxStack` | property | `3` | Same as `max-stack`. `setMaxStack(n)` is an alias. |
|
|
1110
1349
|
| `notify(message, options)` | method | — | Shows a toast (or queues it). |
|
|
1111
1350
|
|
|
1351
|
+
It's a page region, not an open/close overlay: it fires no open/close events and `dismissAllOverlays()` leaves it alone. Like every overlay it moves itself to `<body>`; see [Overlays in a framework](#overlays-in-a-framework) for `removeOverlaysWithin()`.
|
|
1352
|
+
|
|
1112
1353
|
`notify()` options (method and convenience export):
|
|
1113
1354
|
|
|
1114
1355
|
| Option | Default | Description |
|
|
@@ -1143,7 +1384,7 @@ Colors come from the shared `--a11y-color-*` tokens (see [Shared tokens](#shared
|
|
|
1143
1384
|
|
|
1144
1385
|
#### `a11y-tooltip`
|
|
1145
1386
|
|
|
1146
|
-
A short description shown on hover or focus of its anchor, which gets `aria-describedby`. It stays open while the pointer is over it, and Escape hides it. Never traps focus. See [Anchored overlays](#
|
|
1387
|
+
A short description shown on hover or focus of its anchor, which gets `aria-describedby`. It stays open while the pointer is over it, and Escape hides it. Never traps focus. See [Anchored overlays](#anchored-overlays).
|
|
1147
1388
|
|
|
1148
1389
|
```html
|
|
1149
1390
|
<button id="save-btn">Save</button>
|
|
@@ -1156,6 +1397,8 @@ A short description shown on hover or focus of its anchor, which gets `aria-desc
|
|
|
1156
1397
|
| `hide-delay` | attribute / property (read-only) | `100` | Delay before hiding once pointer/focus leaves, in ms. |
|
|
1157
1398
|
| `dispose()` | method | — | Detaches from the anchor for good (`close()` only hides it). |
|
|
1158
1399
|
|
|
1400
|
+
Also takes the shared [anchored-overlay](#anchored-overlays) options: `anchor` / `anchorElement`, `placement`, `offset` and `updatePosition()`. See [Common to all overlays](#common-to-all-overlays) for `open`, `show()` / `close()`, the open/close events and `dismissAllOverlays()`.
|
|
1401
|
+
|
|
1159
1402
|
<details>
|
|
1160
1403
|
<summary>CSS variables</summary>
|
|
1161
1404
|
|