@compa11y/web 0.1.2 → 0.1.5
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/dist/compa11y.iife.js +207 -89
- package/dist/compa11y.js +1253 -994
- package/dist/components/button.d.ts +0 -1
- package/dist/components/checkbox.d.ts +0 -1
- package/dist/components/combobox.d.ts +0 -1
- package/dist/components/dialog.d.ts +0 -1
- package/dist/components/dialog.test.d.ts +0 -1
- package/dist/components/input.d.ts +0 -1
- package/dist/components/listbox.d.ts +3 -4
- package/dist/components/menu.d.ts +3 -1
- package/dist/components/menu.test.d.ts +0 -1
- package/dist/components/radio-group.d.ts +0 -1
- package/dist/components/select.d.ts +0 -1
- package/dist/components/switch.d.ts +0 -1
- package/dist/components/tabs.d.ts +5 -1
- package/dist/components/tabs.test.d.ts +0 -1
- package/dist/components/textarea.d.ts +0 -1
- package/dist/components/toast.d.ts +48 -0
- package/dist/index.d.ts +2 -2
- package/dist/utils/base-element.d.ts +0 -1
- package/dist/utils/styles.d.ts +5 -2
- package/package.json +2 -2
- package/dist/compa11y.iife.js.map +0 -1
- package/dist/compa11y.js.map +0 -1
- package/dist/compa11y.umd.cjs +0 -1633
- package/dist/compa11y.umd.cjs.map +0 -1
- package/dist/components/button.d.ts.map +0 -1
- package/dist/components/checkbox.d.ts.map +0 -1
- package/dist/components/combobox.d.ts.map +0 -1
- package/dist/components/dialog.d.ts.map +0 -1
- package/dist/components/dialog.test.d.ts.map +0 -1
- package/dist/components/input.d.ts.map +0 -1
- package/dist/components/listbox.d.ts.map +0 -1
- package/dist/components/menu.d.ts.map +0 -1
- package/dist/components/menu.test.d.ts.map +0 -1
- package/dist/components/radio-group.d.ts.map +0 -1
- package/dist/components/select.d.ts.map +0 -1
- package/dist/components/switch.d.ts.map +0 -1
- package/dist/components/tabs.d.ts.map +0 -1
- package/dist/components/tabs.test.d.ts.map +0 -1
- package/dist/components/textarea.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/utils/base-element.d.ts.map +0 -1
- package/dist/utils/styles.d.ts.map +0 -1
package/dist/compa11y.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { generateId as
|
|
2
|
-
import { KeyboardPatterns as
|
|
3
|
-
class
|
|
1
|
+
import { generateId as at, announce as v, announcePolite as p, createTypeAhead as q, announceAssertive as O, prefersDarkMode as rt, prefersHighContrast as ot, prefersReducedMotion as lt, isBrowser as nt, hasAccessibleName as ht, buildAriaProps as dt, aria as ct, KeyboardPatterns as ut, createKeyboardManager as bt, createRovingTabindex as pt, createFocusScope as mt, createFocusTrap as gt, initFocusVisible as H, announceError as vt, announceStatus as ft, initAnnouncer as B } from "@compa11y/core";
|
|
2
|
+
import { KeyboardPatterns as jt, announce as Ut, announceAssertive as Yt, announceError as Gt, announcePolite as Vt, announceStatus as Xt, aria as Wt, buildAriaProps as Jt, createFocusScope as Qt, createFocusTrap as Zt, createKeyboardManager as te, createRovingTabindex as ee, createTypeAhead as ie, hasAccessibleName as se, initAnnouncer as ae, initFocusVisible as re, isBrowser as oe, prefersDarkMode as le, prefersHighContrast as ne, prefersReducedMotion as he } from "@compa11y/core";
|
|
3
|
+
class d extends HTMLElement {
|
|
4
4
|
constructor() {
|
|
5
|
-
super(), this._internals = null, this._id =
|
|
5
|
+
super(), this._internals = null, this._id = at(this.tagName.toLowerCase().replace("a11y-", "")), "attachInternals" in this && (this._internals = this.attachInternals());
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Standard observed attributes
|
|
@@ -25,8 +25,8 @@ class c extends HTMLElement {
|
|
|
25
25
|
/**
|
|
26
26
|
* Called when observed attributes change
|
|
27
27
|
*/
|
|
28
|
-
attributeChangedCallback(
|
|
29
|
-
|
|
28
|
+
attributeChangedCallback(t, e, i) {
|
|
29
|
+
e !== i && this.onAttributeChange(t, e, i);
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Set up event listeners
|
|
@@ -41,15 +41,15 @@ class c extends HTMLElement {
|
|
|
41
41
|
/**
|
|
42
42
|
* Handle attribute changes
|
|
43
43
|
*/
|
|
44
|
-
onAttributeChange(
|
|
44
|
+
onAttributeChange(t, e, i) {
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* Emit a custom event
|
|
48
48
|
*/
|
|
49
|
-
emit(
|
|
49
|
+
emit(t, e) {
|
|
50
50
|
return this.dispatchEvent(
|
|
51
|
-
new CustomEvent(
|
|
52
|
-
detail:
|
|
51
|
+
new CustomEvent(t, {
|
|
52
|
+
detail: e,
|
|
53
53
|
bubbles: !0,
|
|
54
54
|
composed: !0,
|
|
55
55
|
cancelable: !0
|
|
@@ -59,25 +59,25 @@ class c extends HTMLElement {
|
|
|
59
59
|
/**
|
|
60
60
|
* Query a slot
|
|
61
61
|
*/
|
|
62
|
-
getSlot(
|
|
63
|
-
var
|
|
64
|
-
return ((
|
|
62
|
+
getSlot(t) {
|
|
63
|
+
var e;
|
|
64
|
+
return ((e = this.shadowRoot) == null ? void 0 : e.querySelector(`slot[name="${t}"]`)) ?? null;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Get slotted elements
|
|
68
68
|
*/
|
|
69
|
-
getSlottedElements(
|
|
69
|
+
getSlottedElements(t) {
|
|
70
70
|
var s;
|
|
71
|
-
const
|
|
72
|
-
|
|
71
|
+
const e = t ? `slot[name="${t}"]` : "slot:not([name])", i = (s = this.shadowRoot) == null ? void 0 : s.querySelector(
|
|
72
|
+
e
|
|
73
73
|
);
|
|
74
74
|
return (i == null ? void 0 : i.assignedElements()) ?? [];
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
function
|
|
78
|
-
customElements.get(n) || customElements.define(n,
|
|
77
|
+
function c(n, t) {
|
|
78
|
+
customElements.get(n) || customElements.define(n, t);
|
|
79
79
|
}
|
|
80
|
-
const
|
|
80
|
+
const T = `
|
|
81
81
|
appearance: none;
|
|
82
82
|
background: none;
|
|
83
83
|
border: none;
|
|
@@ -86,13 +86,13 @@ const H = `
|
|
|
86
86
|
font: inherit;
|
|
87
87
|
color: inherit;
|
|
88
88
|
cursor: pointer;
|
|
89
|
-
`,
|
|
89
|
+
`, _t = `
|
|
90
90
|
:host(:focus-visible),
|
|
91
91
|
:focus-visible {
|
|
92
92
|
outline: 2px solid var(--compa11y-focus-color, #0066cc);
|
|
93
93
|
outline-offset: 2px;
|
|
94
94
|
}
|
|
95
|
-
`,
|
|
95
|
+
`, u = `
|
|
96
96
|
:host {
|
|
97
97
|
display: block;
|
|
98
98
|
box-sizing: border-box;
|
|
@@ -108,9 +108,9 @@ const H = `
|
|
|
108
108
|
box-sizing: inherit;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
${
|
|
112
|
-
`,
|
|
113
|
-
${
|
|
111
|
+
${_t}
|
|
112
|
+
`, yt = `
|
|
113
|
+
${u}
|
|
114
114
|
|
|
115
115
|
:host {
|
|
116
116
|
position: fixed;
|
|
@@ -148,8 +148,8 @@ const H = `
|
|
|
148
148
|
margin: 0 0 1rem 0;
|
|
149
149
|
color: var(--compa11y-dialog-description-color, #666);
|
|
150
150
|
}
|
|
151
|
-
`,
|
|
152
|
-
${
|
|
151
|
+
`, xt = `
|
|
152
|
+
${u}
|
|
153
153
|
|
|
154
154
|
:host {
|
|
155
155
|
position: relative;
|
|
@@ -200,8 +200,8 @@ const H = `
|
|
|
200
200
|
margin: 0.25rem 0;
|
|
201
201
|
background: var(--compa11y-menu-separator-color, #e0e0e0);
|
|
202
202
|
}
|
|
203
|
-
`,
|
|
204
|
-
${
|
|
203
|
+
`, Et = `
|
|
204
|
+
${u}
|
|
205
205
|
|
|
206
206
|
.tablist {
|
|
207
207
|
display: flex;
|
|
@@ -216,7 +216,7 @@ const H = `
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
::slotted([role="tab"]) {
|
|
219
|
-
${
|
|
219
|
+
${T}
|
|
220
220
|
padding: var(--compa11y-tab-padding, 0.75rem 1rem);
|
|
221
221
|
border-bottom: 2px solid transparent;
|
|
222
222
|
margin-bottom: -1px;
|
|
@@ -246,8 +246,8 @@ const H = `
|
|
|
246
246
|
::slotted([role="tabpanel"][hidden]) {
|
|
247
247
|
display: none;
|
|
248
248
|
}
|
|
249
|
-
`,
|
|
250
|
-
${
|
|
249
|
+
`, At = `
|
|
250
|
+
${u}
|
|
251
251
|
|
|
252
252
|
:host {
|
|
253
253
|
display: inline-block;
|
|
@@ -305,7 +305,7 @@ const H = `
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
.clear-button {
|
|
308
|
-
${
|
|
308
|
+
${T}
|
|
309
309
|
position: absolute;
|
|
310
310
|
right: 1.5rem;
|
|
311
311
|
width: 1.25rem;
|
|
@@ -387,8 +387,8 @@ const H = `
|
|
|
387
387
|
.options-source {
|
|
388
388
|
display: none;
|
|
389
389
|
}
|
|
390
|
-
`,
|
|
391
|
-
${
|
|
390
|
+
`, kt = `
|
|
391
|
+
${u}
|
|
392
392
|
|
|
393
393
|
:host {
|
|
394
394
|
display: inline-block;
|
|
@@ -517,8 +517,8 @@ const H = `
|
|
|
517
517
|
.options-source {
|
|
518
518
|
display: none;
|
|
519
519
|
}
|
|
520
|
-
`,
|
|
521
|
-
${
|
|
520
|
+
`, wt = `
|
|
521
|
+
${u}
|
|
522
522
|
|
|
523
523
|
:host {
|
|
524
524
|
display: inline-block;
|
|
@@ -621,8 +621,8 @@ const H = `
|
|
|
621
621
|
opacity: 0.5;
|
|
622
622
|
cursor: not-allowed;
|
|
623
623
|
}
|
|
624
|
-
`,
|
|
625
|
-
${
|
|
624
|
+
`, $t = `
|
|
625
|
+
${u}
|
|
626
626
|
|
|
627
627
|
:host {
|
|
628
628
|
display: block;
|
|
@@ -700,8 +700,8 @@ const H = `
|
|
|
700
700
|
color: var(--compa11y-input-error-color, #ef4444);
|
|
701
701
|
font-size: var(--compa11y-input-error-size, 0.8125rem);
|
|
702
702
|
}
|
|
703
|
-
`,
|
|
704
|
-
${
|
|
703
|
+
`, Lt = `
|
|
704
|
+
${u}
|
|
705
705
|
|
|
706
706
|
:host {
|
|
707
707
|
display: block;
|
|
@@ -781,8 +781,8 @@ const H = `
|
|
|
781
781
|
color: var(--compa11y-textarea-error-color, #ef4444);
|
|
782
782
|
font-size: var(--compa11y-textarea-error-size, 0.8125rem);
|
|
783
783
|
}
|
|
784
|
-
`,
|
|
785
|
-
${
|
|
784
|
+
`, St = `
|
|
785
|
+
${u}
|
|
786
786
|
|
|
787
787
|
:host {
|
|
788
788
|
display: inline-block;
|
|
@@ -896,8 +896,8 @@ const H = `
|
|
|
896
896
|
border-radius: 50%;
|
|
897
897
|
animation: compa11y-spin 0.6s linear infinite;
|
|
898
898
|
}
|
|
899
|
-
`,
|
|
900
|
-
${
|
|
899
|
+
`, It = `
|
|
900
|
+
${u}
|
|
901
901
|
|
|
902
902
|
:host {
|
|
903
903
|
display: block;
|
|
@@ -918,9 +918,10 @@ const H = `
|
|
|
918
918
|
cursor: not-allowed;
|
|
919
919
|
}
|
|
920
920
|
|
|
921
|
+
/* Focus indicator lives on the active option (via data-focused),
|
|
922
|
+
not on the container, to avoid a double focus ring. */
|
|
921
923
|
:host(:focus-visible) .listbox-wrapper {
|
|
922
|
-
outline:
|
|
923
|
-
outline-offset: 2px;
|
|
924
|
+
outline: none;
|
|
924
925
|
}
|
|
925
926
|
|
|
926
927
|
:host([orientation="horizontal"]) .listbox-wrapper {
|
|
@@ -929,8 +930,8 @@ const H = `
|
|
|
929
930
|
max-height: none;
|
|
930
931
|
overflow-y: visible;
|
|
931
932
|
}
|
|
932
|
-
`,
|
|
933
|
-
${
|
|
933
|
+
`, Ct = `
|
|
934
|
+
${u}
|
|
934
935
|
|
|
935
936
|
:host {
|
|
936
937
|
display: block;
|
|
@@ -978,8 +979,8 @@ const H = `
|
|
|
978
979
|
:host([aria-selected="true"]) .check-mark {
|
|
979
980
|
visibility: visible;
|
|
980
981
|
}
|
|
981
|
-
`,
|
|
982
|
-
${
|
|
982
|
+
`, Tt = `
|
|
983
|
+
${u}
|
|
983
984
|
|
|
984
985
|
:host {
|
|
985
986
|
display: block;
|
|
@@ -997,8 +998,8 @@ const H = `
|
|
|
997
998
|
:host([disabled]) {
|
|
998
999
|
opacity: 0.5;
|
|
999
1000
|
}
|
|
1000
|
-
`,
|
|
1001
|
-
${
|
|
1001
|
+
`, zt = `
|
|
1002
|
+
${u}
|
|
1002
1003
|
|
|
1003
1004
|
:host {
|
|
1004
1005
|
display: inline-block;
|
|
@@ -1160,8 +1161,8 @@ const H = `
|
|
|
1160
1161
|
color: HighlightText;
|
|
1161
1162
|
}
|
|
1162
1163
|
}
|
|
1163
|
-
`,
|
|
1164
|
-
${
|
|
1164
|
+
`, Dt = `
|
|
1165
|
+
${u}
|
|
1165
1166
|
|
|
1166
1167
|
:host {
|
|
1167
1168
|
display: block;
|
|
@@ -1202,8 +1203,8 @@ const H = `
|
|
|
1202
1203
|
:host([disabled]) {
|
|
1203
1204
|
opacity: 0.5;
|
|
1204
1205
|
}
|
|
1205
|
-
`,
|
|
1206
|
-
${
|
|
1206
|
+
`, qt = `
|
|
1207
|
+
${u}
|
|
1207
1208
|
|
|
1208
1209
|
:host {
|
|
1209
1210
|
display: block;
|
|
@@ -1255,8 +1256,8 @@ const H = `
|
|
|
1255
1256
|
:host([disabled]) {
|
|
1256
1257
|
opacity: 0.5;
|
|
1257
1258
|
}
|
|
1258
|
-
`,
|
|
1259
|
-
${
|
|
1259
|
+
`, Ot = `
|
|
1260
|
+
${u}
|
|
1260
1261
|
|
|
1261
1262
|
:host {
|
|
1262
1263
|
display: inline-block;
|
|
@@ -1375,31 +1376,147 @@ const H = `
|
|
|
1375
1376
|
background: HighlightText;
|
|
1376
1377
|
}
|
|
1377
1378
|
}
|
|
1378
|
-
`,
|
|
1379
|
-
|
|
1379
|
+
`, Rt = `
|
|
1380
|
+
${u}
|
|
1381
|
+
|
|
1382
|
+
:host {
|
|
1383
|
+
position: fixed;
|
|
1384
|
+
z-index: var(--compa11y-toast-z-index, 9999);
|
|
1385
|
+
padding: var(--compa11y-toast-viewport-padding, 1rem);
|
|
1386
|
+
display: flex;
|
|
1387
|
+
flex-direction: column;
|
|
1388
|
+
gap: var(--compa11y-toast-gap, 0.5rem);
|
|
1389
|
+
pointer-events: none;
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
/* Position variants */
|
|
1393
|
+
:host([position="top-left"]) { top: 0; left: 0; }
|
|
1394
|
+
:host([position="top-center"]) { top: 0; left: 50%; transform: translateX(-50%); }
|
|
1395
|
+
:host([position="top-right"]) { top: 0; right: 0; }
|
|
1396
|
+
:host([position="bottom-left"]) { bottom: 0; left: 0; }
|
|
1397
|
+
:host(:not([position])),
|
|
1398
|
+
:host([position="bottom-right"]) { bottom: 0; right: 0; }
|
|
1399
|
+
:host([position="bottom-center"]) { bottom: 0; left: 50%; transform: translateX(-50%); }
|
|
1400
|
+
|
|
1401
|
+
.toast {
|
|
1402
|
+
pointer-events: auto;
|
|
1403
|
+
display: flex;
|
|
1404
|
+
align-items: flex-start;
|
|
1405
|
+
gap: 0.75rem;
|
|
1406
|
+
padding: var(--compa11y-toast-padding, 0.75rem 1rem);
|
|
1407
|
+
background: var(--compa11y-toast-bg, white);
|
|
1408
|
+
border: var(--compa11y-toast-border, 1px solid #e0e0e0);
|
|
1409
|
+
border-radius: var(--compa11y-toast-radius, 6px);
|
|
1410
|
+
box-shadow: var(--compa11y-toast-shadow, 0 4px 12px rgba(0, 0, 0, 0.15));
|
|
1411
|
+
min-width: var(--compa11y-toast-min-width, 250px);
|
|
1412
|
+
max-width: var(--compa11y-toast-max-width, 420px);
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
.toast[data-type="error"] {
|
|
1416
|
+
border-left: 4px solid var(--compa11y-toast-error-color, #ef4444);
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
.toast[data-type="warning"] {
|
|
1420
|
+
border-left: 4px solid var(--compa11y-toast-warning-color, #f59e0b);
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
.toast[data-type="success"] {
|
|
1424
|
+
border-left: 4px solid var(--compa11y-toast-success-color, #22c55e);
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
.toast[data-type="info"] {
|
|
1428
|
+
border-left: 4px solid var(--compa11y-toast-info-color, #3b82f6);
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
.toast-content {
|
|
1432
|
+
flex: 1;
|
|
1433
|
+
min-width: 0;
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
.toast-title {
|
|
1437
|
+
font-weight: var(--compa11y-toast-title-weight, 600);
|
|
1438
|
+
font-size: var(--compa11y-toast-title-size, 0.875rem);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
.toast-description {
|
|
1442
|
+
color: var(--compa11y-toast-description-color, #666);
|
|
1443
|
+
font-size: var(--compa11y-toast-description-size, 0.8125rem);
|
|
1444
|
+
margin-top: 0.125rem;
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
.toast-close {
|
|
1448
|
+
${T}
|
|
1449
|
+
flex-shrink: 0;
|
|
1450
|
+
width: 1.5rem;
|
|
1451
|
+
height: 1.5rem;
|
|
1452
|
+
display: flex;
|
|
1453
|
+
align-items: center;
|
|
1454
|
+
justify-content: center;
|
|
1455
|
+
border-radius: var(--compa11y-toast-close-radius, 4px);
|
|
1456
|
+
color: var(--compa11y-toast-close-color, #999);
|
|
1457
|
+
font-size: 1.125rem;
|
|
1458
|
+
line-height: 1;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
.toast-close:hover {
|
|
1462
|
+
background: var(--compa11y-toast-close-hover-bg, rgba(0, 0, 0, 0.05));
|
|
1463
|
+
color: var(--compa11y-toast-close-hover-color, #333);
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
.toast-close:focus-visible {
|
|
1467
|
+
outline: 2px solid var(--compa11y-focus-color, #0066cc);
|
|
1468
|
+
outline-offset: 2px;
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
.toast-action {
|
|
1472
|
+
${T}
|
|
1473
|
+
margin-top: 0.375rem;
|
|
1474
|
+
font-size: var(--compa11y-toast-action-size, 0.8125rem);
|
|
1475
|
+
font-weight: 500;
|
|
1476
|
+
color: var(--compa11y-toast-action-color, #0066cc);
|
|
1477
|
+
text-decoration: underline;
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
.toast-action:hover {
|
|
1481
|
+
color: var(--compa11y-toast-action-hover-color, #0052a3);
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
.toast-action:focus-visible {
|
|
1485
|
+
outline: 2px solid var(--compa11y-focus-color, #0066cc);
|
|
1486
|
+
outline-offset: 2px;
|
|
1487
|
+
}
|
|
1488
|
+
`, M = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
1489
|
+
let L = 0, K = "";
|
|
1490
|
+
function Ht() {
|
|
1491
|
+
L === 0 && (K = document.body.style.overflow, document.body.style.overflow = "hidden"), L++;
|
|
1492
|
+
}
|
|
1493
|
+
function Bt() {
|
|
1494
|
+
L--, L <= 0 && (L = 0, document.body.style.overflow = K);
|
|
1495
|
+
}
|
|
1496
|
+
class N extends d {
|
|
1380
1497
|
constructor() {
|
|
1381
1498
|
super(...arguments), this._open = !1, this._previouslyFocused = null, this._triggerElement = null, this.handleTriggerClick = () => {
|
|
1382
1499
|
this.open = !0;
|
|
1383
1500
|
}, this.handleClose = () => {
|
|
1384
1501
|
this.open = !1;
|
|
1385
|
-
}, this.handleKeyDown = (
|
|
1386
|
-
var
|
|
1502
|
+
}, this.handleKeyDown = (t) => {
|
|
1503
|
+
var e;
|
|
1387
1504
|
if (this._open) {
|
|
1388
|
-
if (
|
|
1389
|
-
this.getAttribute("close-on-escape") !== "false" && (
|
|
1505
|
+
if (t.key === "Escape") {
|
|
1506
|
+
this.getAttribute("close-on-escape") !== "false" && (t.preventDefault(), this.handleClose());
|
|
1390
1507
|
return;
|
|
1391
1508
|
}
|
|
1392
|
-
if (
|
|
1393
|
-
|
|
1509
|
+
if (t.key === "Tab") {
|
|
1510
|
+
t.preventDefault();
|
|
1394
1511
|
const i = this.getFocusableElements();
|
|
1395
1512
|
if (i.length === 0) return;
|
|
1396
|
-
const s = ((
|
|
1513
|
+
const s = ((e = this.shadowRoot) == null ? void 0 : e.activeElement) || document.activeElement;
|
|
1397
1514
|
let a = i.findIndex(
|
|
1398
1515
|
(o) => o === s
|
|
1399
1516
|
);
|
|
1400
|
-
a === -1 && (a =
|
|
1517
|
+
a === -1 && (a = t.shiftKey ? 0 : i.length - 1);
|
|
1401
1518
|
let r;
|
|
1402
|
-
|
|
1519
|
+
t.shiftKey ? r = a === 0 ? i.length - 1 : a - 1 : r = a === i.length - 1 ? 0 : a + 1;
|
|
1403
1520
|
const l = i[r];
|
|
1404
1521
|
l && l.focus();
|
|
1405
1522
|
}
|
|
@@ -1412,26 +1529,26 @@ class M extends c {
|
|
|
1412
1529
|
get open() {
|
|
1413
1530
|
return this._open;
|
|
1414
1531
|
}
|
|
1415
|
-
set open(
|
|
1416
|
-
const
|
|
1417
|
-
this._open =
|
|
1532
|
+
set open(t) {
|
|
1533
|
+
const e = this._open;
|
|
1534
|
+
this._open = t, t !== e && (t ? this.showDialog() : this.hideDialog()), this.toggleAttribute("open", t);
|
|
1418
1535
|
}
|
|
1419
1536
|
setupAccessibility() {
|
|
1420
1537
|
}
|
|
1421
1538
|
render() {
|
|
1422
|
-
const
|
|
1423
|
-
|
|
1424
|
-
<style>${
|
|
1539
|
+
const t = this.attachShadow({ mode: "open" }), e = `${this._id}-title`, i = `${this._id}-desc`;
|
|
1540
|
+
t.innerHTML = `
|
|
1541
|
+
<style>${yt}</style>
|
|
1425
1542
|
<div class="overlay" part="overlay"></div>
|
|
1426
1543
|
<div
|
|
1427
1544
|
class="dialog"
|
|
1428
1545
|
role="dialog"
|
|
1429
1546
|
aria-modal="true"
|
|
1430
|
-
aria-labelledby="${
|
|
1547
|
+
aria-labelledby="${e}"
|
|
1431
1548
|
aria-describedby="${i}"
|
|
1432
1549
|
part="dialog"
|
|
1433
1550
|
>
|
|
1434
|
-
<div id="${
|
|
1551
|
+
<div id="${e}" part="title">
|
|
1435
1552
|
<slot name="title"></slot>
|
|
1436
1553
|
</div>
|
|
1437
1554
|
<div id="${i}" part="description">
|
|
@@ -1448,10 +1565,10 @@ class M extends c {
|
|
|
1448
1565
|
}
|
|
1449
1566
|
setupEventListeners() {
|
|
1450
1567
|
var i;
|
|
1451
|
-
const
|
|
1452
|
-
if (
|
|
1568
|
+
const t = this.getAttribute("trigger");
|
|
1569
|
+
if (t) {
|
|
1453
1570
|
const s = () => {
|
|
1454
|
-
this._triggerElement = document.querySelector(
|
|
1571
|
+
this._triggerElement = document.querySelector(t), this._triggerElement && (this._triggerElement.addEventListener(
|
|
1455
1572
|
"click",
|
|
1456
1573
|
this.handleTriggerClick
|
|
1457
1574
|
), this._triggerElement.hasAttribute("tabindex") || this._triggerElement.setAttribute("tabindex", "0"));
|
|
@@ -1460,15 +1577,15 @@ class M extends c {
|
|
|
1460
1577
|
s(), this._triggerElement || setTimeout(s, 0);
|
|
1461
1578
|
});
|
|
1462
1579
|
}
|
|
1463
|
-
const
|
|
1464
|
-
this.getAttribute("close-on-outside-click") !== "false" && (
|
|
1580
|
+
const e = (i = this.shadowRoot) == null ? void 0 : i.querySelector(".overlay");
|
|
1581
|
+
this.getAttribute("close-on-outside-click") !== "false" && (e == null || e.addEventListener("click", this.handleClose)), this.addEventListener("keydown", this.handleKeyDown);
|
|
1465
1582
|
}
|
|
1466
1583
|
cleanupEventListeners() {
|
|
1467
|
-
var
|
|
1468
|
-
(
|
|
1584
|
+
var t;
|
|
1585
|
+
(t = this._triggerElement) == null || t.removeEventListener("click", this.handleTriggerClick), this.removeEventListener("keydown", this.handleKeyDown);
|
|
1469
1586
|
}
|
|
1470
|
-
onAttributeChange(
|
|
1471
|
-
|
|
1587
|
+
onAttributeChange(t, e, i) {
|
|
1588
|
+
t === "open" && (this.open = i !== null);
|
|
1472
1589
|
}
|
|
1473
1590
|
/**
|
|
1474
1591
|
* Get all focusable elements in the dialog (light DOM first, then shadow DOM)
|
|
@@ -1476,20 +1593,20 @@ class M extends c {
|
|
|
1476
1593
|
* close button should be last in tab order
|
|
1477
1594
|
*/
|
|
1478
1595
|
getFocusableElements() {
|
|
1479
|
-
const
|
|
1480
|
-
return this.querySelectorAll(
|
|
1481
|
-
s.classList.contains("overlay") ||
|
|
1482
|
-
}),
|
|
1596
|
+
const t = [];
|
|
1597
|
+
return this.querySelectorAll(M).forEach((i) => t.push(i)), this.shadowRoot && this.shadowRoot.querySelectorAll(M).forEach((s) => {
|
|
1598
|
+
s.classList.contains("overlay") || t.push(s);
|
|
1599
|
+
}), t;
|
|
1483
1600
|
}
|
|
1484
1601
|
showDialog() {
|
|
1485
1602
|
this._previouslyFocused = document.activeElement, this.style.display = "flex", requestAnimationFrame(() => {
|
|
1486
|
-
const
|
|
1487
|
-
|
|
1488
|
-
}),
|
|
1603
|
+
const e = this.getFocusableElements()[0];
|
|
1604
|
+
e && e.focus();
|
|
1605
|
+
}), Ht(), v("Dialog opened", { politeness: "polite" }), this.emit("a11y-dialog-open");
|
|
1489
1606
|
}
|
|
1490
1607
|
hideDialog() {
|
|
1491
|
-
var
|
|
1492
|
-
this.style.display = "none",
|
|
1608
|
+
var t;
|
|
1609
|
+
this.style.display = "none", Bt(), (t = this._previouslyFocused) == null || t.focus(), this._previouslyFocused = null, v("Dialog closed", { politeness: "polite" }), this.emit("a11y-dialog-close");
|
|
1493
1610
|
}
|
|
1494
1611
|
/**
|
|
1495
1612
|
* Programmatic open
|
|
@@ -1504,78 +1621,78 @@ class M extends c {
|
|
|
1504
1621
|
this.open = !1;
|
|
1505
1622
|
}
|
|
1506
1623
|
}
|
|
1507
|
-
|
|
1508
|
-
class
|
|
1624
|
+
c("a11y-dialog", N);
|
|
1625
|
+
class F extends d {
|
|
1509
1626
|
constructor() {
|
|
1510
|
-
super(...arguments), this._open = !1, this._highlightedIndex = -1, this._menuItems = [], this.updateMenuItems = () => {
|
|
1627
|
+
super(...arguments), this._open = !1, this._highlightedIndex = -1, this._menuItems = [], this._triggerEl = null, this._triggerSlotEl = null, this._defaultSlotEl = null, this.updateMenuItems = () => {
|
|
1511
1628
|
this._menuItems = Array.from(
|
|
1512
1629
|
this.querySelectorAll('[role="menuitem"]:not([aria-disabled="true"])')
|
|
1513
|
-
), this._menuItems.forEach((
|
|
1514
|
-
|
|
1630
|
+
), this._menuItems.forEach((t, e) => {
|
|
1631
|
+
t.id = t.id || `${this._id}-item-${e}`, t.setAttribute("tabindex", "-1");
|
|
1515
1632
|
});
|
|
1516
1633
|
}, this._lastClickTime = 0, this.handleTriggerClick = () => {
|
|
1517
|
-
const
|
|
1518
|
-
|
|
1519
|
-
}, this.handleTriggerKeyDown = (
|
|
1520
|
-
switch (
|
|
1634
|
+
const t = Date.now();
|
|
1635
|
+
t - this._lastClickTime < 50 || (this._lastClickTime = t, this.toggle());
|
|
1636
|
+
}, this.handleTriggerKeyDown = (t) => {
|
|
1637
|
+
switch (t.key) {
|
|
1521
1638
|
case "Enter":
|
|
1522
1639
|
case " ":
|
|
1523
|
-
|
|
1640
|
+
t.preventDefault(), this.toggle(), this._open && this.highlightItem(0);
|
|
1524
1641
|
break;
|
|
1525
1642
|
case "ArrowDown":
|
|
1526
|
-
|
|
1643
|
+
t.preventDefault(), this._open || this.show(), this.highlightItem(0);
|
|
1527
1644
|
break;
|
|
1528
1645
|
case "ArrowUp":
|
|
1529
|
-
|
|
1646
|
+
t.preventDefault(), this._open || this.show(), this.highlightItem(this._menuItems.length - 1);
|
|
1530
1647
|
break;
|
|
1531
1648
|
}
|
|
1532
|
-
}, this.handleMenuKeyDown = (
|
|
1649
|
+
}, this.handleMenuKeyDown = (t) => {
|
|
1533
1650
|
if (!this._open) return;
|
|
1534
|
-
const
|
|
1535
|
-
if (!(!
|
|
1536
|
-
switch (
|
|
1651
|
+
const e = t.target;
|
|
1652
|
+
if (!(!e.hasAttribute("role") || e.getAttribute("role") !== "menuitem"))
|
|
1653
|
+
switch (t.key) {
|
|
1537
1654
|
case "ArrowDown":
|
|
1538
|
-
|
|
1655
|
+
t.preventDefault(), this.highlightItem(
|
|
1539
1656
|
(this._highlightedIndex + 1) % this._menuItems.length
|
|
1540
1657
|
);
|
|
1541
1658
|
break;
|
|
1542
1659
|
case "ArrowUp":
|
|
1543
|
-
|
|
1660
|
+
t.preventDefault(), this.highlightItem(
|
|
1544
1661
|
(this._highlightedIndex - 1 + this._menuItems.length) % this._menuItems.length
|
|
1545
1662
|
);
|
|
1546
1663
|
break;
|
|
1547
1664
|
case "Home":
|
|
1548
|
-
|
|
1665
|
+
t.preventDefault(), this.highlightItem(0);
|
|
1549
1666
|
break;
|
|
1550
1667
|
case "End":
|
|
1551
|
-
|
|
1668
|
+
t.preventDefault(), this.highlightItem(this._menuItems.length - 1);
|
|
1552
1669
|
break;
|
|
1553
1670
|
case "Enter":
|
|
1554
1671
|
case " ":
|
|
1555
|
-
|
|
1672
|
+
t.preventDefault(), this.selectItem(this._highlightedIndex);
|
|
1556
1673
|
break;
|
|
1557
1674
|
case "Escape":
|
|
1558
|
-
|
|
1675
|
+
t.preventDefault(), this.close();
|
|
1559
1676
|
break;
|
|
1560
1677
|
case "Tab":
|
|
1561
1678
|
this.close();
|
|
1562
1679
|
break;
|
|
1563
1680
|
}
|
|
1564
|
-
}, this.handleItemClick = (
|
|
1565
|
-
const
|
|
1566
|
-
if (
|
|
1567
|
-
const i = this._menuItems.indexOf(
|
|
1681
|
+
}, this.handleItemClick = (t) => {
|
|
1682
|
+
const e = t.target;
|
|
1683
|
+
if (e.getAttribute("role") === "menuitem" && e.getAttribute("aria-disabled") !== "true") {
|
|
1684
|
+
const i = this._menuItems.indexOf(e);
|
|
1568
1685
|
this.selectItem(i);
|
|
1569
1686
|
}
|
|
1570
|
-
}, this.handleMouseOver = (
|
|
1571
|
-
const
|
|
1572
|
-
if (
|
|
1573
|
-
const i = this._menuItems.indexOf(
|
|
1687
|
+
}, this.handleMouseOver = (t) => {
|
|
1688
|
+
const e = t.target;
|
|
1689
|
+
if (e.getAttribute("role") === "menuitem") {
|
|
1690
|
+
const i = this._menuItems.indexOf(e);
|
|
1574
1691
|
i !== -1 && this.highlightItem(i, !1);
|
|
1575
1692
|
}
|
|
1576
|
-
}, this.handleOutsideClick = (
|
|
1693
|
+
}, this.handleOutsideClick = (t) => {
|
|
1577
1694
|
if (!this._open) return;
|
|
1578
|
-
|
|
1695
|
+
t.composedPath().includes(this) || this.close();
|
|
1579
1696
|
};
|
|
1580
1697
|
}
|
|
1581
1698
|
static get observedAttributes() {
|
|
@@ -1584,18 +1701,18 @@ class K extends c {
|
|
|
1584
1701
|
get open() {
|
|
1585
1702
|
return this._open;
|
|
1586
1703
|
}
|
|
1587
|
-
set open(
|
|
1588
|
-
const
|
|
1589
|
-
this._open =
|
|
1704
|
+
set open(t) {
|
|
1705
|
+
const e = this._open;
|
|
1706
|
+
this._open = t, t !== e && this.updateMenuVisibility(), this.toggleAttribute("open", t);
|
|
1590
1707
|
}
|
|
1591
1708
|
setupAccessibility() {
|
|
1592
|
-
const
|
|
1593
|
-
|
|
1709
|
+
const t = this.querySelector('[slot="trigger"]');
|
|
1710
|
+
t && (t.setAttribute("aria-haspopup", "menu"), t.setAttribute("aria-expanded", String(this._open)), t.id = t.id || `${this._id}-trigger`, t.hasAttribute("tabindex") || t.setAttribute("tabindex", "0"));
|
|
1594
1711
|
}
|
|
1595
1712
|
render() {
|
|
1596
|
-
const
|
|
1597
|
-
|
|
1598
|
-
<style>${
|
|
1713
|
+
const t = this.attachShadow({ mode: "open" });
|
|
1714
|
+
t.innerHTML = `
|
|
1715
|
+
<style>${xt}</style>
|
|
1599
1716
|
<slot name="trigger"></slot>
|
|
1600
1717
|
<div
|
|
1601
1718
|
class="menu-content"
|
|
@@ -1610,47 +1727,46 @@ class K extends c {
|
|
|
1610
1727
|
`;
|
|
1611
1728
|
}
|
|
1612
1729
|
setupEventListeners() {
|
|
1613
|
-
var s, a;
|
|
1614
|
-
|
|
1615
|
-
e == null || e.addEventListener("click", this.handleTriggerClick), e == null || e.addEventListener(
|
|
1730
|
+
var t, e, i, s, a, r;
|
|
1731
|
+
this._triggerEl = this.querySelector('[slot="trigger"]'), (t = this._triggerEl) == null || t.addEventListener("click", this.handleTriggerClick), (e = this._triggerEl) == null || e.addEventListener(
|
|
1616
1732
|
"keydown",
|
|
1617
1733
|
this.handleTriggerKeyDown
|
|
1618
|
-
);
|
|
1619
|
-
const t = (s = this.shadowRoot) == null ? void 0 : s.querySelector('slot[name="trigger"]');
|
|
1620
|
-
t == null || t.addEventListener("click", this.handleTriggerClick), this.addEventListener("click", this.handleItemClick), this.addEventListener("keydown", this.handleMenuKeyDown), this.addEventListener("mouseover", this.handleMouseOver), document.addEventListener("mousedown", this.handleOutsideClick);
|
|
1621
|
-
const i = (a = this.shadowRoot) == null ? void 0 : a.querySelector("slot:not([name])");
|
|
1622
|
-
i == null || i.addEventListener("slotchange", this.updateMenuItems), this.updateMenuItems();
|
|
1734
|
+
), this._triggerSlotEl = ((i = this.shadowRoot) == null ? void 0 : i.querySelector('slot[name="trigger"]')) ?? null, (s = this._triggerSlotEl) == null || s.addEventListener("click", this.handleTriggerClick), this.addEventListener("click", this.handleItemClick), this.addEventListener("keydown", this.handleMenuKeyDown), this.addEventListener("mouseover", this.handleMouseOver), document.addEventListener("mousedown", this.handleOutsideClick), this._defaultSlotEl = ((a = this.shadowRoot) == null ? void 0 : a.querySelector("slot:not([name])")) ?? null, (r = this._defaultSlotEl) == null || r.addEventListener("slotchange", this.updateMenuItems), this.updateMenuItems();
|
|
1623
1735
|
}
|
|
1624
1736
|
cleanupEventListeners() {
|
|
1625
|
-
|
|
1737
|
+
var t, e, i, s;
|
|
1738
|
+
(t = this._triggerEl) == null || t.removeEventListener("click", this.handleTriggerClick), (e = this._triggerEl) == null || e.removeEventListener(
|
|
1739
|
+
"keydown",
|
|
1740
|
+
this.handleTriggerKeyDown
|
|
1741
|
+
), (i = this._triggerSlotEl) == null || i.removeEventListener("click", this.handleTriggerClick), this.removeEventListener("click", this.handleItemClick), this.removeEventListener("keydown", this.handleMenuKeyDown), this.removeEventListener("mouseover", this.handleMouseOver), document.removeEventListener("mousedown", this.handleOutsideClick), (s = this._defaultSlotEl) == null || s.removeEventListener("slotchange", this.updateMenuItems);
|
|
1626
1742
|
}
|
|
1627
|
-
onAttributeChange(
|
|
1628
|
-
|
|
1743
|
+
onAttributeChange(t, e, i) {
|
|
1744
|
+
t === "open" && (this.open = i !== null);
|
|
1629
1745
|
}
|
|
1630
|
-
highlightItem(
|
|
1746
|
+
highlightItem(t, e = !0) {
|
|
1631
1747
|
var s;
|
|
1632
1748
|
if (this._highlightedIndex >= 0) {
|
|
1633
1749
|
const a = this._menuItems[this._highlightedIndex];
|
|
1634
1750
|
a == null || a.removeAttribute("data-highlighted");
|
|
1635
1751
|
}
|
|
1636
|
-
this._highlightedIndex =
|
|
1637
|
-
const i = this._menuItems[
|
|
1752
|
+
this._highlightedIndex = t;
|
|
1753
|
+
const i = this._menuItems[t];
|
|
1638
1754
|
if (i) {
|
|
1639
|
-
i.setAttribute("data-highlighted", "true"),
|
|
1755
|
+
i.setAttribute("data-highlighted", "true"), e && i.focus();
|
|
1640
1756
|
const a = (s = this.shadowRoot) == null ? void 0 : s.querySelector('[role="menu"]');
|
|
1641
1757
|
a == null || a.setAttribute("aria-activedescendant", i.id);
|
|
1642
1758
|
}
|
|
1643
1759
|
}
|
|
1644
|
-
selectItem(
|
|
1645
|
-
const
|
|
1646
|
-
|
|
1760
|
+
selectItem(t) {
|
|
1761
|
+
const e = this._menuItems[t];
|
|
1762
|
+
e && (this.emit("a11y-menu-select", { item: e, index: t }), e.click()), this.close();
|
|
1647
1763
|
}
|
|
1648
1764
|
updateMenuVisibility() {
|
|
1649
1765
|
var i;
|
|
1650
|
-
const
|
|
1651
|
-
this._open ? (
|
|
1766
|
+
const t = (i = this.shadowRoot) == null ? void 0 : i.querySelector(".menu-content"), e = this.querySelector('[slot="trigger"]');
|
|
1767
|
+
this._open ? (t == null || t.removeAttribute("hidden"), e == null || e.setAttribute("aria-expanded", "true"), this.updateMenuItems(), this.emit("a11y-menu-open")) : (t == null || t.setAttribute("hidden", ""), e == null || e.setAttribute("aria-expanded", "false"), this._highlightedIndex = -1, this._menuItems.forEach((s) => {
|
|
1652
1768
|
s.removeAttribute("data-highlighted");
|
|
1653
|
-
}),
|
|
1769
|
+
}), e == null || e.focus(), this.emit("a11y-menu-close"));
|
|
1654
1770
|
}
|
|
1655
1771
|
/**
|
|
1656
1772
|
* Show the menu
|
|
@@ -1671,46 +1787,50 @@ class K extends c {
|
|
|
1671
1787
|
this.open = !this._open;
|
|
1672
1788
|
}
|
|
1673
1789
|
}
|
|
1674
|
-
|
|
1675
|
-
class
|
|
1790
|
+
c("a11y-menu", F);
|
|
1791
|
+
class P extends d {
|
|
1676
1792
|
constructor() {
|
|
1677
|
-
super(...arguments), this._tabs = [], this._panels = [], this._selectedIndex = 0, this.updateTabsAndPanels = () => {
|
|
1793
|
+
super(...arguments), this._tabs = [], this._panels = [], this._selectedIndex = 0, this._focusedIndex = 0, this._tabSlotEl = null, this._panelSlotEl = null, this._defaultSlotEl = null, this.updateTabsAndPanels = () => {
|
|
1678
1794
|
this._tabs = Array.from(
|
|
1679
1795
|
this.querySelectorAll('[role="tab"]')
|
|
1680
1796
|
), this._panels = Array.from(
|
|
1681
1797
|
this.querySelectorAll('[role="tabpanel"]')
|
|
1682
|
-
), this._tabs.forEach((
|
|
1683
|
-
const i = this._panels[
|
|
1684
|
-
|
|
1798
|
+
), this._tabs.forEach((t, e) => {
|
|
1799
|
+
const i = this._panels[e], s = t.id || `${this._id}-tab-${e}`, a = (i == null ? void 0 : i.id) || `${this._id}-panel-${e}`;
|
|
1800
|
+
t.id = s, t.setAttribute("aria-controls", a), t.setAttribute("tabindex", e === this._selectedIndex ? "0" : "-1"), t.setAttribute("aria-selected", String(e === this._selectedIndex)), t.hasAttribute("slot") || t.setAttribute("slot", "tab"), i && (i.id = a, i.setAttribute("aria-labelledby", s), i.setAttribute("tabindex", "0"), i.hidden = e !== this._selectedIndex, i.hasAttribute("slot") || i.setAttribute("slot", "panel"));
|
|
1685
1801
|
}), this.updateSelection();
|
|
1686
|
-
}, this.handleClick = (
|
|
1687
|
-
const
|
|
1688
|
-
if (
|
|
1689
|
-
const i = this._tabs.indexOf(
|
|
1690
|
-
i !== -1 &&
|
|
1802
|
+
}, this.handleClick = (t) => {
|
|
1803
|
+
const e = t.target;
|
|
1804
|
+
if (e.getAttribute("role") === "tab") {
|
|
1805
|
+
const i = this._tabs.indexOf(e);
|
|
1806
|
+
i !== -1 && e.getAttribute("aria-disabled") !== "true" && (this._focusedIndex = i, this.selectTab(i));
|
|
1691
1807
|
}
|
|
1692
|
-
}, this.handleKeyDown = (
|
|
1808
|
+
}, this.handleKeyDown = (t) => {
|
|
1693
1809
|
var l;
|
|
1694
|
-
if (
|
|
1810
|
+
if (t.target.getAttribute("role") !== "tab") return;
|
|
1695
1811
|
const i = this.orientation === "horizontal", s = i ? "ArrowRight" : "ArrowDown", a = i ? "ArrowLeft" : "ArrowUp";
|
|
1696
|
-
let r = this.
|
|
1697
|
-
switch (
|
|
1812
|
+
let r = this._focusedIndex;
|
|
1813
|
+
switch (t.key) {
|
|
1698
1814
|
case s:
|
|
1699
|
-
|
|
1815
|
+
t.preventDefault(), r = (this._focusedIndex + 1) % this._tabs.length;
|
|
1700
1816
|
break;
|
|
1701
1817
|
case a:
|
|
1702
|
-
|
|
1818
|
+
t.preventDefault(), r = (this._focusedIndex - 1 + this._tabs.length) % this._tabs.length;
|
|
1703
1819
|
break;
|
|
1704
1820
|
case "Home":
|
|
1705
|
-
|
|
1821
|
+
t.preventDefault(), r = 0;
|
|
1706
1822
|
break;
|
|
1707
1823
|
case "End":
|
|
1708
|
-
|
|
1824
|
+
t.preventDefault(), r = this._tabs.length - 1;
|
|
1709
1825
|
break;
|
|
1826
|
+
case "Enter":
|
|
1827
|
+
case " ":
|
|
1828
|
+
t.preventDefault(), this.selectTab(this._focusedIndex);
|
|
1829
|
+
return;
|
|
1710
1830
|
default:
|
|
1711
1831
|
return;
|
|
1712
1832
|
}
|
|
1713
|
-
(l = this._tabs[r]) == null || l.focus(), this.activationMode === "automatic" && this.selectTab(r);
|
|
1833
|
+
this._focusedIndex = r, (l = this._tabs[r]) == null || l.focus(), this.activationMode === "automatic" && this.selectTab(r);
|
|
1714
1834
|
};
|
|
1715
1835
|
}
|
|
1716
1836
|
static get observedAttributes() {
|
|
@@ -1719,8 +1839,8 @@ class F extends c {
|
|
|
1719
1839
|
get selectedIndex() {
|
|
1720
1840
|
return this._selectedIndex;
|
|
1721
1841
|
}
|
|
1722
|
-
set selectedIndex(
|
|
1723
|
-
|
|
1842
|
+
set selectedIndex(t) {
|
|
1843
|
+
t >= 0 && t < this._tabs.length && (this._selectedIndex = t, this.updateSelection());
|
|
1724
1844
|
}
|
|
1725
1845
|
get orientation() {
|
|
1726
1846
|
return this.getAttribute("orientation") || "horizontal";
|
|
@@ -1732,9 +1852,9 @@ class F extends c {
|
|
|
1732
1852
|
this.updateTabsAndPanels();
|
|
1733
1853
|
}
|
|
1734
1854
|
render() {
|
|
1735
|
-
const
|
|
1736
|
-
|
|
1737
|
-
<style>${
|
|
1855
|
+
const t = this.attachShadow({ mode: "open" });
|
|
1856
|
+
t.innerHTML = `
|
|
1857
|
+
<style>${Et}</style>
|
|
1738
1858
|
<div class="tablist" role="tablist" aria-orientation="${this.orientation}" part="tablist">
|
|
1739
1859
|
<slot name="tab"></slot>
|
|
1740
1860
|
</div>
|
|
@@ -1745,43 +1865,45 @@ class F extends c {
|
|
|
1745
1865
|
`;
|
|
1746
1866
|
}
|
|
1747
1867
|
setupEventListeners() {
|
|
1748
|
-
var s, a, r;
|
|
1749
|
-
this.addEventListener("click", this.handleClick), this.addEventListener("keydown", this.handleKeyDown);
|
|
1750
|
-
const e = (s = this.shadowRoot) == null ? void 0 : s.querySelector('slot[name="tab"]'), t = (a = this.shadowRoot) == null ? void 0 : a.querySelector('slot[name="panel"]'), i = (r = this.shadowRoot) == null ? void 0 : r.querySelector("slot:not([name])");
|
|
1751
|
-
e == null || e.addEventListener("slotchange", this.updateTabsAndPanels), t == null || t.addEventListener("slotchange", this.updateTabsAndPanels), i == null || i.addEventListener("slotchange", this.updateTabsAndPanels);
|
|
1868
|
+
var t, e, i, s, a, r;
|
|
1869
|
+
this.addEventListener("click", this.handleClick), this.addEventListener("keydown", this.handleKeyDown), this._tabSlotEl = ((t = this.shadowRoot) == null ? void 0 : t.querySelector('slot[name="tab"]')) ?? null, this._panelSlotEl = ((e = this.shadowRoot) == null ? void 0 : e.querySelector('slot[name="panel"]')) ?? null, this._defaultSlotEl = ((i = this.shadowRoot) == null ? void 0 : i.querySelector("slot:not([name])")) ?? null, (s = this._tabSlotEl) == null || s.addEventListener("slotchange", this.updateTabsAndPanels), (a = this._panelSlotEl) == null || a.addEventListener("slotchange", this.updateTabsAndPanels), (r = this._defaultSlotEl) == null || r.addEventListener("slotchange", this.updateTabsAndPanels);
|
|
1752
1870
|
}
|
|
1753
|
-
|
|
1871
|
+
cleanupEventListeners() {
|
|
1872
|
+
var t, e, i;
|
|
1873
|
+
this.removeEventListener("click", this.handleClick), this.removeEventListener("keydown", this.handleKeyDown), (t = this._tabSlotEl) == null || t.removeEventListener("slotchange", this.updateTabsAndPanels), (e = this._panelSlotEl) == null || e.removeEventListener("slotchange", this.updateTabsAndPanels), (i = this._defaultSlotEl) == null || i.removeEventListener("slotchange", this.updateTabsAndPanels);
|
|
1874
|
+
}
|
|
1875
|
+
onAttributeChange(t, e, i) {
|
|
1754
1876
|
var s;
|
|
1755
|
-
if (
|
|
1877
|
+
if (t === "orientation") {
|
|
1756
1878
|
const a = (s = this.shadowRoot) == null ? void 0 : s.querySelector('[role="tablist"]');
|
|
1757
1879
|
a == null || a.setAttribute("aria-orientation", i || "horizontal");
|
|
1758
1880
|
}
|
|
1759
|
-
|
|
1881
|
+
t === "selected-index" && i && (this.selectedIndex = parseInt(i, 10));
|
|
1760
1882
|
}
|
|
1761
|
-
selectTab(
|
|
1762
|
-
const
|
|
1763
|
-
if (this._selectedIndex =
|
|
1764
|
-
const i = this._tabs[
|
|
1883
|
+
selectTab(t) {
|
|
1884
|
+
const e = this._selectedIndex;
|
|
1885
|
+
if (this._selectedIndex = t, this._focusedIndex = t, this.updateSelection(), e !== t) {
|
|
1886
|
+
const i = this._tabs[t];
|
|
1765
1887
|
v(`${(i == null ? void 0 : i.textContent) || "Tab"} selected`), this.emit("a11y-tabs-change", {
|
|
1766
|
-
index:
|
|
1767
|
-
tab: this._tabs[
|
|
1768
|
-
panel: this._panels[
|
|
1888
|
+
index: t,
|
|
1889
|
+
tab: this._tabs[t],
|
|
1890
|
+
panel: this._panels[t]
|
|
1769
1891
|
});
|
|
1770
1892
|
}
|
|
1771
1893
|
}
|
|
1772
1894
|
updateSelection() {
|
|
1773
|
-
this._tabs.forEach((
|
|
1774
|
-
const i =
|
|
1775
|
-
|
|
1776
|
-
}), this._panels.forEach((
|
|
1777
|
-
|
|
1895
|
+
this._tabs.forEach((t, e) => {
|
|
1896
|
+
const i = e === this._selectedIndex;
|
|
1897
|
+
t.setAttribute("aria-selected", String(i)), t.setAttribute("tabindex", i ? "0" : "-1");
|
|
1898
|
+
}), this._panels.forEach((t, e) => {
|
|
1899
|
+
t.hidden = e !== this._selectedIndex;
|
|
1778
1900
|
});
|
|
1779
1901
|
}
|
|
1780
1902
|
/**
|
|
1781
1903
|
* Select a tab by index
|
|
1782
1904
|
*/
|
|
1783
|
-
select(
|
|
1784
|
-
this.selectTab(
|
|
1905
|
+
select(t) {
|
|
1906
|
+
this.selectTab(t);
|
|
1785
1907
|
}
|
|
1786
1908
|
/**
|
|
1787
1909
|
* Select next tab
|
|
@@ -1798,20 +1920,20 @@ class F extends c {
|
|
|
1798
1920
|
);
|
|
1799
1921
|
}
|
|
1800
1922
|
}
|
|
1801
|
-
|
|
1802
|
-
class
|
|
1923
|
+
c("a11y-tabs", P);
|
|
1924
|
+
class j extends d {
|
|
1803
1925
|
constructor() {
|
|
1804
1926
|
super(...arguments), this._open = !1, this._highlightedIndex = -1, this._options = [], this._filteredOptions = [], this._inputValue = "", this._selectedValue = null, this._inputElement = null, this._listboxElement = null, this.updateOptions = () => {
|
|
1805
|
-
const
|
|
1806
|
-
this._options =
|
|
1807
|
-
value:
|
|
1808
|
-
label:
|
|
1809
|
-
disabled:
|
|
1810
|
-
element:
|
|
1927
|
+
const t = Array.from(this.querySelectorAll("option"));
|
|
1928
|
+
this._options = t.map((e) => ({
|
|
1929
|
+
value: e.getAttribute("value") || e.textContent || "",
|
|
1930
|
+
label: e.textContent || "",
|
|
1931
|
+
disabled: e.hasAttribute("disabled"),
|
|
1932
|
+
element: e
|
|
1811
1933
|
})), this._filteredOptions = [...this._options], this.renderOptions();
|
|
1812
|
-
}, this.handleInput = (
|
|
1813
|
-
const
|
|
1814
|
-
this._inputValue =
|
|
1934
|
+
}, this.handleInput = (t) => {
|
|
1935
|
+
const e = t.target;
|
|
1936
|
+
this._inputValue = e.value;
|
|
1815
1937
|
const i = this._inputValue.toLowerCase();
|
|
1816
1938
|
this._filteredOptions = i ? this._options.filter((a) => a.label.toLowerCase().includes(i)) : [...this._options], this.renderOptions(), this.open = !0, this._highlightedIndex = 0, this.updateHighlight(), this.updateClearButton();
|
|
1817
1939
|
const s = this._filteredOptions.length;
|
|
@@ -1822,50 +1944,50 @@ class N extends c {
|
|
|
1822
1944
|
this.open = !0;
|
|
1823
1945
|
}, this.handleBlur = () => {
|
|
1824
1946
|
setTimeout(() => {
|
|
1825
|
-
var
|
|
1826
|
-
(
|
|
1947
|
+
var t;
|
|
1948
|
+
(t = this.shadowRoot) != null && t.activeElement || (this.open = !1);
|
|
1827
1949
|
}, 150);
|
|
1828
|
-
}, this.handleKeyDown = (
|
|
1829
|
-
switch (
|
|
1950
|
+
}, this.handleKeyDown = (t) => {
|
|
1951
|
+
switch (t.key) {
|
|
1830
1952
|
case "ArrowDown":
|
|
1831
|
-
|
|
1953
|
+
t.preventDefault(), this._open ? this._highlightedIndex = Math.min(
|
|
1832
1954
|
this._highlightedIndex + 1,
|
|
1833
1955
|
this._filteredOptions.length - 1
|
|
1834
1956
|
) : (this.open = !0, this._highlightedIndex = 0), this.updateHighlight();
|
|
1835
1957
|
break;
|
|
1836
1958
|
case "ArrowUp":
|
|
1837
|
-
|
|
1959
|
+
t.preventDefault(), this._open ? this._highlightedIndex = Math.max(this._highlightedIndex - 1, 0) : (this.open = !0, this._highlightedIndex = this._filteredOptions.length - 1), this.updateHighlight();
|
|
1838
1960
|
break;
|
|
1839
1961
|
case "Enter":
|
|
1840
|
-
if (
|
|
1841
|
-
const
|
|
1842
|
-
|
|
1962
|
+
if (t.preventDefault(), this._open && this._highlightedIndex >= 0) {
|
|
1963
|
+
const e = this._filteredOptions[this._highlightedIndex];
|
|
1964
|
+
e && !e.disabled && this.selectOption(e);
|
|
1843
1965
|
}
|
|
1844
1966
|
break;
|
|
1845
1967
|
case "Escape":
|
|
1846
|
-
|
|
1968
|
+
t.preventDefault(), this.open = !1, this._highlightedIndex = -1;
|
|
1847
1969
|
break;
|
|
1848
1970
|
case "Home":
|
|
1849
|
-
this._open && (
|
|
1971
|
+
this._open && (t.preventDefault(), this._highlightedIndex = 0, this.updateHighlight());
|
|
1850
1972
|
break;
|
|
1851
1973
|
case "End":
|
|
1852
|
-
this._open && (
|
|
1974
|
+
this._open && (t.preventDefault(), this._highlightedIndex = this._filteredOptions.length - 1, this.updateHighlight());
|
|
1853
1975
|
break;
|
|
1854
1976
|
case "Tab":
|
|
1855
1977
|
this._open && (this.open = !1, this._highlightedIndex = -1);
|
|
1856
1978
|
break;
|
|
1857
1979
|
}
|
|
1858
|
-
}, this.handleOptionClick = (
|
|
1859
|
-
const
|
|
1980
|
+
}, this.handleOptionClick = (t) => {
|
|
1981
|
+
const e = t.currentTarget, i = parseInt(e.dataset.index || "0", 10), s = this._filteredOptions[i];
|
|
1860
1982
|
s && !s.disabled && this.selectOption(s);
|
|
1861
|
-
}, this.handleOptionHover = (
|
|
1862
|
-
const
|
|
1983
|
+
}, this.handleOptionHover = (t) => {
|
|
1984
|
+
const e = t.currentTarget, i = parseInt(e.dataset.index || "0", 10), s = this._filteredOptions[i];
|
|
1863
1985
|
s && !s.disabled && (this._highlightedIndex = i, this.updateHighlight());
|
|
1864
1986
|
}, this.handleClear = () => {
|
|
1865
1987
|
this._inputValue = "", this._selectedValue = null, this._inputElement && (this._inputElement.value = "", this._inputElement.focus()), this._filteredOptions = [...this._options], this.renderOptions(), this.updateClearButton(), this.emit("a11y-combobox-clear"), this.emit("a11y-combobox-change", { value: null, label: null });
|
|
1866
|
-
}, this.handleOutsideClick = (
|
|
1988
|
+
}, this.handleOutsideClick = (t) => {
|
|
1867
1989
|
if (!this._open) return;
|
|
1868
|
-
|
|
1990
|
+
t.composedPath().includes(this) || (this.open = !1);
|
|
1869
1991
|
};
|
|
1870
1992
|
}
|
|
1871
1993
|
static get observedAttributes() {
|
|
@@ -1874,28 +1996,28 @@ class N extends c {
|
|
|
1874
1996
|
get open() {
|
|
1875
1997
|
return this._open;
|
|
1876
1998
|
}
|
|
1877
|
-
set open(
|
|
1878
|
-
const
|
|
1879
|
-
this._open =
|
|
1999
|
+
set open(t) {
|
|
2000
|
+
const e = this._open;
|
|
2001
|
+
this._open = t, t !== e && this.updateListboxVisibility(), this.toggleAttribute("open", t);
|
|
1880
2002
|
}
|
|
1881
2003
|
get value() {
|
|
1882
2004
|
return this._selectedValue;
|
|
1883
2005
|
}
|
|
1884
|
-
set value(
|
|
1885
|
-
this._selectedValue =
|
|
1886
|
-
const
|
|
1887
|
-
|
|
2006
|
+
set value(t) {
|
|
2007
|
+
this._selectedValue = t;
|
|
2008
|
+
const e = this._options.find((i) => i.value === t);
|
|
2009
|
+
e && (this._inputValue = e.label, this._inputElement && (this._inputElement.value = e.label)), this.setAttribute("value", t || "");
|
|
1888
2010
|
}
|
|
1889
2011
|
setupAccessibility() {
|
|
1890
2012
|
}
|
|
1891
2013
|
render() {
|
|
1892
|
-
const
|
|
1893
|
-
|
|
1894
|
-
<style>${
|
|
2014
|
+
const t = this.attachShadow({ mode: "open" }), e = `${this._id}-input`, i = `${this._id}-listbox`, s = this.getAttribute("placeholder") || "Search...", a = this.hasAttribute("clearable");
|
|
2015
|
+
t.innerHTML = `
|
|
2016
|
+
<style>${At}</style>
|
|
1895
2017
|
<div class="combobox-wrapper" part="wrapper">
|
|
1896
2018
|
<div class="input-wrapper" part="input-wrapper">
|
|
1897
2019
|
<input
|
|
1898
|
-
id="${
|
|
2020
|
+
id="${e}"
|
|
1899
2021
|
type="text"
|
|
1900
2022
|
role="combobox"
|
|
1901
2023
|
autocomplete="off"
|
|
@@ -1921,7 +2043,7 @@ class N extends c {
|
|
|
1921
2043
|
<ul
|
|
1922
2044
|
id="${i}"
|
|
1923
2045
|
role="listbox"
|
|
1924
|
-
aria-labelledby="${
|
|
2046
|
+
aria-labelledby="${e}"
|
|
1925
2047
|
class="listbox"
|
|
1926
2048
|
tabindex="-1"
|
|
1927
2049
|
hidden
|
|
@@ -1931,56 +2053,56 @@ class N extends c {
|
|
|
1931
2053
|
<div class="options-source" hidden>
|
|
1932
2054
|
<slot></slot>
|
|
1933
2055
|
</div>
|
|
1934
|
-
`, this._inputElement =
|
|
2056
|
+
`, this._inputElement = t.querySelector("input"), this._listboxElement = t.querySelector(".listbox");
|
|
1935
2057
|
}
|
|
1936
2058
|
setupEventListeners() {
|
|
1937
2059
|
var i, s, a, r, l, o;
|
|
1938
2060
|
(i = this._inputElement) == null || i.addEventListener("input", this.handleInput), (s = this._inputElement) == null || s.addEventListener("focus", this.handleFocus), (a = this._inputElement) == null || a.addEventListener("blur", this.handleBlur), (r = this._inputElement) == null || r.addEventListener("keydown", this.handleKeyDown);
|
|
1939
|
-
const
|
|
1940
|
-
|
|
1941
|
-
const
|
|
1942
|
-
|
|
2061
|
+
const t = (l = this.shadowRoot) == null ? void 0 : l.querySelector(".clear-button");
|
|
2062
|
+
t == null || t.addEventListener("click", this.handleClear), document.addEventListener("mousedown", this.handleOutsideClick);
|
|
2063
|
+
const e = (o = this.shadowRoot) == null ? void 0 : o.querySelector("slot");
|
|
2064
|
+
e == null || e.addEventListener("slotchange", this.updateOptions), this.updateOptions();
|
|
1943
2065
|
}
|
|
1944
2066
|
cleanupEventListeners() {
|
|
1945
2067
|
document.removeEventListener("mousedown", this.handleOutsideClick);
|
|
1946
2068
|
}
|
|
1947
|
-
onAttributeChange(
|
|
1948
|
-
|
|
2069
|
+
onAttributeChange(t, e, i) {
|
|
2070
|
+
t === "open" && (this.open = i !== null), t === "value" && (this.value = i), t === "disabled" && this._inputElement && (this._inputElement.disabled = i !== null), t === "placeholder" && this._inputElement && (this._inputElement.placeholder = i || "Search...");
|
|
1949
2071
|
}
|
|
1950
2072
|
renderOptions() {
|
|
1951
2073
|
this._listboxElement && (this._listboxElement.innerHTML = this._filteredOptions.length === 0 ? '<li role="presentation" class="empty-message" part="empty">No results found</li>' : this._filteredOptions.map(
|
|
1952
|
-
(
|
|
2074
|
+
(t, e) => `
|
|
1953
2075
|
<li
|
|
1954
|
-
id="${this._id}-option-${
|
|
2076
|
+
id="${this._id}-option-${e}"
|
|
1955
2077
|
role="option"
|
|
1956
|
-
aria-selected="${this._selectedValue ===
|
|
1957
|
-
aria-disabled="${
|
|
1958
|
-
data-value="${
|
|
1959
|
-
data-index="${
|
|
2078
|
+
aria-selected="${this._selectedValue === t.value}"
|
|
2079
|
+
aria-disabled="${t.disabled}"
|
|
2080
|
+
data-value="${t.value}"
|
|
2081
|
+
data-index="${e}"
|
|
1960
2082
|
part="option"
|
|
1961
|
-
${
|
|
1962
|
-
>${
|
|
2083
|
+
${t.disabled ? 'class="disabled"' : ""}
|
|
2084
|
+
>${t.label}</li>
|
|
1963
2085
|
`
|
|
1964
|
-
).join(""), this._listboxElement.querySelectorAll('[role="option"]').forEach((
|
|
1965
|
-
|
|
2086
|
+
).join(""), this._listboxElement.querySelectorAll('[role="option"]').forEach((t) => {
|
|
2087
|
+
t.addEventListener("click", this.handleOptionClick), t.addEventListener("mouseenter", this.handleOptionHover);
|
|
1966
2088
|
}));
|
|
1967
2089
|
}
|
|
1968
|
-
selectOption(
|
|
1969
|
-
this._selectedValue =
|
|
1970
|
-
value:
|
|
1971
|
-
label:
|
|
2090
|
+
selectOption(t) {
|
|
2091
|
+
this._selectedValue = t.value, this._inputValue = t.label, this._inputElement && (this._inputElement.value = t.label), this.open = !1, this._highlightedIndex = -1, this.renderOptions(), this.updateClearButton(), v(`${t.label} selected`), this.emit("a11y-combobox-select", {
|
|
2092
|
+
value: t.value,
|
|
2093
|
+
label: t.label
|
|
1972
2094
|
}), this.emit("a11y-combobox-change", {
|
|
1973
|
-
value:
|
|
1974
|
-
label:
|
|
2095
|
+
value: t.value,
|
|
2096
|
+
label: t.label
|
|
1975
2097
|
});
|
|
1976
2098
|
}
|
|
1977
2099
|
updateHighlight() {
|
|
1978
|
-
var
|
|
1979
|
-
if ((
|
|
2100
|
+
var t, e, i, s;
|
|
2101
|
+
if ((t = this._listboxElement) == null || t.querySelectorAll('[role="option"]').forEach((a, r) => {
|
|
1980
2102
|
a.classList.toggle("highlighted", r === this._highlightedIndex);
|
|
1981
2103
|
}), this._highlightedIndex >= 0) {
|
|
1982
2104
|
const a = `${this._id}-option-${this._highlightedIndex}`;
|
|
1983
|
-
(
|
|
2105
|
+
(e = this._inputElement) == null || e.setAttribute("aria-activedescendant", a);
|
|
1984
2106
|
const r = (i = this._listboxElement) == null ? void 0 : i.querySelector(`#${a}`);
|
|
1985
2107
|
r == null || r.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
|
1986
2108
|
} else
|
|
@@ -1991,19 +2113,19 @@ class N extends c {
|
|
|
1991
2113
|
}
|
|
1992
2114
|
updateListboxPosition() {
|
|
1993
2115
|
if (!this._listboxElement || !this._inputElement) return;
|
|
1994
|
-
const
|
|
2116
|
+
const t = this._inputElement.getBoundingClientRect(), e = window.innerHeight, i = Math.min(
|
|
1995
2117
|
this._listboxElement.scrollHeight,
|
|
1996
2118
|
200
|
|
1997
2119
|
// max-height from CSS
|
|
1998
|
-
), s =
|
|
2120
|
+
), s = e - t.bottom, a = t.top;
|
|
1999
2121
|
s < i + 8 && a > s ? (this._listboxElement.style.top = "auto", this._listboxElement.style.bottom = "100%", this._listboxElement.style.marginTop = "0", this._listboxElement.style.marginBottom = "4px", this.setAttribute("data-position", "top")) : (this._listboxElement.style.top = "100%", this._listboxElement.style.bottom = "auto", this._listboxElement.style.marginTop = "4px", this._listboxElement.style.marginBottom = "0", this.setAttribute("data-position", "bottom"));
|
|
2000
2122
|
}
|
|
2001
2123
|
updateClearButton() {
|
|
2002
|
-
var
|
|
2003
|
-
const
|
|
2124
|
+
var e;
|
|
2125
|
+
const t = (e = this.shadowRoot) == null ? void 0 : e.querySelector(
|
|
2004
2126
|
".clear-button"
|
|
2005
2127
|
);
|
|
2006
|
-
|
|
2128
|
+
t && (t.hidden = !this._inputValue);
|
|
2007
2129
|
}
|
|
2008
2130
|
/**
|
|
2009
2131
|
* Programmatic open
|
|
@@ -2024,16 +2146,16 @@ class N extends c {
|
|
|
2024
2146
|
this.handleClear();
|
|
2025
2147
|
}
|
|
2026
2148
|
}
|
|
2027
|
-
|
|
2028
|
-
class
|
|
2149
|
+
c("a11y-combobox", j);
|
|
2150
|
+
class U extends d {
|
|
2029
2151
|
constructor() {
|
|
2030
2152
|
super(...arguments), this._checked = !1, this._button = null, this._label = null, this.handleClick = () => {
|
|
2031
2153
|
this.toggle();
|
|
2032
|
-
}, this.handleKeyDown = (
|
|
2033
|
-
this.disabled || (
|
|
2154
|
+
}, this.handleKeyDown = (t) => {
|
|
2155
|
+
this.disabled || (t.key === " " || t.key === "Enter") && (t.preventDefault(), this.toggle());
|
|
2034
2156
|
}, this.handleLabelClick = () => {
|
|
2035
|
-
var
|
|
2036
|
-
this.disabled || (this.toggle(), (
|
|
2157
|
+
var t;
|
|
2158
|
+
this.disabled || (this.toggle(), (t = this._button) == null || t.focus());
|
|
2037
2159
|
};
|
|
2038
2160
|
}
|
|
2039
2161
|
static get observedAttributes() {
|
|
@@ -2045,9 +2167,9 @@ class P extends c {
|
|
|
2045
2167
|
get checked() {
|
|
2046
2168
|
return this._checked;
|
|
2047
2169
|
}
|
|
2048
|
-
set checked(
|
|
2049
|
-
const
|
|
2050
|
-
this._checked =
|
|
2170
|
+
set checked(t) {
|
|
2171
|
+
const e = this._checked;
|
|
2172
|
+
this._checked = t, this.toggleAttribute("checked", t), t !== e && (this.updateVisualState(), this.emit("change", { checked: t }));
|
|
2051
2173
|
}
|
|
2052
2174
|
/**
|
|
2053
2175
|
* Get/set the disabled state
|
|
@@ -2055,8 +2177,8 @@ class P extends c {
|
|
|
2055
2177
|
get disabled() {
|
|
2056
2178
|
return this.hasAttribute("disabled");
|
|
2057
2179
|
}
|
|
2058
|
-
set disabled(
|
|
2059
|
-
this.toggleAttribute("disabled",
|
|
2180
|
+
set disabled(t) {
|
|
2181
|
+
this.toggleAttribute("disabled", t), this.updateDisabledState();
|
|
2060
2182
|
}
|
|
2061
2183
|
/**
|
|
2062
2184
|
* Get/set the visible label
|
|
@@ -2064,30 +2186,30 @@ class P extends c {
|
|
|
2064
2186
|
get label() {
|
|
2065
2187
|
return this.getAttribute("label") || "";
|
|
2066
2188
|
}
|
|
2067
|
-
set label(
|
|
2068
|
-
|
|
2189
|
+
set label(t) {
|
|
2190
|
+
t ? this.setAttribute("label", t) : this.removeAttribute("label");
|
|
2069
2191
|
}
|
|
2070
2192
|
/**
|
|
2071
2193
|
* Get/set the size variant
|
|
2072
2194
|
*/
|
|
2073
2195
|
get size() {
|
|
2074
|
-
const
|
|
2075
|
-
return
|
|
2196
|
+
const t = this.getAttribute("size");
|
|
2197
|
+
return t === "sm" || t === "lg" ? t : "md";
|
|
2076
2198
|
}
|
|
2077
|
-
set size(
|
|
2078
|
-
this.setAttribute("size",
|
|
2199
|
+
set size(t) {
|
|
2200
|
+
this.setAttribute("size", t);
|
|
2079
2201
|
}
|
|
2080
2202
|
setupAccessibility() {
|
|
2081
|
-
var
|
|
2082
|
-
this.getAttribute("role"), typeof process < "u" && ((
|
|
2203
|
+
var t;
|
|
2204
|
+
this.getAttribute("role"), typeof process < "u" && ((t = process.env) == null ? void 0 : t.NODE_ENV) !== "production" && !this.label && !this.getAttribute("aria-label") && console.warn(
|
|
2083
2205
|
`[compa11y/Switch] Switch has no accessible label. Add label="..." or aria-label="..." attribute.
|
|
2084
2206
|
💡 Suggestion: <a11y-switch label="Enable feature"></a11y-switch>`
|
|
2085
2207
|
);
|
|
2086
2208
|
}
|
|
2087
2209
|
render() {
|
|
2088
|
-
const
|
|
2089
|
-
|
|
2090
|
-
<style>${
|
|
2210
|
+
const t = this.attachShadow({ mode: "open" }), e = `${this._id}-label`, i = !!this.label, s = this.getAttribute("aria-label"), a = i ? "" : s ? `aria-label="${s}"` : "", r = i ? `aria-labelledby="${e}"` : "";
|
|
2211
|
+
t.innerHTML = `
|
|
2212
|
+
<style>${wt}</style>
|
|
2091
2213
|
<div class="switch-wrapper size-${this.size}" part="wrapper">
|
|
2092
2214
|
<button
|
|
2093
2215
|
type="button"
|
|
@@ -2102,20 +2224,20 @@ class P extends c {
|
|
|
2102
2224
|
>
|
|
2103
2225
|
<span class="switch-thumb" part="thumb" aria-hidden="true"></span>
|
|
2104
2226
|
</button>
|
|
2105
|
-
${i ? `<label id="${
|
|
2227
|
+
${i ? `<label id="${e}" class="switch-label ${this.disabled ? "disabled" : ""}" part="label">${this.label}</label>` : ""}
|
|
2106
2228
|
</div>
|
|
2107
|
-
`, this._button =
|
|
2229
|
+
`, this._button = t.querySelector("button"), this._label = t.querySelector("label");
|
|
2108
2230
|
}
|
|
2109
2231
|
setupEventListeners() {
|
|
2110
|
-
var
|
|
2111
|
-
(
|
|
2232
|
+
var t, e, i;
|
|
2233
|
+
(t = this._button) == null || t.addEventListener("click", this.handleClick), (e = this._button) == null || e.addEventListener("keydown", this.handleKeyDown), (i = this._label) == null || i.addEventListener("click", this.handleLabelClick);
|
|
2112
2234
|
}
|
|
2113
2235
|
cleanupEventListeners() {
|
|
2114
|
-
var
|
|
2115
|
-
(
|
|
2236
|
+
var t, e, i;
|
|
2237
|
+
(t = this._button) == null || t.removeEventListener("click", this.handleClick), (e = this._button) == null || e.removeEventListener("keydown", this.handleKeyDown), (i = this._label) == null || i.removeEventListener("click", this.handleLabelClick);
|
|
2116
2238
|
}
|
|
2117
|
-
onAttributeChange(
|
|
2118
|
-
switch (
|
|
2239
|
+
onAttributeChange(t, e, i) {
|
|
2240
|
+
switch (t) {
|
|
2119
2241
|
case "checked":
|
|
2120
2242
|
this._checked = i !== null, this.updateVisualState();
|
|
2121
2243
|
break;
|
|
@@ -2147,9 +2269,9 @@ class P extends c {
|
|
|
2147
2269
|
* Update the size class
|
|
2148
2270
|
*/
|
|
2149
2271
|
updateSizeClass() {
|
|
2150
|
-
var
|
|
2151
|
-
const
|
|
2152
|
-
|
|
2272
|
+
var e;
|
|
2273
|
+
const t = (e = this.shadowRoot) == null ? void 0 : e.querySelector(".switch-wrapper");
|
|
2274
|
+
t && (t.classList.remove("size-sm", "size-md", "size-lg"), t.classList.add(`size-${this.size}`));
|
|
2153
2275
|
}
|
|
2154
2276
|
/**
|
|
2155
2277
|
* Public method to toggle the switch programmatically
|
|
@@ -2157,69 +2279,69 @@ class P extends c {
|
|
|
2157
2279
|
toggle() {
|
|
2158
2280
|
if (this.disabled) return;
|
|
2159
2281
|
this.checked = !this.checked;
|
|
2160
|
-
const
|
|
2161
|
-
p(`${
|
|
2282
|
+
const t = this.label || this.getAttribute("aria-label") || "Switch";
|
|
2283
|
+
p(`${t} ${this.checked ? "on" : "off"}`);
|
|
2162
2284
|
}
|
|
2163
2285
|
/**
|
|
2164
2286
|
* Public method to open/close programmatically
|
|
2165
2287
|
*/
|
|
2166
|
-
setChecked(
|
|
2167
|
-
this.checked =
|
|
2288
|
+
setChecked(t) {
|
|
2289
|
+
this.checked = t;
|
|
2168
2290
|
}
|
|
2169
2291
|
}
|
|
2170
|
-
|
|
2171
|
-
class
|
|
2292
|
+
c("a11y-switch", U);
|
|
2293
|
+
class Y extends d {
|
|
2172
2294
|
constructor() {
|
|
2173
2295
|
super(...arguments), this._open = !1, this._highlightedIndex = -1, this._options = [], this._selectedValue = null, this._triggerElement = null, this._listboxElement = null, this._typeAhead = null, this.updateOptions = () => {
|
|
2174
|
-
const
|
|
2175
|
-
this._options =
|
|
2176
|
-
value:
|
|
2177
|
-
label:
|
|
2178
|
-
disabled:
|
|
2179
|
-
element:
|
|
2296
|
+
const t = Array.from(this.querySelectorAll("option"));
|
|
2297
|
+
this._options = t.map((e) => ({
|
|
2298
|
+
value: e.getAttribute("value") || e.textContent || "",
|
|
2299
|
+
label: e.textContent || "",
|
|
2300
|
+
disabled: e.hasAttribute("disabled"),
|
|
2301
|
+
element: e
|
|
2180
2302
|
})), this._typeAhead = q(
|
|
2181
|
-
this._options.map((
|
|
2303
|
+
this._options.map((e) => e.label),
|
|
2182
2304
|
{ timeout: 500 }
|
|
2183
2305
|
), this.renderOptions(), this.updateTriggerText();
|
|
2184
2306
|
}, this.handleTriggerClick = () => {
|
|
2185
|
-
var e;
|
|
2186
|
-
(e = this._triggerElement) != null && e.disabled || (this._open ? (this.open = !1, this._highlightedIndex = -1) : this.openAndHighlight());
|
|
2187
|
-
}, this.handleKeyDown = (e) => {
|
|
2188
2307
|
var t;
|
|
2189
|
-
|
|
2308
|
+
(t = this._triggerElement) != null && t.disabled || (this._open ? (this.open = !1, this._highlightedIndex = -1) : this.openAndHighlight());
|
|
2309
|
+
}, this.handleKeyDown = (t) => {
|
|
2310
|
+
var e;
|
|
2311
|
+
switch (t.key) {
|
|
2190
2312
|
case "ArrowDown":
|
|
2191
|
-
|
|
2313
|
+
t.preventDefault(), this._open ? this.highlightNext() : this.openAndHighlight();
|
|
2192
2314
|
break;
|
|
2193
2315
|
case "ArrowUp":
|
|
2194
|
-
|
|
2316
|
+
t.preventDefault(), this._open ? this.highlightPrevious() : this.openAndHighlight(!0);
|
|
2195
2317
|
break;
|
|
2196
2318
|
case "Enter":
|
|
2197
|
-
if (
|
|
2319
|
+
if (t.preventDefault(), this._open && this._highlightedIndex >= 0) {
|
|
2198
2320
|
const i = this._options[this._highlightedIndex];
|
|
2199
2321
|
i && !i.disabled && this.selectOption(i);
|
|
2200
2322
|
} else this._open || this.openAndHighlight();
|
|
2201
2323
|
break;
|
|
2202
2324
|
case " ":
|
|
2203
|
-
if (
|
|
2325
|
+
if (t.preventDefault(), this._open && this._highlightedIndex >= 0) {
|
|
2204
2326
|
const i = this._options[this._highlightedIndex];
|
|
2205
2327
|
i && !i.disabled && this.selectOption(i);
|
|
2206
2328
|
} else this._open || this.openAndHighlight();
|
|
2207
2329
|
break;
|
|
2208
2330
|
case "Escape":
|
|
2209
|
-
|
|
2331
|
+
t.preventDefault(), this._open && (this.open = !1, this._highlightedIndex = -1);
|
|
2210
2332
|
break;
|
|
2211
2333
|
case "Home":
|
|
2212
|
-
this._open && (
|
|
2334
|
+
this._open && (t.preventDefault(), this._highlightedIndex = this.findFirstEnabled(), this.updateHighlight());
|
|
2213
2335
|
break;
|
|
2214
2336
|
case "End":
|
|
2215
|
-
this._open && (
|
|
2337
|
+
this._open && (t.preventDefault(), this._highlightedIndex = this.findLastEnabled(), this.updateHighlight());
|
|
2216
2338
|
break;
|
|
2217
2339
|
case "Tab":
|
|
2218
2340
|
this._open && (this.open = !1, this._highlightedIndex = -1);
|
|
2219
2341
|
break;
|
|
2220
2342
|
default:
|
|
2221
|
-
if (
|
|
2222
|
-
const i = (
|
|
2343
|
+
if (t.key.length === 1 && !t.ctrlKey && !t.altKey && !t.metaKey) {
|
|
2344
|
+
const i = (e = this._typeAhead) == null ? void 0 : e.type(t.key);
|
|
2223
2345
|
if (i) {
|
|
2224
2346
|
const s = this._options.findIndex(
|
|
2225
2347
|
(a) => a.label === i && !a.disabled
|
|
@@ -2231,20 +2353,20 @@ class j extends c {
|
|
|
2231
2353
|
}
|
|
2232
2354
|
}, this.handleBlur = () => {
|
|
2233
2355
|
setTimeout(() => {
|
|
2234
|
-
var
|
|
2235
|
-
(
|
|
2356
|
+
var t;
|
|
2357
|
+
(t = this.shadowRoot) != null && t.activeElement || (this.open = !1, this._highlightedIndex = -1);
|
|
2236
2358
|
}, 150);
|
|
2237
|
-
}, this.handleListboxMouseDown = (
|
|
2238
|
-
|
|
2239
|
-
}, this.handleOptionClick = (
|
|
2240
|
-
const
|
|
2359
|
+
}, this.handleListboxMouseDown = (t) => {
|
|
2360
|
+
t.preventDefault();
|
|
2361
|
+
}, this.handleOptionClick = (t) => {
|
|
2362
|
+
const e = t.currentTarget, i = parseInt(e.dataset.index || "0", 10), s = this._options[i];
|
|
2241
2363
|
s && !s.disabled && this.selectOption(s);
|
|
2242
|
-
}, this.handleOptionHover = (
|
|
2243
|
-
const
|
|
2364
|
+
}, this.handleOptionHover = (t) => {
|
|
2365
|
+
const e = t.currentTarget, i = parseInt(e.dataset.index || "0", 10), s = this._options[i];
|
|
2244
2366
|
s && !s.disabled && (this._highlightedIndex = i, this.updateHighlight());
|
|
2245
|
-
}, this.handleOutsideClick = (
|
|
2367
|
+
}, this.handleOutsideClick = (t) => {
|
|
2246
2368
|
if (!this._open) return;
|
|
2247
|
-
|
|
2369
|
+
t.composedPath().includes(this) || (this.open = !1, this._highlightedIndex = -1);
|
|
2248
2370
|
};
|
|
2249
2371
|
}
|
|
2250
2372
|
static get observedAttributes() {
|
|
@@ -2253,25 +2375,25 @@ class j extends c {
|
|
|
2253
2375
|
get open() {
|
|
2254
2376
|
return this._open;
|
|
2255
2377
|
}
|
|
2256
|
-
set open(
|
|
2257
|
-
const
|
|
2258
|
-
this._open =
|
|
2378
|
+
set open(t) {
|
|
2379
|
+
const e = this._open;
|
|
2380
|
+
this._open = t, t !== e && this.updateListboxVisibility(), this.toggleAttribute("open", t);
|
|
2259
2381
|
}
|
|
2260
2382
|
get value() {
|
|
2261
2383
|
return this._selectedValue;
|
|
2262
2384
|
}
|
|
2263
|
-
set value(
|
|
2264
|
-
this._selectedValue =
|
|
2385
|
+
set value(t) {
|
|
2386
|
+
this._selectedValue = t, this.updateTriggerText(), this.setAttribute("value", t || "");
|
|
2265
2387
|
}
|
|
2266
2388
|
setupAccessibility() {
|
|
2267
2389
|
}
|
|
2268
2390
|
render() {
|
|
2269
|
-
const
|
|
2270
|
-
|
|
2271
|
-
<style>${
|
|
2391
|
+
const t = this.attachShadow({ mode: "open" }), e = `${this._id}-trigger`, i = `${this._id}-listbox`, s = this.getAttribute("placeholder") || "Select an option...", a = this.getAttribute("aria-label") || "", r = this.getAttribute("aria-labelledby") || "";
|
|
2392
|
+
t.innerHTML = `
|
|
2393
|
+
<style>${kt}</style>
|
|
2272
2394
|
<div class="select-wrapper" part="wrapper">
|
|
2273
2395
|
<button
|
|
2274
|
-
id="${
|
|
2396
|
+
id="${e}"
|
|
2275
2397
|
type="button"
|
|
2276
2398
|
role="combobox"
|
|
2277
2399
|
aria-expanded="false"
|
|
@@ -2288,7 +2410,7 @@ class j extends c {
|
|
|
2288
2410
|
<ul
|
|
2289
2411
|
id="${i}"
|
|
2290
2412
|
role="listbox"
|
|
2291
|
-
aria-labelledby="${
|
|
2413
|
+
aria-labelledby="${e}"
|
|
2292
2414
|
class="listbox"
|
|
2293
2415
|
tabindex="-1"
|
|
2294
2416
|
hidden
|
|
@@ -2298,105 +2420,105 @@ class j extends c {
|
|
|
2298
2420
|
<div class="options-source" hidden>
|
|
2299
2421
|
<slot></slot>
|
|
2300
2422
|
</div>
|
|
2301
|
-
`, this._triggerElement =
|
|
2423
|
+
`, this._triggerElement = t.querySelector(".select-trigger"), this._listboxElement = t.querySelector(".listbox");
|
|
2302
2424
|
}
|
|
2303
2425
|
setupEventListeners() {
|
|
2304
|
-
var
|
|
2305
|
-
(
|
|
2426
|
+
var e, i, s, a, r;
|
|
2427
|
+
(e = this._triggerElement) == null || e.addEventListener("click", this.handleTriggerClick), (i = this._triggerElement) == null || i.addEventListener("keydown", this.handleKeyDown), (s = this._triggerElement) == null || s.addEventListener("blur", this.handleBlur), (a = this._listboxElement) == null || a.addEventListener(
|
|
2306
2428
|
"mousedown",
|
|
2307
2429
|
this.handleListboxMouseDown
|
|
2308
2430
|
), document.addEventListener("mousedown", this.handleOutsideClick);
|
|
2309
|
-
const
|
|
2310
|
-
|
|
2431
|
+
const t = (r = this.shadowRoot) == null ? void 0 : r.querySelector("slot");
|
|
2432
|
+
t == null || t.addEventListener("slotchange", this.updateOptions), this.updateOptions();
|
|
2311
2433
|
}
|
|
2312
2434
|
cleanupEventListeners() {
|
|
2313
2435
|
document.removeEventListener("mousedown", this.handleOutsideClick);
|
|
2314
2436
|
}
|
|
2315
|
-
onAttributeChange(
|
|
2316
|
-
|
|
2437
|
+
onAttributeChange(t, e, i) {
|
|
2438
|
+
t === "open" && (this.open = i !== null), t === "value" && (this.value = i), t === "disabled" && this._triggerElement && (this._triggerElement.disabled = i !== null), t === "placeholder" && this.updateTriggerText();
|
|
2317
2439
|
}
|
|
2318
2440
|
renderOptions() {
|
|
2319
2441
|
this._listboxElement && (this._listboxElement.innerHTML = this._options.map(
|
|
2320
|
-
(
|
|
2442
|
+
(t, e) => `
|
|
2321
2443
|
<li
|
|
2322
|
-
id="${this._id}-option-${
|
|
2444
|
+
id="${this._id}-option-${e}"
|
|
2323
2445
|
role="option"
|
|
2324
|
-
aria-selected="${this._selectedValue ===
|
|
2325
|
-
aria-disabled="${
|
|
2326
|
-
data-value="${
|
|
2327
|
-
data-index="${
|
|
2446
|
+
aria-selected="${this._selectedValue === t.value}"
|
|
2447
|
+
aria-disabled="${t.disabled}"
|
|
2448
|
+
data-value="${t.value}"
|
|
2449
|
+
data-index="${e}"
|
|
2328
2450
|
part="option"
|
|
2329
|
-
${
|
|
2451
|
+
${t.disabled ? 'class="disabled"' : ""}
|
|
2330
2452
|
>
|
|
2331
|
-
<span class="option-text">${
|
|
2332
|
-
${this._selectedValue ===
|
|
2453
|
+
<span class="option-text">${t.label}</span>
|
|
2454
|
+
${this._selectedValue === t.value ? '<span class="check-mark" aria-hidden="true">✓</span>' : ""}
|
|
2333
2455
|
</li>
|
|
2334
2456
|
`
|
|
2335
|
-
).join(""), this._listboxElement.querySelectorAll('[role="option"]').forEach((
|
|
2336
|
-
|
|
2457
|
+
).join(""), this._listboxElement.querySelectorAll('[role="option"]').forEach((t) => {
|
|
2458
|
+
t.addEventListener("click", this.handleOptionClick), t.addEventListener("mouseenter", this.handleOptionHover);
|
|
2337
2459
|
}));
|
|
2338
2460
|
}
|
|
2339
|
-
openAndHighlight(
|
|
2461
|
+
openAndHighlight(t = !1) {
|
|
2340
2462
|
this.open = !0;
|
|
2341
|
-
const
|
|
2463
|
+
const e = this._options.findIndex(
|
|
2342
2464
|
(i) => i.value === this._selectedValue
|
|
2343
2465
|
);
|
|
2344
|
-
|
|
2466
|
+
e >= 0 ? this._highlightedIndex = e : this._highlightedIndex = t ? this.findLastEnabled() : this.findFirstEnabled(), this.updateHighlight(), v(
|
|
2345
2467
|
`${this._options.length} option${this._options.length === 1 ? "" : "s"} available`
|
|
2346
2468
|
);
|
|
2347
2469
|
}
|
|
2348
|
-
selectOption(
|
|
2349
|
-
this._selectedValue =
|
|
2350
|
-
value:
|
|
2351
|
-
label:
|
|
2470
|
+
selectOption(t) {
|
|
2471
|
+
this._selectedValue = t.value, this.updateTriggerText(), this.open = !1, this._highlightedIndex = -1, this.renderOptions(), v(`${t.label} selected`), this.emit("a11y-select-change", {
|
|
2472
|
+
value: t.value,
|
|
2473
|
+
label: t.label
|
|
2352
2474
|
}), this.emit("change", {
|
|
2353
|
-
value:
|
|
2354
|
-
label:
|
|
2475
|
+
value: t.value,
|
|
2476
|
+
label: t.label
|
|
2355
2477
|
});
|
|
2356
2478
|
}
|
|
2357
2479
|
updateTriggerText() {
|
|
2358
2480
|
var s;
|
|
2359
|
-
const
|
|
2360
|
-
if (!
|
|
2361
|
-
const
|
|
2481
|
+
const t = (s = this.shadowRoot) == null ? void 0 : s.querySelector(".select-value");
|
|
2482
|
+
if (!t) return;
|
|
2483
|
+
const e = this._options.find(
|
|
2362
2484
|
(a) => a.value === this._selectedValue
|
|
2363
2485
|
), i = this.getAttribute("placeholder") || "Select an option...";
|
|
2364
|
-
|
|
2486
|
+
e ? (t.textContent = e.label, t.classList.remove("placeholder")) : (t.textContent = i, t.classList.add("placeholder"));
|
|
2365
2487
|
}
|
|
2366
2488
|
highlightNext() {
|
|
2367
|
-
const
|
|
2368
|
-
|
|
2489
|
+
const t = this.findNextEnabled(this._highlightedIndex, 1);
|
|
2490
|
+
t >= 0 && (this._highlightedIndex = t, this.updateHighlight());
|
|
2369
2491
|
}
|
|
2370
2492
|
highlightPrevious() {
|
|
2371
|
-
const
|
|
2372
|
-
|
|
2493
|
+
const t = this.findNextEnabled(this._highlightedIndex, -1);
|
|
2494
|
+
t >= 0 && (this._highlightedIndex = t, this.updateHighlight());
|
|
2373
2495
|
}
|
|
2374
|
-
findNextEnabled(
|
|
2496
|
+
findNextEnabled(t, e) {
|
|
2375
2497
|
var r;
|
|
2376
2498
|
const i = this._options.length;
|
|
2377
|
-
let s =
|
|
2499
|
+
let s = t + e;
|
|
2378
2500
|
s < 0 && (s = i - 1), s >= i && (s = 0);
|
|
2379
2501
|
const a = s;
|
|
2380
2502
|
for (; (r = this._options[s]) != null && r.disabled; )
|
|
2381
|
-
if (s +=
|
|
2503
|
+
if (s += e, s < 0 && (s = i - 1), s >= i && (s = 0), s === a) return -1;
|
|
2382
2504
|
return s;
|
|
2383
2505
|
}
|
|
2384
2506
|
findFirstEnabled() {
|
|
2385
|
-
return this._options.findIndex((
|
|
2507
|
+
return this._options.findIndex((t) => !t.disabled);
|
|
2386
2508
|
}
|
|
2387
2509
|
findLastEnabled() {
|
|
2388
|
-
var
|
|
2389
|
-
for (let
|
|
2390
|
-
if (!((
|
|
2510
|
+
var t;
|
|
2511
|
+
for (let e = this._options.length - 1; e >= 0; e--)
|
|
2512
|
+
if (!((t = this._options[e]) != null && t.disabled)) return e;
|
|
2391
2513
|
return -1;
|
|
2392
2514
|
}
|
|
2393
2515
|
updateHighlight() {
|
|
2394
|
-
var
|
|
2395
|
-
if ((
|
|
2516
|
+
var t, e, i, s;
|
|
2517
|
+
if ((t = this._listboxElement) == null || t.querySelectorAll('[role="option"]').forEach((a, r) => {
|
|
2396
2518
|
a.classList.toggle("highlighted", r === this._highlightedIndex);
|
|
2397
2519
|
}), this._highlightedIndex >= 0) {
|
|
2398
2520
|
const a = `${this._id}-option-${this._highlightedIndex}`;
|
|
2399
|
-
(
|
|
2521
|
+
(e = this._triggerElement) == null || e.setAttribute("aria-activedescendant", a);
|
|
2400
2522
|
const r = (i = this._listboxElement) == null ? void 0 : i.querySelector(`#${a}`);
|
|
2401
2523
|
r == null || r.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
|
2402
2524
|
} else
|
|
@@ -2407,7 +2529,7 @@ class j extends c {
|
|
|
2407
2529
|
}
|
|
2408
2530
|
updateListboxPosition() {
|
|
2409
2531
|
if (!this._listboxElement || !this._triggerElement) return;
|
|
2410
|
-
const
|
|
2532
|
+
const t = this._triggerElement.getBoundingClientRect(), e = window.innerHeight, i = Math.min(this._listboxElement.scrollHeight, 200), s = e - t.bottom, a = t.top;
|
|
2411
2533
|
s < i + 8 && a > s ? (this._listboxElement.style.top = "auto", this._listboxElement.style.bottom = "100%", this._listboxElement.style.marginTop = "0", this._listboxElement.style.marginBottom = "4px", this.setAttribute("data-position", "top")) : (this._listboxElement.style.top = "100%", this._listboxElement.style.bottom = "auto", this._listboxElement.style.marginTop = "4px", this._listboxElement.style.marginBottom = "0", this.setAttribute("data-position", "bottom"));
|
|
2412
2534
|
}
|
|
2413
2535
|
/** Programmatic open */
|
|
@@ -2419,15 +2541,15 @@ class j extends c {
|
|
|
2419
2541
|
this.open = !1;
|
|
2420
2542
|
}
|
|
2421
2543
|
}
|
|
2422
|
-
|
|
2423
|
-
class
|
|
2544
|
+
c("a11y-select", Y);
|
|
2545
|
+
class G extends d {
|
|
2424
2546
|
constructor() {
|
|
2425
|
-
super(...arguments), this._value = "", this._inputEl = null, this._labelEl = null, this._hintEl = null, this._errorEl = null, this.handleInput = (
|
|
2426
|
-
const
|
|
2427
|
-
this._value =
|
|
2428
|
-
}, this.handleChange = (
|
|
2429
|
-
const
|
|
2430
|
-
this._value =
|
|
2547
|
+
super(...arguments), this._value = "", this._inputEl = null, this._labelEl = null, this._hintEl = null, this._errorEl = null, this.handleInput = (t) => {
|
|
2548
|
+
const e = t.target;
|
|
2549
|
+
this._value = e.value, this.emit("input", { value: this._value });
|
|
2550
|
+
}, this.handleChange = (t) => {
|
|
2551
|
+
const e = t.target;
|
|
2552
|
+
this._value = e.value, this.emit("change", { value: this._value });
|
|
2431
2553
|
}, this.handleFocus = () => {
|
|
2432
2554
|
this.emit("a11y-input-focus");
|
|
2433
2555
|
}, this.handleBlur = () => {
|
|
@@ -2461,91 +2583,91 @@ class U extends c {
|
|
|
2461
2583
|
get value() {
|
|
2462
2584
|
return this._value;
|
|
2463
2585
|
}
|
|
2464
|
-
set value(
|
|
2465
|
-
const
|
|
2466
|
-
this._value =
|
|
2586
|
+
set value(t) {
|
|
2587
|
+
const e = this._value;
|
|
2588
|
+
this._value = t, this._inputEl && this._inputEl.value !== t && (this._inputEl.value = t), t !== e && this.setAttribute("value", t);
|
|
2467
2589
|
}
|
|
2468
2590
|
get disabled() {
|
|
2469
2591
|
return this.hasAttribute("disabled");
|
|
2470
2592
|
}
|
|
2471
|
-
set disabled(
|
|
2472
|
-
this.toggleAttribute("disabled",
|
|
2593
|
+
set disabled(t) {
|
|
2594
|
+
this.toggleAttribute("disabled", t);
|
|
2473
2595
|
}
|
|
2474
2596
|
get readOnly() {
|
|
2475
2597
|
return this.hasAttribute("readonly");
|
|
2476
2598
|
}
|
|
2477
|
-
set readOnly(
|
|
2478
|
-
this.toggleAttribute("readonly",
|
|
2599
|
+
set readOnly(t) {
|
|
2600
|
+
this.toggleAttribute("readonly", t);
|
|
2479
2601
|
}
|
|
2480
2602
|
get required() {
|
|
2481
2603
|
return this.hasAttribute("required");
|
|
2482
2604
|
}
|
|
2483
|
-
set required(
|
|
2484
|
-
this.toggleAttribute("required",
|
|
2605
|
+
set required(t) {
|
|
2606
|
+
this.toggleAttribute("required", t);
|
|
2485
2607
|
}
|
|
2486
2608
|
get error() {
|
|
2487
2609
|
return this.getAttribute("error") || "";
|
|
2488
2610
|
}
|
|
2489
|
-
set error(
|
|
2490
|
-
|
|
2611
|
+
set error(t) {
|
|
2612
|
+
t ? this.setAttribute("error", t) : this.removeAttribute("error");
|
|
2491
2613
|
}
|
|
2492
2614
|
// =========================================================================
|
|
2493
2615
|
// Lifecycle
|
|
2494
2616
|
// =========================================================================
|
|
2495
2617
|
setupAccessibility() {
|
|
2496
|
-
var
|
|
2497
|
-
typeof process < "u" && ((
|
|
2618
|
+
var t;
|
|
2619
|
+
typeof process < "u" && ((t = process.env) == null ? void 0 : t.NODE_ENV) !== "production" && (this.hasAttribute("label") || this.hasAttribute("aria-label") || this.hasAttribute("aria-labelledby") || console.warn(
|
|
2498
2620
|
`[compa11y/Input] Input has no accessible label. Add label="...", aria-label="...", or aria-labelledby="..." attribute.
|
|
2499
2621
|
💡 Suggestion: <a11y-input label="Full Name"></a11y-input>`
|
|
2500
2622
|
));
|
|
2501
2623
|
}
|
|
2502
2624
|
render() {
|
|
2503
|
-
const
|
|
2504
|
-
l &&
|
|
2505
|
-
const
|
|
2506
|
-
this.setAttribute("data-error",
|
|
2507
|
-
<style>${
|
|
2625
|
+
const t = this.attachShadow({ mode: "open" }), e = `${this._id}-field`, i = `${this._id}-label`, s = `${this._id}-hint`, a = `${this._id}-error`, r = this.getAttribute("label") || "", l = this.getAttribute("hint") || "", o = this.getAttribute("error") || "", b = this.getAttribute("type") || "text", h = this.getAttribute("placeholder") || "", m = this.getAttribute("name") || "", g = this.getAttribute("autocomplete") || "", f = this.getAttribute("maxlength"), _ = this.getAttribute("minlength"), k = this.getAttribute("pattern"), w = this.getAttribute("inputmode"), S = this.getAttribute("aria-label") || "", I = this.getAttribute("aria-labelledby") || "", C = this.disabled, x = this.readOnly, y = this.required, E = !!o, A = [];
|
|
2626
|
+
l && A.push(s), E && A.push(a);
|
|
2627
|
+
const z = A.length ? `aria-describedby="${A.join(" ")}"` : "", $ = !r && S ? `aria-label="${S}"` : "", st = !r && I ? `aria-labelledby="${I}"` : r ? `aria-labelledby="${i}"` : "";
|
|
2628
|
+
this.setAttribute("data-error", E ? "true" : "false"), t.innerHTML = `
|
|
2629
|
+
<style>${$t}</style>
|
|
2508
2630
|
<div class="input-wrapper" part="wrapper">
|
|
2509
|
-
${r ? `<label id="${i}" for="${
|
|
2631
|
+
${r ? `<label id="${i}" for="${e}" class="input-label" part="label">
|
|
2510
2632
|
${r}${y ? '<span class="input-required" aria-hidden="true" part="required">*</span>' : ""}
|
|
2511
2633
|
</label>` : ""}
|
|
2512
2634
|
<input
|
|
2513
|
-
id="${
|
|
2514
|
-
type="${
|
|
2635
|
+
id="${e}"
|
|
2636
|
+
type="${b}"
|
|
2515
2637
|
value="${this._value}"
|
|
2516
2638
|
${h ? `placeholder="${h}"` : ""}
|
|
2517
|
-
${
|
|
2518
|
-
${
|
|
2639
|
+
${m ? `name="${m}"` : ""}
|
|
2640
|
+
${g ? `autocomplete="${g}"` : ""}
|
|
2519
2641
|
${f ? `maxlength="${f}"` : ""}
|
|
2520
2642
|
${_ ? `minlength="${_}"` : ""}
|
|
2521
2643
|
${k ? `pattern="${k}"` : ""}
|
|
2522
2644
|
${w ? `inputmode="${w}"` : ""}
|
|
2523
2645
|
${$}
|
|
2524
|
-
${
|
|
2525
|
-
${
|
|
2526
|
-
${
|
|
2646
|
+
${st}
|
|
2647
|
+
${z}
|
|
2648
|
+
${E ? 'aria-invalid="true"' : ""}
|
|
2527
2649
|
${y ? 'aria-required="true"' : ""}
|
|
2528
|
-
${
|
|
2650
|
+
${C ? "disabled" : ""}
|
|
2529
2651
|
${x ? "readonly" : ""}
|
|
2530
2652
|
part="field"
|
|
2531
2653
|
/>
|
|
2532
2654
|
${l ? `<div id="${s}" class="input-hint" part="hint">${l}</div>` : ""}
|
|
2533
|
-
${
|
|
2655
|
+
${E ? `<div id="${a}" class="input-error" role="alert" part="error">${o}</div>` : ""}
|
|
2534
2656
|
</div>
|
|
2535
|
-
`, this._inputEl =
|
|
2536
|
-
const
|
|
2537
|
-
|
|
2657
|
+
`, this._inputEl = t.querySelector("input"), this._labelEl = t.querySelector("label"), this._hintEl = t.querySelector(".input-hint"), this._errorEl = t.querySelector(".input-error");
|
|
2658
|
+
const D = this.getAttribute("value");
|
|
2659
|
+
D && this._inputEl && (this._value = D, this._inputEl.value = D);
|
|
2538
2660
|
}
|
|
2539
2661
|
setupEventListeners() {
|
|
2540
|
-
var
|
|
2541
|
-
(
|
|
2662
|
+
var t, e, i, s;
|
|
2663
|
+
(t = this._inputEl) == null || t.addEventListener("input", this.handleInput), (e = this._inputEl) == null || e.addEventListener("change", this.handleChange), (i = this._inputEl) == null || i.addEventListener("focus", this.handleFocus), (s = this._inputEl) == null || s.addEventListener("blur", this.handleBlur);
|
|
2542
2664
|
}
|
|
2543
2665
|
cleanupEventListeners() {
|
|
2544
|
-
var
|
|
2545
|
-
(
|
|
2666
|
+
var t, e, i, s;
|
|
2667
|
+
(t = this._inputEl) == null || t.removeEventListener("input", this.handleInput), (e = this._inputEl) == null || e.removeEventListener("change", this.handleChange), (i = this._inputEl) == null || i.removeEventListener("focus", this.handleFocus), (s = this._inputEl) == null || s.removeEventListener("blur", this.handleBlur);
|
|
2546
2668
|
}
|
|
2547
|
-
onAttributeChange(
|
|
2548
|
-
switch (
|
|
2669
|
+
onAttributeChange(t, e, i) {
|
|
2670
|
+
switch (t) {
|
|
2549
2671
|
case "value":
|
|
2550
2672
|
this._value = i || "", this._inputEl && this._inputEl.value !== this._value && (this._inputEl.value = this._value);
|
|
2551
2673
|
break;
|
|
@@ -2598,31 +2720,31 @@ class U extends c {
|
|
|
2598
2720
|
// =========================================================================
|
|
2599
2721
|
// DOM update helpers
|
|
2600
2722
|
// =========================================================================
|
|
2601
|
-
updateError(
|
|
2723
|
+
updateError(t) {
|
|
2602
2724
|
var i;
|
|
2603
|
-
const
|
|
2604
|
-
if (this.setAttribute("data-error",
|
|
2725
|
+
const e = !!t;
|
|
2726
|
+
if (this.setAttribute("data-error", e ? "true" : "false"), this._inputEl && (e ? this._inputEl.setAttribute("aria-invalid", "true") : this._inputEl.removeAttribute("aria-invalid")), e) {
|
|
2605
2727
|
if (this._errorEl)
|
|
2606
|
-
this._errorEl.textContent =
|
|
2728
|
+
this._errorEl.textContent = t;
|
|
2607
2729
|
else {
|
|
2608
2730
|
const s = `${this._id}-error`, a = document.createElement("div");
|
|
2609
|
-
a.id = s, a.className = "input-error", a.setAttribute("role", "alert"), a.setAttribute("part", "error"), a.textContent =
|
|
2731
|
+
a.id = s, a.className = "input-error", a.setAttribute("role", "alert"), a.setAttribute("part", "error"), a.textContent = t;
|
|
2610
2732
|
const r = (i = this.shadowRoot) == null ? void 0 : i.querySelector(".input-wrapper");
|
|
2611
|
-
r == null || r.appendChild(a), this._errorEl = a,
|
|
2733
|
+
r == null || r.appendChild(a), this._errorEl = a, O(t);
|
|
2612
2734
|
}
|
|
2613
2735
|
this.updateAriaDescribedBy();
|
|
2614
2736
|
} else
|
|
2615
2737
|
this._errorEl && (this._errorEl.remove(), this._errorEl = null), this.updateAriaDescribedBy();
|
|
2616
2738
|
}
|
|
2617
|
-
updateHint(
|
|
2618
|
-
var
|
|
2619
|
-
if (
|
|
2739
|
+
updateHint(t) {
|
|
2740
|
+
var e;
|
|
2741
|
+
if (t)
|
|
2620
2742
|
if (this._hintEl)
|
|
2621
|
-
this._hintEl.textContent =
|
|
2743
|
+
this._hintEl.textContent = t;
|
|
2622
2744
|
else {
|
|
2623
2745
|
const i = `${this._id}-hint`, s = document.createElement("div");
|
|
2624
|
-
s.id = i, s.className = "input-hint", s.setAttribute("part", "hint"), s.textContent =
|
|
2625
|
-
const a = (
|
|
2746
|
+
s.id = i, s.className = "input-hint", s.setAttribute("part", "hint"), s.textContent = t;
|
|
2747
|
+
const a = (e = this.shadowRoot) == null ? void 0 : e.querySelector(".input-wrapper");
|
|
2626
2748
|
this._errorEl ? a == null || a.insertBefore(s, this._errorEl) : a == null || a.appendChild(s), this._hintEl = s;
|
|
2627
2749
|
}
|
|
2628
2750
|
else
|
|
@@ -2631,45 +2753,45 @@ class U extends c {
|
|
|
2631
2753
|
}
|
|
2632
2754
|
updateAriaDescribedBy() {
|
|
2633
2755
|
if (!this._inputEl) return;
|
|
2634
|
-
const
|
|
2635
|
-
this._hintEl &&
|
|
2756
|
+
const t = [];
|
|
2757
|
+
this._hintEl && t.push(this._hintEl.id), this._errorEl && t.push(this._errorEl.id), t.length > 0 ? this._inputEl.setAttribute("aria-describedby", t.join(" ")) : this._inputEl.removeAttribute("aria-describedby");
|
|
2636
2758
|
}
|
|
2637
|
-
updateRequiredIndicator(
|
|
2759
|
+
updateRequiredIndicator(t) {
|
|
2638
2760
|
if (!this._labelEl) return;
|
|
2639
|
-
const
|
|
2640
|
-
if (
|
|
2761
|
+
const e = this._labelEl.querySelector(".input-required");
|
|
2762
|
+
if (t && !e) {
|
|
2641
2763
|
const i = document.createElement("span");
|
|
2642
2764
|
i.className = "input-required", i.setAttribute("aria-hidden", "true"), i.setAttribute("part", "required"), i.textContent = "*", this._labelEl.appendChild(i);
|
|
2643
|
-
} else !
|
|
2765
|
+
} else !t && e && e.remove();
|
|
2644
2766
|
}
|
|
2645
2767
|
// =========================================================================
|
|
2646
2768
|
// Public methods
|
|
2647
2769
|
// =========================================================================
|
|
2648
2770
|
/** Focus the input element */
|
|
2649
2771
|
focus() {
|
|
2650
|
-
var
|
|
2651
|
-
(
|
|
2772
|
+
var t;
|
|
2773
|
+
(t = this._inputEl) == null || t.focus();
|
|
2652
2774
|
}
|
|
2653
2775
|
/** Blur the input element */
|
|
2654
2776
|
blur() {
|
|
2655
|
-
var
|
|
2656
|
-
(
|
|
2777
|
+
var t;
|
|
2778
|
+
(t = this._inputEl) == null || t.blur();
|
|
2657
2779
|
}
|
|
2658
2780
|
/** Select all text in the input */
|
|
2659
2781
|
select() {
|
|
2660
|
-
var
|
|
2661
|
-
(
|
|
2782
|
+
var t;
|
|
2783
|
+
(t = this._inputEl) == null || t.select();
|
|
2662
2784
|
}
|
|
2663
2785
|
}
|
|
2664
|
-
|
|
2665
|
-
class
|
|
2786
|
+
c("a11y-input", G);
|
|
2787
|
+
class V extends d {
|
|
2666
2788
|
constructor() {
|
|
2667
|
-
super(...arguments), this._value = "", this._textareaEl = null, this._labelEl = null, this._hintEl = null, this._errorEl = null, this.handleInput = (
|
|
2668
|
-
const
|
|
2669
|
-
this._value =
|
|
2670
|
-
}, this.handleChange = (
|
|
2671
|
-
const
|
|
2672
|
-
this._value =
|
|
2789
|
+
super(...arguments), this._value = "", this._textareaEl = null, this._labelEl = null, this._hintEl = null, this._errorEl = null, this.handleInput = (t) => {
|
|
2790
|
+
const e = t.target;
|
|
2791
|
+
this._value = e.value, this.emit("input", { value: this._value });
|
|
2792
|
+
}, this.handleChange = (t) => {
|
|
2793
|
+
const e = t.target;
|
|
2794
|
+
this._value = e.value, this.emit("change", { value: this._value });
|
|
2673
2795
|
}, this.handleFocus = () => {
|
|
2674
2796
|
this.emit("a11y-textarea-focus");
|
|
2675
2797
|
}, this.handleBlur = () => {
|
|
@@ -2702,88 +2824,88 @@ class Y extends c {
|
|
|
2702
2824
|
get value() {
|
|
2703
2825
|
return this._value;
|
|
2704
2826
|
}
|
|
2705
|
-
set value(
|
|
2706
|
-
const
|
|
2707
|
-
this._value =
|
|
2827
|
+
set value(t) {
|
|
2828
|
+
const e = this._value;
|
|
2829
|
+
this._value = t, this._textareaEl && this._textareaEl.value !== t && (this._textareaEl.value = t), t !== e && this.setAttribute("value", t);
|
|
2708
2830
|
}
|
|
2709
2831
|
get disabled() {
|
|
2710
2832
|
return this.hasAttribute("disabled");
|
|
2711
2833
|
}
|
|
2712
|
-
set disabled(
|
|
2713
|
-
this.toggleAttribute("disabled",
|
|
2834
|
+
set disabled(t) {
|
|
2835
|
+
this.toggleAttribute("disabled", t);
|
|
2714
2836
|
}
|
|
2715
2837
|
get readOnly() {
|
|
2716
2838
|
return this.hasAttribute("readonly");
|
|
2717
2839
|
}
|
|
2718
|
-
set readOnly(
|
|
2719
|
-
this.toggleAttribute("readonly",
|
|
2840
|
+
set readOnly(t) {
|
|
2841
|
+
this.toggleAttribute("readonly", t);
|
|
2720
2842
|
}
|
|
2721
2843
|
get required() {
|
|
2722
2844
|
return this.hasAttribute("required");
|
|
2723
2845
|
}
|
|
2724
|
-
set required(
|
|
2725
|
-
this.toggleAttribute("required",
|
|
2846
|
+
set required(t) {
|
|
2847
|
+
this.toggleAttribute("required", t);
|
|
2726
2848
|
}
|
|
2727
2849
|
get error() {
|
|
2728
2850
|
return this.getAttribute("error") || "";
|
|
2729
2851
|
}
|
|
2730
|
-
set error(
|
|
2731
|
-
|
|
2852
|
+
set error(t) {
|
|
2853
|
+
t ? this.setAttribute("error", t) : this.removeAttribute("error");
|
|
2732
2854
|
}
|
|
2733
2855
|
// =========================================================================
|
|
2734
2856
|
// Lifecycle
|
|
2735
2857
|
// =========================================================================
|
|
2736
2858
|
setupAccessibility() {
|
|
2737
|
-
var
|
|
2738
|
-
typeof process < "u" && ((
|
|
2859
|
+
var t;
|
|
2860
|
+
typeof process < "u" && ((t = process.env) == null ? void 0 : t.NODE_ENV) !== "production" && (this.hasAttribute("label") || this.hasAttribute("aria-label") || this.hasAttribute("aria-labelledby") || console.warn(
|
|
2739
2861
|
`[compa11y/Textarea] Textarea has no accessible label. Add label="...", aria-label="...", or aria-labelledby="..." attribute.
|
|
2740
2862
|
💡 Suggestion: <a11y-textarea label="Description"></a11y-textarea>`
|
|
2741
2863
|
));
|
|
2742
2864
|
}
|
|
2743
2865
|
render() {
|
|
2744
|
-
const
|
|
2866
|
+
const t = this.attachShadow({ mode: "open" }), e = `${this._id}-field`, i = `${this._id}-label`, s = `${this._id}-hint`, a = `${this._id}-error`, r = this.getAttribute("label") || "", l = this.getAttribute("hint") || "", o = this.getAttribute("error") || "", b = this.getAttribute("rows") || "3", h = this.getAttribute("placeholder") || "", m = this.getAttribute("name") || "", g = this.getAttribute("autocomplete") || "", f = this.getAttribute("maxlength"), _ = this.getAttribute("minlength"), k = this.getAttribute("aria-label") || "", w = this.getAttribute("aria-labelledby") || "", S = this.disabled, I = this.readOnly, C = this.required, x = !!o, y = [];
|
|
2745
2867
|
l && y.push(s), x && y.push(a);
|
|
2746
|
-
const
|
|
2747
|
-
this.setAttribute("data-error", x ? "true" : "false"),
|
|
2748
|
-
<style>${
|
|
2868
|
+
const E = y.length ? `aria-describedby="${y.join(" ")}"` : "", A = !r && k ? `aria-label="${k}"` : "", z = !r && w ? `aria-labelledby="${w}"` : r ? `aria-labelledby="${i}"` : "";
|
|
2869
|
+
this.setAttribute("data-error", x ? "true" : "false"), t.innerHTML = `
|
|
2870
|
+
<style>${Lt}</style>
|
|
2749
2871
|
<div class="textarea-wrapper" part="wrapper">
|
|
2750
|
-
${r ? `<label id="${i}" for="${
|
|
2751
|
-
${r}${
|
|
2872
|
+
${r ? `<label id="${i}" for="${e}" class="textarea-label" part="label">
|
|
2873
|
+
${r}${C ? '<span class="textarea-required" aria-hidden="true" part="required">*</span>' : ""}
|
|
2752
2874
|
</label>` : ""}
|
|
2753
2875
|
<textarea
|
|
2754
|
-
id="${
|
|
2755
|
-
rows="${
|
|
2876
|
+
id="${e}"
|
|
2877
|
+
rows="${b}"
|
|
2756
2878
|
${h ? `placeholder="${h}"` : ""}
|
|
2757
|
-
${
|
|
2758
|
-
${
|
|
2879
|
+
${m ? `name="${m}"` : ""}
|
|
2880
|
+
${g ? `autocomplete="${g}"` : ""}
|
|
2759
2881
|
${f ? `maxlength="${f}"` : ""}
|
|
2760
2882
|
${_ ? `minlength="${_}"` : ""}
|
|
2761
|
-
${E}
|
|
2762
|
-
${C}
|
|
2763
2883
|
${A}
|
|
2884
|
+
${z}
|
|
2885
|
+
${E}
|
|
2764
2886
|
${x ? 'aria-invalid="true"' : ""}
|
|
2765
|
-
${
|
|
2766
|
-
${
|
|
2767
|
-
${
|
|
2887
|
+
${C ? 'aria-required="true"' : ""}
|
|
2888
|
+
${S ? "disabled" : ""}
|
|
2889
|
+
${I ? "readonly" : ""}
|
|
2768
2890
|
part="field"
|
|
2769
2891
|
>${this._value}</textarea>
|
|
2770
2892
|
${l ? `<div id="${s}" class="textarea-hint" part="hint">${l}</div>` : ""}
|
|
2771
2893
|
${x ? `<div id="${a}" class="textarea-error" role="alert" part="error">${o}</div>` : ""}
|
|
2772
2894
|
</div>
|
|
2773
|
-
`, this._textareaEl =
|
|
2895
|
+
`, this._textareaEl = t.querySelector("textarea"), this._labelEl = t.querySelector("label"), this._hintEl = t.querySelector(".textarea-hint"), this._errorEl = t.querySelector(".textarea-error");
|
|
2774
2896
|
const $ = this.getAttribute("value");
|
|
2775
2897
|
$ && this._textareaEl && (this._value = $, this._textareaEl.value = $);
|
|
2776
2898
|
}
|
|
2777
2899
|
setupEventListeners() {
|
|
2778
|
-
var
|
|
2779
|
-
(
|
|
2900
|
+
var t, e, i, s;
|
|
2901
|
+
(t = this._textareaEl) == null || t.addEventListener("input", this.handleInput), (e = this._textareaEl) == null || e.addEventListener("change", this.handleChange), (i = this._textareaEl) == null || i.addEventListener("focus", this.handleFocus), (s = this._textareaEl) == null || s.addEventListener("blur", this.handleBlur);
|
|
2780
2902
|
}
|
|
2781
2903
|
cleanupEventListeners() {
|
|
2782
|
-
var
|
|
2783
|
-
(
|
|
2904
|
+
var t, e, i, s;
|
|
2905
|
+
(t = this._textareaEl) == null || t.removeEventListener("input", this.handleInput), (e = this._textareaEl) == null || e.removeEventListener("change", this.handleChange), (i = this._textareaEl) == null || i.removeEventListener("focus", this.handleFocus), (s = this._textareaEl) == null || s.removeEventListener("blur", this.handleBlur);
|
|
2784
2906
|
}
|
|
2785
|
-
onAttributeChange(
|
|
2786
|
-
switch (
|
|
2907
|
+
onAttributeChange(t, e, i) {
|
|
2908
|
+
switch (t) {
|
|
2787
2909
|
case "value":
|
|
2788
2910
|
this._value = i || "", this._textareaEl && this._textareaEl.value !== this._value && (this._textareaEl.value = this._value);
|
|
2789
2911
|
break;
|
|
@@ -2833,31 +2955,31 @@ class Y extends c {
|
|
|
2833
2955
|
// =========================================================================
|
|
2834
2956
|
// DOM update helpers
|
|
2835
2957
|
// =========================================================================
|
|
2836
|
-
updateError(
|
|
2958
|
+
updateError(t) {
|
|
2837
2959
|
var i;
|
|
2838
|
-
const
|
|
2839
|
-
if (this.setAttribute("data-error",
|
|
2960
|
+
const e = !!t;
|
|
2961
|
+
if (this.setAttribute("data-error", e ? "true" : "false"), this._textareaEl && (e ? this._textareaEl.setAttribute("aria-invalid", "true") : this._textareaEl.removeAttribute("aria-invalid")), e) {
|
|
2840
2962
|
if (this._errorEl)
|
|
2841
|
-
this._errorEl.textContent =
|
|
2963
|
+
this._errorEl.textContent = t;
|
|
2842
2964
|
else {
|
|
2843
2965
|
const s = `${this._id}-error`, a = document.createElement("div");
|
|
2844
|
-
a.id = s, a.className = "textarea-error", a.setAttribute("role", "alert"), a.setAttribute("part", "error"), a.textContent =
|
|
2966
|
+
a.id = s, a.className = "textarea-error", a.setAttribute("role", "alert"), a.setAttribute("part", "error"), a.textContent = t;
|
|
2845
2967
|
const r = (i = this.shadowRoot) == null ? void 0 : i.querySelector(".textarea-wrapper");
|
|
2846
|
-
r == null || r.appendChild(a), this._errorEl = a,
|
|
2968
|
+
r == null || r.appendChild(a), this._errorEl = a, O(t);
|
|
2847
2969
|
}
|
|
2848
2970
|
this.updateAriaDescribedBy();
|
|
2849
2971
|
} else
|
|
2850
2972
|
this._errorEl && (this._errorEl.remove(), this._errorEl = null), this.updateAriaDescribedBy();
|
|
2851
2973
|
}
|
|
2852
|
-
updateHint(
|
|
2853
|
-
var
|
|
2854
|
-
if (
|
|
2974
|
+
updateHint(t) {
|
|
2975
|
+
var e;
|
|
2976
|
+
if (t)
|
|
2855
2977
|
if (this._hintEl)
|
|
2856
|
-
this._hintEl.textContent =
|
|
2978
|
+
this._hintEl.textContent = t;
|
|
2857
2979
|
else {
|
|
2858
2980
|
const i = `${this._id}-hint`, s = document.createElement("div");
|
|
2859
|
-
s.id = i, s.className = "textarea-hint", s.setAttribute("part", "hint"), s.textContent =
|
|
2860
|
-
const a = (
|
|
2981
|
+
s.id = i, s.className = "textarea-hint", s.setAttribute("part", "hint"), s.textContent = t;
|
|
2982
|
+
const a = (e = this.shadowRoot) == null ? void 0 : e.querySelector(".textarea-wrapper");
|
|
2861
2983
|
this._errorEl ? a == null || a.insertBefore(s, this._errorEl) : a == null || a.appendChild(s), this._hintEl = s;
|
|
2862
2984
|
}
|
|
2863
2985
|
else
|
|
@@ -2866,42 +2988,42 @@ class Y extends c {
|
|
|
2866
2988
|
}
|
|
2867
2989
|
updateAriaDescribedBy() {
|
|
2868
2990
|
if (!this._textareaEl) return;
|
|
2869
|
-
const
|
|
2870
|
-
this._hintEl &&
|
|
2991
|
+
const t = [];
|
|
2992
|
+
this._hintEl && t.push(this._hintEl.id), this._errorEl && t.push(this._errorEl.id), t.length > 0 ? this._textareaEl.setAttribute("aria-describedby", t.join(" ")) : this._textareaEl.removeAttribute("aria-describedby");
|
|
2871
2993
|
}
|
|
2872
|
-
updateRequiredIndicator(
|
|
2994
|
+
updateRequiredIndicator(t) {
|
|
2873
2995
|
if (!this._labelEl) return;
|
|
2874
|
-
const
|
|
2875
|
-
if (
|
|
2996
|
+
const e = this._labelEl.querySelector(".textarea-required");
|
|
2997
|
+
if (t && !e) {
|
|
2876
2998
|
const i = document.createElement("span");
|
|
2877
2999
|
i.className = "textarea-required", i.setAttribute("aria-hidden", "true"), i.setAttribute("part", "required"), i.textContent = "*", this._labelEl.appendChild(i);
|
|
2878
|
-
} else !
|
|
3000
|
+
} else !t && e && e.remove();
|
|
2879
3001
|
}
|
|
2880
3002
|
// =========================================================================
|
|
2881
3003
|
// Public methods
|
|
2882
3004
|
// =========================================================================
|
|
2883
3005
|
/** Focus the textarea element */
|
|
2884
3006
|
focus() {
|
|
2885
|
-
var
|
|
2886
|
-
(
|
|
3007
|
+
var t;
|
|
3008
|
+
(t = this._textareaEl) == null || t.focus();
|
|
2887
3009
|
}
|
|
2888
3010
|
/** Blur the textarea element */
|
|
2889
3011
|
blur() {
|
|
2890
|
-
var
|
|
2891
|
-
(
|
|
3012
|
+
var t;
|
|
3013
|
+
(t = this._textareaEl) == null || t.blur();
|
|
2892
3014
|
}
|
|
2893
3015
|
/** Select all text in the textarea */
|
|
2894
3016
|
select() {
|
|
2895
|
-
var
|
|
2896
|
-
(
|
|
3017
|
+
var t;
|
|
3018
|
+
(t = this._textareaEl) == null || t.select();
|
|
2897
3019
|
}
|
|
2898
3020
|
}
|
|
2899
|
-
|
|
2900
|
-
class
|
|
3021
|
+
c("a11y-textarea", V);
|
|
3022
|
+
class X extends d {
|
|
2901
3023
|
constructor() {
|
|
2902
|
-
super(...arguments), this._buttonEl = null, this.handleClick = (
|
|
3024
|
+
super(...arguments), this._buttonEl = null, this.handleClick = (t) => {
|
|
2903
3025
|
if (this.disabled || this.loading) {
|
|
2904
|
-
|
|
3026
|
+
t.preventDefault(), t.stopPropagation();
|
|
2905
3027
|
return;
|
|
2906
3028
|
}
|
|
2907
3029
|
this.emit("a11y-button-click");
|
|
@@ -2924,68 +3046,68 @@ class G extends c {
|
|
|
2924
3046
|
get disabled() {
|
|
2925
3047
|
return this.hasAttribute("disabled");
|
|
2926
3048
|
}
|
|
2927
|
-
set disabled(
|
|
2928
|
-
this.toggleAttribute("disabled",
|
|
3049
|
+
set disabled(t) {
|
|
3050
|
+
this.toggleAttribute("disabled", t);
|
|
2929
3051
|
}
|
|
2930
3052
|
get discoverable() {
|
|
2931
3053
|
return this.hasAttribute("discoverable");
|
|
2932
3054
|
}
|
|
2933
|
-
set discoverable(
|
|
2934
|
-
this.toggleAttribute("discoverable",
|
|
3055
|
+
set discoverable(t) {
|
|
3056
|
+
this.toggleAttribute("discoverable", t);
|
|
2935
3057
|
}
|
|
2936
3058
|
get loading() {
|
|
2937
3059
|
return this.hasAttribute("loading");
|
|
2938
3060
|
}
|
|
2939
|
-
set loading(
|
|
2940
|
-
this.toggleAttribute("loading",
|
|
3061
|
+
set loading(t) {
|
|
3062
|
+
this.toggleAttribute("loading", t);
|
|
2941
3063
|
}
|
|
2942
3064
|
get variant() {
|
|
2943
3065
|
return this.getAttribute("variant") || "secondary";
|
|
2944
3066
|
}
|
|
2945
|
-
set variant(
|
|
2946
|
-
this.setAttribute("variant",
|
|
3067
|
+
set variant(t) {
|
|
3068
|
+
this.setAttribute("variant", t);
|
|
2947
3069
|
}
|
|
2948
3070
|
get size() {
|
|
2949
3071
|
return this.getAttribute("size") || "md";
|
|
2950
3072
|
}
|
|
2951
|
-
set size(
|
|
2952
|
-
this.setAttribute("size",
|
|
3073
|
+
set size(t) {
|
|
3074
|
+
this.setAttribute("size", t);
|
|
2953
3075
|
}
|
|
2954
3076
|
// =========================================================================
|
|
2955
3077
|
// Lifecycle
|
|
2956
3078
|
// =========================================================================
|
|
2957
3079
|
setupAccessibility() {
|
|
2958
|
-
var
|
|
2959
|
-
typeof process < "u" && ((
|
|
3080
|
+
var t, e;
|
|
3081
|
+
typeof process < "u" && ((t = process.env) == null ? void 0 : t.NODE_ENV) !== "production" && ((e = this.textContent) != null && e.trim() || this.hasAttribute("aria-label") || this.hasAttribute("aria-labelledby") || console.warn(
|
|
2960
3082
|
`[compa11y/Button] Button has no accessible label. Add text content, aria-label="...", or aria-labelledby="..." attribute.
|
|
2961
3083
|
💡 Suggestion: <a11y-button>Click me</a11y-button>`
|
|
2962
3084
|
));
|
|
2963
3085
|
}
|
|
2964
3086
|
render() {
|
|
2965
|
-
const
|
|
2966
|
-
|
|
2967
|
-
<style>${
|
|
3087
|
+
const t = this.attachShadow({ mode: "open" }), e = this.variant, i = this.size, s = this.getAttribute("type") || "button", a = this.getAttribute("aria-label") || "", r = this.disabled, l = this.discoverable, o = this.loading, b = r || o, h = r && !l;
|
|
3088
|
+
t.innerHTML = `
|
|
3089
|
+
<style>${St}</style>
|
|
2968
3090
|
<button
|
|
2969
|
-
class="variant-${
|
|
3091
|
+
class="variant-${e} size-${i}"
|
|
2970
3092
|
type="${s}"
|
|
2971
3093
|
${h ? "disabled" : ""}
|
|
2972
|
-
${
|
|
3094
|
+
${b ? 'aria-disabled="true"' : ""}
|
|
2973
3095
|
${o ? 'aria-busy="true"' : ""}
|
|
2974
3096
|
${a ? `aria-label="${a}"` : ""}
|
|
2975
3097
|
part="button"
|
|
2976
3098
|
>${o ? '<span class="button-spinner" aria-hidden="true" part="spinner"></span>' : ""}<slot></slot></button>
|
|
2977
|
-
`, this._buttonEl =
|
|
3099
|
+
`, this._buttonEl = t.querySelector("button");
|
|
2978
3100
|
}
|
|
2979
3101
|
setupEventListeners() {
|
|
2980
|
-
var
|
|
2981
|
-
(
|
|
3102
|
+
var t;
|
|
3103
|
+
(t = this._buttonEl) == null || t.addEventListener("click", this.handleClick);
|
|
2982
3104
|
}
|
|
2983
3105
|
cleanupEventListeners() {
|
|
2984
|
-
var
|
|
2985
|
-
(
|
|
3106
|
+
var t;
|
|
3107
|
+
(t = this._buttonEl) == null || t.removeEventListener("click", this.handleClick);
|
|
2986
3108
|
}
|
|
2987
|
-
onAttributeChange(
|
|
2988
|
-
switch (
|
|
3109
|
+
onAttributeChange(t, e, i) {
|
|
3110
|
+
switch (t) {
|
|
2989
3111
|
case "variant": {
|
|
2990
3112
|
if (!this._buttonEl) break;
|
|
2991
3113
|
const a = this._buttonEl.className.split(" ").filter((r) => !r.startsWith("variant-"));
|
|
@@ -3018,20 +3140,20 @@ class G extends c {
|
|
|
3018
3140
|
// =========================================================================
|
|
3019
3141
|
updateDisabledState() {
|
|
3020
3142
|
if (!this._buttonEl) return;
|
|
3021
|
-
const
|
|
3143
|
+
const t = this.disabled, e = this.discoverable, i = this.loading, s = t && !e, a = t || i;
|
|
3022
3144
|
s ? this._buttonEl.setAttribute("disabled", "") : this._buttonEl.removeAttribute("disabled"), a ? this._buttonEl.setAttribute("aria-disabled", "true") : this._buttonEl.removeAttribute("aria-disabled");
|
|
3023
3145
|
}
|
|
3024
3146
|
updateLoadingState() {
|
|
3025
3147
|
if (!this._buttonEl) return;
|
|
3026
3148
|
if (this.loading) {
|
|
3027
3149
|
if (this._buttonEl.setAttribute("aria-busy", "true"), this._buttonEl.setAttribute("aria-disabled", "true"), !this._buttonEl.querySelector(".button-spinner")) {
|
|
3028
|
-
const
|
|
3029
|
-
|
|
3150
|
+
const e = document.createElement("span");
|
|
3151
|
+
e.className = "button-spinner", e.setAttribute("aria-hidden", "true"), e.setAttribute("part", "spinner"), this._buttonEl.insertBefore(e, this._buttonEl.firstChild);
|
|
3030
3152
|
}
|
|
3031
3153
|
} else {
|
|
3032
3154
|
this._buttonEl.removeAttribute("aria-busy");
|
|
3033
|
-
const
|
|
3034
|
-
|
|
3155
|
+
const e = this._buttonEl.querySelector(".button-spinner");
|
|
3156
|
+
e == null || e.remove(), this.updateDisabledState();
|
|
3035
3157
|
}
|
|
3036
3158
|
}
|
|
3037
3159
|
// =========================================================================
|
|
@@ -3039,22 +3161,22 @@ class G extends c {
|
|
|
3039
3161
|
// =========================================================================
|
|
3040
3162
|
/** Focus the button element */
|
|
3041
3163
|
focus() {
|
|
3042
|
-
var
|
|
3043
|
-
(
|
|
3164
|
+
var t;
|
|
3165
|
+
(t = this._buttonEl) == null || t.focus();
|
|
3044
3166
|
}
|
|
3045
3167
|
/** Blur the button element */
|
|
3046
3168
|
blur() {
|
|
3047
|
-
var
|
|
3048
|
-
(
|
|
3169
|
+
var t;
|
|
3170
|
+
(t = this._buttonEl) == null || t.blur();
|
|
3049
3171
|
}
|
|
3050
3172
|
/** Programmatically click the button */
|
|
3051
3173
|
click() {
|
|
3052
|
-
var
|
|
3053
|
-
(
|
|
3174
|
+
var t;
|
|
3175
|
+
(t = this._buttonEl) == null || t.click();
|
|
3054
3176
|
}
|
|
3055
3177
|
}
|
|
3056
|
-
|
|
3057
|
-
class
|
|
3178
|
+
c("a11y-button", X);
|
|
3179
|
+
class W extends d {
|
|
3058
3180
|
constructor() {
|
|
3059
3181
|
super(...arguments), this._label = "", this._disabled = !1;
|
|
3060
3182
|
}
|
|
@@ -3064,60 +3186,59 @@ class X extends c {
|
|
|
3064
3186
|
get label() {
|
|
3065
3187
|
return this._label;
|
|
3066
3188
|
}
|
|
3067
|
-
set label(
|
|
3068
|
-
this._label =
|
|
3189
|
+
set label(t) {
|
|
3190
|
+
this._label = t, this.setAttribute("label", t), this.updateLabel();
|
|
3069
3191
|
}
|
|
3070
3192
|
get disabled() {
|
|
3071
3193
|
return this._disabled;
|
|
3072
3194
|
}
|
|
3073
|
-
set disabled(
|
|
3074
|
-
const
|
|
3075
|
-
this._disabled !==
|
|
3195
|
+
set disabled(t) {
|
|
3196
|
+
const e = !!t;
|
|
3197
|
+
this._disabled !== e && (this._disabled = e, e ? (this.setAttribute("disabled", ""), this.setAttribute("aria-disabled", "true")) : (this.removeAttribute("disabled"), this.removeAttribute("aria-disabled")));
|
|
3076
3198
|
}
|
|
3077
3199
|
setupAccessibility() {
|
|
3078
3200
|
this.setAttribute("role", "group"), this._label = this.getAttribute("label") || "", this._disabled = this.hasAttribute("disabled"), this._disabled && this.setAttribute("aria-disabled", "true");
|
|
3079
3201
|
}
|
|
3080
3202
|
render() {
|
|
3081
3203
|
this.shadowRoot || this.attachShadow({ mode: "open" });
|
|
3082
|
-
const
|
|
3204
|
+
const t = `${this._id}-label`;
|
|
3083
3205
|
this.shadowRoot.innerHTML = `
|
|
3084
|
-
<style>${
|
|
3206
|
+
<style>${Tt}</style>
|
|
3085
3207
|
<div class="optgroup-wrapper" part="group">
|
|
3086
|
-
<div class="optgroup-label" part="label" id="${
|
|
3208
|
+
<div class="optgroup-label" part="label" id="${t}" role="presentation">
|
|
3087
3209
|
${this._label}
|
|
3088
3210
|
</div>
|
|
3089
3211
|
<div class="optgroup-options" part="options" role="none">
|
|
3090
3212
|
<slot></slot>
|
|
3091
3213
|
</div>
|
|
3092
3214
|
</div>
|
|
3093
|
-
`, this.setAttribute("aria-labelledby",
|
|
3215
|
+
`, this.setAttribute("aria-labelledby", t);
|
|
3094
3216
|
}
|
|
3095
3217
|
setupEventListeners() {
|
|
3096
3218
|
}
|
|
3097
3219
|
cleanupEventListeners() {
|
|
3098
3220
|
}
|
|
3099
3221
|
updateLabel() {
|
|
3100
|
-
var
|
|
3101
|
-
const
|
|
3102
|
-
|
|
3222
|
+
var e;
|
|
3223
|
+
const t = (e = this.shadowRoot) == null ? void 0 : e.querySelector(".optgroup-label");
|
|
3224
|
+
t && (t.textContent = this._label);
|
|
3103
3225
|
}
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
}
|
|
3226
|
+
onAttributeChange(t, e, i) {
|
|
3227
|
+
switch (t) {
|
|
3228
|
+
case "label":
|
|
3229
|
+
this._label = i || "", this.updateLabel();
|
|
3230
|
+
break;
|
|
3231
|
+
case "disabled":
|
|
3232
|
+
this._disabled = i !== null, this._disabled ? this.setAttribute("aria-disabled", "true") : this.removeAttribute("aria-disabled");
|
|
3233
|
+
break;
|
|
3234
|
+
}
|
|
3114
3235
|
}
|
|
3115
3236
|
}
|
|
3116
|
-
class
|
|
3237
|
+
class J extends d {
|
|
3117
3238
|
constructor() {
|
|
3118
|
-
super(...arguments), this._value = "", this._disabled = !1, this._selected = !1, this._discoverable = !0, this.handleClick = (
|
|
3239
|
+
super(...arguments), this._value = "", this._disabled = !1, this._selected = !1, this._discoverable = !0, this.handleClick = (t) => {
|
|
3119
3240
|
if (this.effectivelyDisabled) {
|
|
3120
|
-
|
|
3241
|
+
t.preventDefault();
|
|
3121
3242
|
return;
|
|
3122
3243
|
}
|
|
3123
3244
|
this.dispatchEvent(
|
|
@@ -3135,45 +3256,45 @@ class V extends c {
|
|
|
3135
3256
|
get value() {
|
|
3136
3257
|
return this._value;
|
|
3137
3258
|
}
|
|
3138
|
-
set value(
|
|
3139
|
-
this._value =
|
|
3259
|
+
set value(t) {
|
|
3260
|
+
this._value = t, this.setAttribute("value", t);
|
|
3140
3261
|
}
|
|
3141
3262
|
get disabled() {
|
|
3142
3263
|
return this._disabled;
|
|
3143
3264
|
}
|
|
3144
|
-
set disabled(
|
|
3145
|
-
const
|
|
3146
|
-
this._disabled !==
|
|
3265
|
+
set disabled(t) {
|
|
3266
|
+
const e = !!t;
|
|
3267
|
+
this._disabled !== e && (this._disabled = e, e ? (this.setAttribute("disabled", ""), this.setAttribute("aria-disabled", "true")) : (this.removeAttribute("disabled"), this.removeAttribute("aria-disabled")));
|
|
3147
3268
|
}
|
|
3148
3269
|
get selected() {
|
|
3149
3270
|
return this._selected;
|
|
3150
3271
|
}
|
|
3151
|
-
set selected(
|
|
3152
|
-
const
|
|
3153
|
-
this._selected !==
|
|
3272
|
+
set selected(t) {
|
|
3273
|
+
const e = !!t;
|
|
3274
|
+
this._selected !== e && (this._selected = e, this.setAttribute("aria-selected", String(e)));
|
|
3154
3275
|
}
|
|
3155
3276
|
get discoverable() {
|
|
3156
3277
|
return this._discoverable;
|
|
3157
3278
|
}
|
|
3158
|
-
set discoverable(
|
|
3159
|
-
this._discoverable = !!
|
|
3279
|
+
set discoverable(t) {
|
|
3280
|
+
this._discoverable = !!t;
|
|
3160
3281
|
}
|
|
3161
3282
|
/**
|
|
3162
3283
|
* Whether this option is effectively disabled (own disabled or group disabled)
|
|
3163
3284
|
*/
|
|
3164
3285
|
get effectivelyDisabled() {
|
|
3165
3286
|
if (this._disabled) return !0;
|
|
3166
|
-
const
|
|
3167
|
-
return (
|
|
3287
|
+
const t = this.closest("a11y-optgroup");
|
|
3288
|
+
return (t == null ? void 0 : t.disabled) ?? !1;
|
|
3168
3289
|
}
|
|
3169
3290
|
setupAccessibility() {
|
|
3170
3291
|
this.setAttribute("role", "option"), this.setAttribute("aria-selected", "false"), this._value = this.getAttribute("value") || "", this._disabled = this.hasAttribute("disabled"), this._disabled && this.setAttribute("aria-disabled", "true");
|
|
3171
|
-
const
|
|
3172
|
-
(
|
|
3292
|
+
const t = this.getAttribute("discoverable");
|
|
3293
|
+
(t === "false" || t === "0") && (this._discoverable = !1);
|
|
3173
3294
|
}
|
|
3174
3295
|
render() {
|
|
3175
3296
|
this.shadowRoot || this.attachShadow({ mode: "open" }), this.shadowRoot.innerHTML = `
|
|
3176
|
-
<style>${
|
|
3297
|
+
<style>${Ct}</style>
|
|
3177
3298
|
<div class="option-wrapper" part="option">
|
|
3178
3299
|
<span class="option-content" part="content"><slot></slot></span>
|
|
3179
3300
|
<span class="check-mark" part="check" aria-hidden="true">✓</span>
|
|
@@ -3186,92 +3307,91 @@ class V extends c {
|
|
|
3186
3307
|
cleanupEventListeners() {
|
|
3187
3308
|
this.removeEventListener("click", this.handleClick);
|
|
3188
3309
|
}
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
}
|
|
3310
|
+
onAttributeChange(t, e, i) {
|
|
3311
|
+
switch (t) {
|
|
3312
|
+
case "value":
|
|
3313
|
+
this._value = i || "";
|
|
3314
|
+
break;
|
|
3315
|
+
case "disabled":
|
|
3316
|
+
this._disabled = i !== null, this._disabled ? this.setAttribute("aria-disabled", "true") : this.removeAttribute("aria-disabled");
|
|
3317
|
+
break;
|
|
3318
|
+
case "discoverable":
|
|
3319
|
+
i === null ? this._discoverable = !0 : i === "false" || i === "0" ? this._discoverable = !1 : this._discoverable = !0;
|
|
3320
|
+
break;
|
|
3321
|
+
}
|
|
3202
3322
|
}
|
|
3203
3323
|
}
|
|
3204
|
-
class
|
|
3324
|
+
class Q extends d {
|
|
3205
3325
|
constructor() {
|
|
3206
3326
|
super(...arguments), this._value = null, this._values = /* @__PURE__ */ new Set(), this._multiple = !1, this._disabled = !1, this._discoverable = !0, this._orientation = "vertical", this._focusedIndex = -1, this._typeAhead = null, this.handleFocus = () => {
|
|
3207
3327
|
if (this._focusedIndex >= 0) return;
|
|
3208
|
-
const
|
|
3328
|
+
const t = this.getAllOptions();
|
|
3209
3329
|
if (!this._multiple && this._value) {
|
|
3210
|
-
const
|
|
3211
|
-
if (
|
|
3212
|
-
this._focusedIndex =
|
|
3330
|
+
const e = t.findIndex((i) => i.value === this._value);
|
|
3331
|
+
if (e >= 0) {
|
|
3332
|
+
this._focusedIndex = e, this.updateFocusHighlight();
|
|
3213
3333
|
return;
|
|
3214
3334
|
}
|
|
3215
3335
|
} else if (this._multiple && this._values.size > 0) {
|
|
3216
|
-
const
|
|
3217
|
-
if (
|
|
3218
|
-
this._focusedIndex =
|
|
3336
|
+
const e = t.findIndex((i) => this._values.has(i.value));
|
|
3337
|
+
if (e >= 0) {
|
|
3338
|
+
this._focusedIndex = e, this.updateFocusHighlight();
|
|
3219
3339
|
return;
|
|
3220
3340
|
}
|
|
3221
3341
|
}
|
|
3222
3342
|
this._focusedIndex = this.findFirstEnabled(), this.updateFocusHighlight();
|
|
3223
|
-
}, this.handleOptionSelect = (
|
|
3343
|
+
}, this.handleOptionSelect = (t) => {
|
|
3224
3344
|
var r;
|
|
3225
3345
|
if (this._disabled) return;
|
|
3226
|
-
const
|
|
3227
|
-
if (
|
|
3228
|
-
const i = this.getAllOptions(), s = i.find((l) => l.value ===
|
|
3346
|
+
const e = (r = t.detail) == null ? void 0 : r.value;
|
|
3347
|
+
if (e === void 0) return;
|
|
3348
|
+
const i = this.getAllOptions(), s = i.find((l) => l.value === e);
|
|
3229
3349
|
if (!s) return;
|
|
3230
3350
|
const a = i.indexOf(s);
|
|
3231
3351
|
this._focusedIndex = a, this.updateFocusHighlight(), this.selectOption(s), this.focus();
|
|
3232
|
-
}, this.handleKeyDown = (
|
|
3352
|
+
}, this.handleKeyDown = (t) => {
|
|
3233
3353
|
var a, r, l;
|
|
3234
3354
|
if (this._disabled && !this._discoverable) return;
|
|
3235
|
-
const
|
|
3236
|
-
if (
|
|
3355
|
+
const e = this.getAllOptions();
|
|
3356
|
+
if (e.length === 0) return;
|
|
3237
3357
|
let i = null, s = !1;
|
|
3238
3358
|
if (this._multiple)
|
|
3239
|
-
switch (
|
|
3359
|
+
switch (t.key) {
|
|
3240
3360
|
case "ArrowDown":
|
|
3241
|
-
|
|
3361
|
+
t.shiftKey ? (i = this.findNextEnabled(this._focusedIndex, 1), i >= 0 && this.toggleOptionSelection(e[i])) : i = this.findNextEnabled(this._focusedIndex, 1), s = !0;
|
|
3242
3362
|
break;
|
|
3243
3363
|
case "ArrowUp":
|
|
3244
|
-
|
|
3364
|
+
t.shiftKey ? (i = this.findNextEnabled(this._focusedIndex, -1), i >= 0 && this.toggleOptionSelection(e[i])) : i = this.findNextEnabled(this._focusedIndex, -1), s = !0;
|
|
3245
3365
|
break;
|
|
3246
3366
|
case " ":
|
|
3247
|
-
this._focusedIndex >= 0 &&
|
|
3367
|
+
this._focusedIndex >= 0 && e[this._focusedIndex] != null && this.toggleOptionSelection(e[this._focusedIndex]), s = !0;
|
|
3248
3368
|
break;
|
|
3249
3369
|
case "Home":
|
|
3250
|
-
|
|
3370
|
+
t.ctrlKey && t.shiftKey ? (this.selectRange(this.findFirstEnabled(), this._focusedIndex), i = this.findFirstEnabled()) : i = this.findFirstEnabled(), s = !0;
|
|
3251
3371
|
break;
|
|
3252
3372
|
case "End":
|
|
3253
|
-
|
|
3373
|
+
t.ctrlKey && t.shiftKey ? (this.selectRange(this._focusedIndex, this.findLastEnabled()), i = this.findLastEnabled()) : i = this.findLastEnabled(), s = !0;
|
|
3254
3374
|
break;
|
|
3255
3375
|
case "a":
|
|
3256
|
-
(
|
|
3376
|
+
(t.ctrlKey || t.metaKey) && (this.toggleSelectAll(), s = !0);
|
|
3257
3377
|
break;
|
|
3258
3378
|
default:
|
|
3259
|
-
if (
|
|
3260
|
-
const o = (a = this._typeAhead) == null ? void 0 : a.type(
|
|
3379
|
+
if (t.key.length === 1 && !t.ctrlKey && !t.altKey && !t.metaKey) {
|
|
3380
|
+
const o = (a = this._typeAhead) == null ? void 0 : a.type(t.key);
|
|
3261
3381
|
if (o) {
|
|
3262
|
-
const
|
|
3382
|
+
const b = e.findIndex(
|
|
3263
3383
|
(h) => {
|
|
3264
|
-
var
|
|
3265
|
-
return (((
|
|
3384
|
+
var m;
|
|
3385
|
+
return (((m = h.textContent) == null ? void 0 : m.trim()) || "") === o && !h.effectivelyDisabled;
|
|
3266
3386
|
}
|
|
3267
3387
|
);
|
|
3268
|
-
|
|
3388
|
+
b >= 0 && (i = b, s = !0);
|
|
3269
3389
|
}
|
|
3270
3390
|
}
|
|
3271
3391
|
break;
|
|
3272
3392
|
}
|
|
3273
3393
|
else
|
|
3274
|
-
switch (
|
|
3394
|
+
switch (t.key) {
|
|
3275
3395
|
case "ArrowDown":
|
|
3276
3396
|
i = this.findNextEnabled(this._focusedIndex, 1), s = !0;
|
|
3277
3397
|
break;
|
|
@@ -3285,28 +3405,28 @@ class W extends c {
|
|
|
3285
3405
|
i = this.findLastEnabled(), s = !0;
|
|
3286
3406
|
break;
|
|
3287
3407
|
default:
|
|
3288
|
-
if (
|
|
3289
|
-
const o = (r = this._typeAhead) == null ? void 0 : r.type(
|
|
3408
|
+
if (t.key.length === 1 && !t.ctrlKey && !t.altKey && !t.metaKey) {
|
|
3409
|
+
const o = (r = this._typeAhead) == null ? void 0 : r.type(t.key);
|
|
3290
3410
|
if (o) {
|
|
3291
|
-
const
|
|
3411
|
+
const b = e.findIndex(
|
|
3292
3412
|
(h) => {
|
|
3293
|
-
var
|
|
3294
|
-
return (((
|
|
3413
|
+
var m;
|
|
3414
|
+
return (((m = h.textContent) == null ? void 0 : m.trim()) || "") === o && !h.effectivelyDisabled;
|
|
3295
3415
|
}
|
|
3296
3416
|
);
|
|
3297
|
-
|
|
3417
|
+
b >= 0 && (i = b, s = !0);
|
|
3298
3418
|
}
|
|
3299
3419
|
}
|
|
3300
3420
|
break;
|
|
3301
3421
|
}
|
|
3302
|
-
if (s && (
|
|
3422
|
+
if (s && (t.preventDefault(), t.stopPropagation()), i !== null && i >= 0) {
|
|
3303
3423
|
this._focusedIndex = i, this.updateFocusHighlight();
|
|
3304
|
-
const o =
|
|
3424
|
+
const o = e[i];
|
|
3305
3425
|
if (!this._multiple && o)
|
|
3306
3426
|
this.selectSingle(o);
|
|
3307
3427
|
else if (o) {
|
|
3308
|
-
const
|
|
3309
|
-
p(`${
|
|
3428
|
+
const b = ((l = o.textContent) == null ? void 0 : l.trim()) || o.value, h = this._values.has(o.value);
|
|
3429
|
+
p(`${b}${h ? ", selected" : ""}`);
|
|
3310
3430
|
}
|
|
3311
3431
|
}
|
|
3312
3432
|
};
|
|
@@ -3326,49 +3446,49 @@ class W extends c {
|
|
|
3326
3446
|
get value() {
|
|
3327
3447
|
return this._multiple ? Array.from(this._values) : this._value || "";
|
|
3328
3448
|
}
|
|
3329
|
-
set value(
|
|
3449
|
+
set value(t) {
|
|
3330
3450
|
if (this._multiple) {
|
|
3331
|
-
const
|
|
3332
|
-
this._values = new Set(
|
|
3451
|
+
const e = Array.isArray(t) ? t : String(t).split(",").filter(Boolean);
|
|
3452
|
+
this._values = new Set(e), this.setAttribute("value", e.join(","));
|
|
3333
3453
|
} else {
|
|
3334
|
-
const
|
|
3335
|
-
this._value =
|
|
3454
|
+
const e = Array.isArray(t) ? t[0] || "" : String(t);
|
|
3455
|
+
this._value = e, this.setAttribute("value", e);
|
|
3336
3456
|
}
|
|
3337
3457
|
this.syncOptionStates();
|
|
3338
3458
|
}
|
|
3339
3459
|
get multiple() {
|
|
3340
3460
|
return this._multiple;
|
|
3341
3461
|
}
|
|
3342
|
-
set multiple(
|
|
3343
|
-
const
|
|
3344
|
-
this._multiple !==
|
|
3462
|
+
set multiple(t) {
|
|
3463
|
+
const e = !!t;
|
|
3464
|
+
this._multiple !== e && (this._multiple = e, e ? (this.setAttribute("multiple", ""), this.setAttribute("aria-multiselectable", "true")) : (this.removeAttribute("multiple"), this.removeAttribute("aria-multiselectable")));
|
|
3345
3465
|
}
|
|
3346
3466
|
get disabled() {
|
|
3347
3467
|
return this._disabled;
|
|
3348
3468
|
}
|
|
3349
|
-
set disabled(
|
|
3350
|
-
const
|
|
3351
|
-
this._disabled !==
|
|
3469
|
+
set disabled(t) {
|
|
3470
|
+
const e = !!t;
|
|
3471
|
+
this._disabled !== e && (this._disabled = e, e ? (this.setAttribute("disabled", ""), this.setAttribute("aria-disabled", "true")) : (this.removeAttribute("disabled"), this.removeAttribute("aria-disabled")));
|
|
3352
3472
|
}
|
|
3353
3473
|
get discoverable() {
|
|
3354
3474
|
return this._discoverable;
|
|
3355
3475
|
}
|
|
3356
|
-
set discoverable(
|
|
3357
|
-
this._discoverable = !!
|
|
3476
|
+
set discoverable(t) {
|
|
3477
|
+
this._discoverable = !!t;
|
|
3358
3478
|
}
|
|
3359
3479
|
get orientation() {
|
|
3360
3480
|
return this._orientation;
|
|
3361
3481
|
}
|
|
3362
|
-
set orientation(
|
|
3363
|
-
this._orientation =
|
|
3482
|
+
set orientation(t) {
|
|
3483
|
+
this._orientation = t, this.setAttribute("orientation", t), this.setAttribute("aria-orientation", t);
|
|
3364
3484
|
}
|
|
3365
3485
|
// ===== Lifecycle =====
|
|
3366
3486
|
setupAccessibility() {
|
|
3367
3487
|
this.setAttribute("role", "listbox"), this.setAttribute("aria-orientation", this._orientation), !(this.hasAttribute("aria-label") || this.hasAttribute("aria-labelledby")) && process.env.NODE_ENV !== "production" && console.warn(
|
|
3368
3488
|
"[Compa11y Listbox]: Listbox has no accessible label. Use aria-label or aria-labelledby."
|
|
3369
3489
|
), this._multiple = this.hasAttribute("multiple"), this._multiple && this.setAttribute("aria-multiselectable", "true"), this._disabled = this.hasAttribute("disabled"), this._disabled && this.setAttribute("aria-disabled", "true");
|
|
3370
|
-
const
|
|
3371
|
-
(
|
|
3490
|
+
const e = this.getAttribute("orientation");
|
|
3491
|
+
(e === "horizontal" || e === "vertical") && (this._orientation = e);
|
|
3372
3492
|
const i = this.getAttribute("discoverable");
|
|
3373
3493
|
(i === "false" || i === "0") && (this._discoverable = !1);
|
|
3374
3494
|
const s = this.getAttribute("value");
|
|
@@ -3376,17 +3496,17 @@ class W extends c {
|
|
|
3376
3496
|
}
|
|
3377
3497
|
render() {
|
|
3378
3498
|
this.shadowRoot || this.attachShadow({ mode: "open" }), this.shadowRoot.innerHTML = `
|
|
3379
|
-
<style>${
|
|
3499
|
+
<style>${It}</style>
|
|
3380
3500
|
<div class="listbox-wrapper" part="wrapper">
|
|
3381
3501
|
<slot></slot>
|
|
3382
3502
|
</div>
|
|
3383
3503
|
`;
|
|
3384
3504
|
}
|
|
3385
3505
|
setupEventListeners() {
|
|
3386
|
-
var
|
|
3506
|
+
var e;
|
|
3387
3507
|
this.addEventListener("keydown", this.handleKeyDown), this.addEventListener("focus", this.handleFocus), this.addEventListener("option-select", this.handleOptionSelect);
|
|
3388
|
-
const
|
|
3389
|
-
|
|
3508
|
+
const t = (e = this.shadowRoot) == null ? void 0 : e.querySelector("slot");
|
|
3509
|
+
t && t.addEventListener("slotchange", () => {
|
|
3390
3510
|
this.rebuildTypeAhead(), this.syncOptionStates();
|
|
3391
3511
|
}), this.rebuildTypeAhead(), this.syncOptionStates();
|
|
3392
3512
|
}
|
|
@@ -3398,68 +3518,68 @@ class W extends c {
|
|
|
3398
3518
|
return Array.from(this.querySelectorAll("a11y-option"));
|
|
3399
3519
|
}
|
|
3400
3520
|
getEnabledOptions() {
|
|
3401
|
-
return this.getAllOptions().filter((
|
|
3521
|
+
return this.getAllOptions().filter((t) => !t.effectivelyDisabled);
|
|
3402
3522
|
}
|
|
3403
3523
|
getEnabledIndices() {
|
|
3404
|
-
const
|
|
3405
|
-
return
|
|
3406
|
-
i.effectivelyDisabled ||
|
|
3407
|
-
}),
|
|
3524
|
+
const t = this.getAllOptions(), e = [];
|
|
3525
|
+
return t.forEach((i, s) => {
|
|
3526
|
+
i.effectivelyDisabled || e.push(s);
|
|
3527
|
+
}), e;
|
|
3408
3528
|
}
|
|
3409
3529
|
// ===== State Sync =====
|
|
3410
3530
|
syncOptionStates() {
|
|
3411
|
-
this.getAllOptions().forEach((
|
|
3412
|
-
this._multiple ?
|
|
3531
|
+
this.getAllOptions().forEach((e) => {
|
|
3532
|
+
this._multiple ? e.selected = this._values.has(e.value) : e.selected = e.value === this._value;
|
|
3413
3533
|
});
|
|
3414
3534
|
}
|
|
3415
3535
|
updateFocusHighlight() {
|
|
3416
|
-
const
|
|
3417
|
-
|
|
3536
|
+
const t = this.getAllOptions();
|
|
3537
|
+
t.forEach((i, s) => {
|
|
3418
3538
|
s === this._focusedIndex ? i.toggleAttribute("data-focused", !0) : i.removeAttribute("data-focused");
|
|
3419
3539
|
});
|
|
3420
|
-
const
|
|
3421
|
-
|
|
3540
|
+
const e = this._focusedIndex >= 0 ? t[this._focusedIndex] : void 0;
|
|
3541
|
+
e ? (this.setAttribute("aria-activedescendant", e.id), e.scrollIntoView({ block: "nearest" })) : this.removeAttribute("aria-activedescendant");
|
|
3422
3542
|
}
|
|
3423
3543
|
// ===== Navigation Helpers =====
|
|
3424
|
-
findNextEnabled(
|
|
3544
|
+
findNextEnabled(t, e) {
|
|
3425
3545
|
const i = this.getEnabledIndices();
|
|
3426
3546
|
if (i.length === 0) return -1;
|
|
3427
|
-
const s = i.indexOf(
|
|
3547
|
+
const s = i.indexOf(t);
|
|
3428
3548
|
if (s === -1)
|
|
3429
|
-
return
|
|
3430
|
-
const a = s +
|
|
3549
|
+
return e === 1 ? i[0] : i[i.length - 1];
|
|
3550
|
+
const a = s + e;
|
|
3431
3551
|
return a < 0 || a >= i.length ? -1 : i[a];
|
|
3432
3552
|
}
|
|
3433
3553
|
findFirstEnabled() {
|
|
3434
|
-
const
|
|
3435
|
-
return
|
|
3554
|
+
const t = this.getEnabledIndices();
|
|
3555
|
+
return t.length > 0 ? t[0] : -1;
|
|
3436
3556
|
}
|
|
3437
3557
|
findLastEnabled() {
|
|
3438
|
-
const
|
|
3439
|
-
return
|
|
3558
|
+
const t = this.getEnabledIndices();
|
|
3559
|
+
return t.length > 0 ? t[t.length - 1] : -1;
|
|
3440
3560
|
}
|
|
3441
3561
|
// ===== Selection =====
|
|
3442
|
-
selectOption(
|
|
3443
|
-
|
|
3562
|
+
selectOption(t) {
|
|
3563
|
+
t.effectivelyDisabled || this._disabled || (this._multiple ? this.toggleOptionSelection(t) : this.selectSingle(t));
|
|
3444
3564
|
}
|
|
3445
|
-
selectSingle(
|
|
3565
|
+
selectSingle(t) {
|
|
3446
3566
|
var i;
|
|
3447
|
-
const
|
|
3448
|
-
if (this._value =
|
|
3449
|
-
const s = ((i =
|
|
3567
|
+
const e = this._value;
|
|
3568
|
+
if (this._value = t.value, this.setAttribute("value", t.value), this.syncOptionStates(), e !== this._value) {
|
|
3569
|
+
const s = ((i = t.textContent) == null ? void 0 : i.trim()) || t.value;
|
|
3450
3570
|
this.emit("change", { value: this._value, label: s }), this.emit("a11y-listbox-change", { value: this._value, label: s }), p(`${s} selected`);
|
|
3451
3571
|
}
|
|
3452
3572
|
}
|
|
3453
|
-
toggleOptionSelection(
|
|
3573
|
+
toggleOptionSelection(t) {
|
|
3454
3574
|
var s;
|
|
3455
|
-
if (
|
|
3456
|
-
const
|
|
3457
|
-
this._values.has(
|
|
3575
|
+
if (t.effectivelyDisabled || this._disabled) return;
|
|
3576
|
+
const e = ((s = t.textContent) == null ? void 0 : s.trim()) || t.value;
|
|
3577
|
+
this._values.has(t.value) ? (this._values.delete(t.value), t.selected = !1, p(`${e} deselected`)) : (this._values.add(t.value), t.selected = !0, p(`${e} selected`));
|
|
3458
3578
|
const i = Array.from(this._values);
|
|
3459
3579
|
this.setAttribute("value", i.join(",")), this.emit("change", { value: i }), this.emit("a11y-listbox-change", { value: i });
|
|
3460
3580
|
}
|
|
3461
|
-
selectRange(
|
|
3462
|
-
const i = this.getAllOptions(), s = Math.min(
|
|
3581
|
+
selectRange(t, e) {
|
|
3582
|
+
const i = this.getAllOptions(), s = Math.min(t, e), a = Math.max(t, e);
|
|
3463
3583
|
for (let l = s; l <= a; l++) {
|
|
3464
3584
|
const o = i[l];
|
|
3465
3585
|
o && !o.effectivelyDisabled && (this._values.add(o.value), o.selected = !0);
|
|
@@ -3468,8 +3588,8 @@ class W extends c {
|
|
|
3468
3588
|
this.setAttribute("value", r.join(",")), this.emit("change", { value: r }), this.emit("a11y-listbox-change", { value: r }), p(`${a - s + 1} items selected`);
|
|
3469
3589
|
}
|
|
3470
3590
|
toggleSelectAll() {
|
|
3471
|
-
const
|
|
3472
|
-
|
|
3591
|
+
const t = this.getEnabledOptions();
|
|
3592
|
+
t.every((s) => this._values.has(s.value)) ? (this._values.clear(), this.getAllOptions().forEach((s) => s.selected = !1), p("All deselected")) : (t.forEach((s) => {
|
|
3473
3593
|
this._values.add(s.value), s.selected = !0;
|
|
3474
3594
|
}), p("All selected"));
|
|
3475
3595
|
const i = Array.from(this._values);
|
|
@@ -3477,53 +3597,52 @@ class W extends c {
|
|
|
3477
3597
|
}
|
|
3478
3598
|
// ===== Type-ahead =====
|
|
3479
3599
|
rebuildTypeAhead() {
|
|
3480
|
-
const
|
|
3481
|
-
(
|
|
3600
|
+
const t = this.getAllOptions().map(
|
|
3601
|
+
(e) => {
|
|
3482
3602
|
var i;
|
|
3483
|
-
return ((i =
|
|
3603
|
+
return ((i = e.textContent) == null ? void 0 : i.trim()) || "";
|
|
3484
3604
|
}
|
|
3485
3605
|
);
|
|
3486
|
-
this._typeAhead = q(
|
|
3606
|
+
this._typeAhead = q(t, { timeout: 500 });
|
|
3487
3607
|
}
|
|
3488
3608
|
// ===== Attribute Changes =====
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
}
|
|
3609
|
+
onAttributeChange(t, e, i) {
|
|
3610
|
+
switch (t) {
|
|
3611
|
+
case "value":
|
|
3612
|
+
this._multiple ? this._values = new Set(
|
|
3613
|
+
(i || "").split(",").filter(Boolean)
|
|
3614
|
+
) : this._value = i || null, this.syncOptionStates();
|
|
3615
|
+
break;
|
|
3616
|
+
case "multiple":
|
|
3617
|
+
this._multiple = i !== null, this._multiple ? (this.setAttribute("aria-multiselectable", "true"), this._value && (this._values = /* @__PURE__ */ new Set([this._value]), this._value = null)) : (this.removeAttribute("aria-multiselectable"), this._values.size > 0 && (this._value = Array.from(this._values)[0] ?? null, this._values.clear())), this.syncOptionStates();
|
|
3618
|
+
break;
|
|
3619
|
+
case "disabled":
|
|
3620
|
+
this._disabled = i !== null, this._disabled ? (this.setAttribute("aria-disabled", "true"), this._discoverable || this.setAttribute("tabindex", "-1")) : (this.removeAttribute("aria-disabled"), this.setAttribute("tabindex", "0"));
|
|
3621
|
+
break;
|
|
3622
|
+
case "discoverable":
|
|
3623
|
+
i === null ? this._discoverable = !0 : i === "false" || i === "0" ? this._discoverable = !1 : this._discoverable = !0;
|
|
3624
|
+
break;
|
|
3625
|
+
case "orientation":
|
|
3626
|
+
(i === "horizontal" || i === "vertical") && (this._orientation = i, this.setAttribute("aria-orientation", i));
|
|
3627
|
+
break;
|
|
3628
|
+
}
|
|
3510
3629
|
}
|
|
3511
3630
|
}
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
const
|
|
3631
|
+
c("a11y-optgroup", W);
|
|
3632
|
+
c("a11y-option", J);
|
|
3633
|
+
c("a11y-listbox", Q);
|
|
3634
|
+
const Mt = `<svg class="checkbox-check" width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true">
|
|
3516
3635
|
<path d="M2.5 6L5 8.5L9.5 3.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
3517
|
-
</svg>`,
|
|
3636
|
+
</svg>`, Kt = `<svg class="checkbox-dash" width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true">
|
|
3518
3637
|
<path d="M3 6H9" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
|
3519
3638
|
</svg>`;
|
|
3520
|
-
class
|
|
3639
|
+
class R extends d {
|
|
3521
3640
|
constructor() {
|
|
3522
3641
|
super(...arguments), this._checked = !1, this._indeterminate = !1, this._input = null, this.handleChange = () => {
|
|
3523
3642
|
if (!this._input) return;
|
|
3524
3643
|
this._checked = this._input.checked, this.toggleAttribute("checked", this._checked), this._indeterminate && (this._indeterminate = !1, this.removeAttribute("indeterminate"), this._input.indeterminate = !1), this.updateVisualState(), this.emit("change", { checked: this._checked, value: this.value });
|
|
3525
|
-
const
|
|
3526
|
-
p(`${
|
|
3644
|
+
const t = this.label || this.getAttribute("aria-label") || "Checkbox";
|
|
3645
|
+
p(`${t} ${this._checked ? "checked" : "unchecked"}`);
|
|
3527
3646
|
};
|
|
3528
3647
|
}
|
|
3529
3648
|
static get observedAttributes() {
|
|
@@ -3548,9 +3667,9 @@ class O extends c {
|
|
|
3548
3667
|
get checked() {
|
|
3549
3668
|
return this._checked;
|
|
3550
3669
|
}
|
|
3551
|
-
set checked(
|
|
3552
|
-
const
|
|
3553
|
-
this._checked =
|
|
3670
|
+
set checked(t) {
|
|
3671
|
+
const e = this._checked;
|
|
3672
|
+
this._checked = t, this.toggleAttribute("checked", t), t !== e && (this.updateVisualState(), this.emit("change", { checked: t, value: this.value }));
|
|
3554
3673
|
}
|
|
3555
3674
|
/**
|
|
3556
3675
|
* Get/set the indeterminate state
|
|
@@ -3558,9 +3677,9 @@ class O extends c {
|
|
|
3558
3677
|
get indeterminate() {
|
|
3559
3678
|
return this._indeterminate;
|
|
3560
3679
|
}
|
|
3561
|
-
set indeterminate(
|
|
3562
|
-
const
|
|
3563
|
-
this._indeterminate =
|
|
3680
|
+
set indeterminate(t) {
|
|
3681
|
+
const e = this._indeterminate;
|
|
3682
|
+
this._indeterminate = t, this.toggleAttribute("indeterminate", t), t !== e && this.updateVisualState();
|
|
3564
3683
|
}
|
|
3565
3684
|
/**
|
|
3566
3685
|
* Get/set the disabled state
|
|
@@ -3568,8 +3687,8 @@ class O extends c {
|
|
|
3568
3687
|
get disabled() {
|
|
3569
3688
|
return this.hasAttribute("disabled");
|
|
3570
3689
|
}
|
|
3571
|
-
set disabled(
|
|
3572
|
-
this.toggleAttribute("disabled",
|
|
3690
|
+
set disabled(t) {
|
|
3691
|
+
this.toggleAttribute("disabled", t), this.updateDisabledState();
|
|
3573
3692
|
}
|
|
3574
3693
|
/**
|
|
3575
3694
|
* Get/set the value
|
|
@@ -3577,8 +3696,8 @@ class O extends c {
|
|
|
3577
3696
|
get value() {
|
|
3578
3697
|
return this.getAttribute("value") || "";
|
|
3579
3698
|
}
|
|
3580
|
-
set value(
|
|
3581
|
-
|
|
3699
|
+
set value(t) {
|
|
3700
|
+
t ? this.setAttribute("value", t) : this.removeAttribute("value");
|
|
3582
3701
|
}
|
|
3583
3702
|
/**
|
|
3584
3703
|
* Get/set the visible label
|
|
@@ -3586,8 +3705,8 @@ class O extends c {
|
|
|
3586
3705
|
get label() {
|
|
3587
3706
|
return this.getAttribute("label") || "";
|
|
3588
3707
|
}
|
|
3589
|
-
set label(
|
|
3590
|
-
|
|
3708
|
+
set label(t) {
|
|
3709
|
+
t ? this.setAttribute("label", t) : this.removeAttribute("label");
|
|
3591
3710
|
}
|
|
3592
3711
|
/**
|
|
3593
3712
|
* Get/set the hint text
|
|
@@ -3595,8 +3714,8 @@ class O extends c {
|
|
|
3595
3714
|
get hint() {
|
|
3596
3715
|
return this.getAttribute("hint") || "";
|
|
3597
3716
|
}
|
|
3598
|
-
set hint(
|
|
3599
|
-
|
|
3717
|
+
set hint(t) {
|
|
3718
|
+
t ? this.setAttribute("hint", t) : this.removeAttribute("hint");
|
|
3600
3719
|
}
|
|
3601
3720
|
/**
|
|
3602
3721
|
* Get/set the error message
|
|
@@ -3604,18 +3723,18 @@ class O extends c {
|
|
|
3604
3723
|
get error() {
|
|
3605
3724
|
return this.getAttribute("error") || "";
|
|
3606
3725
|
}
|
|
3607
|
-
set error(
|
|
3608
|
-
|
|
3726
|
+
set error(t) {
|
|
3727
|
+
t ? this.setAttribute("error", t) : this.removeAttribute("error");
|
|
3609
3728
|
}
|
|
3610
3729
|
/**
|
|
3611
3730
|
* Get/set the size variant
|
|
3612
3731
|
*/
|
|
3613
3732
|
get size() {
|
|
3614
|
-
const
|
|
3615
|
-
return
|
|
3733
|
+
const t = this.getAttribute("size");
|
|
3734
|
+
return t === "sm" || t === "lg" ? t : "md";
|
|
3616
3735
|
}
|
|
3617
|
-
set size(
|
|
3618
|
-
this.setAttribute("size",
|
|
3736
|
+
set size(t) {
|
|
3737
|
+
this.setAttribute("size", t);
|
|
3619
3738
|
}
|
|
3620
3739
|
/**
|
|
3621
3740
|
* Get/set required state
|
|
@@ -3623,28 +3742,28 @@ class O extends c {
|
|
|
3623
3742
|
get required() {
|
|
3624
3743
|
return this.hasAttribute("required");
|
|
3625
3744
|
}
|
|
3626
|
-
set required(
|
|
3627
|
-
this.toggleAttribute("required",
|
|
3745
|
+
set required(t) {
|
|
3746
|
+
this.toggleAttribute("required", t);
|
|
3628
3747
|
}
|
|
3629
3748
|
setupAccessibility() {
|
|
3630
|
-
var
|
|
3631
|
-
this._checked = this.hasAttribute("checked"), this._indeterminate = this.hasAttribute("indeterminate"), typeof process < "u" && ((
|
|
3749
|
+
var t;
|
|
3750
|
+
this._checked = this.hasAttribute("checked"), this._indeterminate = this.hasAttribute("indeterminate"), typeof process < "u" && ((t = process.env) == null ? void 0 : t.NODE_ENV) !== "production" && !this.label && !this.getAttribute("aria-label") && console.warn(
|
|
3632
3751
|
`[compa11y/Checkbox] Checkbox has no accessible label. Add label="..." or aria-label="..." attribute.
|
|
3633
3752
|
💡 Suggestion: <a11y-checkbox label="Accept terms"></a11y-checkbox>`
|
|
3634
3753
|
);
|
|
3635
3754
|
}
|
|
3636
3755
|
render() {
|
|
3637
|
-
const
|
|
3638
|
-
|
|
3639
|
-
const f =
|
|
3640
|
-
|
|
3641
|
-
<style>${
|
|
3756
|
+
const t = this.attachShadow({ mode: "open" }), e = `${this._id}-input`, i = `${this._id}-label`, s = `${this._id}-hint`, a = `${this._id}-error`, r = !!this.label, l = !!this.hint, o = !!this.error, b = this.getAttribute("aria-label"), h = this.getAttribute("name") || "", m = this.getAttribute("aria-describedby") || "", g = [];
|
|
3757
|
+
m && g.push(m), l && g.push(s), o && g.push(a);
|
|
3758
|
+
const f = g.length ? `aria-describedby="${g.join(" ")}"` : "", _ = !r && b ? `aria-label="${b}"` : "";
|
|
3759
|
+
t.innerHTML = `
|
|
3760
|
+
<style>${zt}</style>
|
|
3642
3761
|
<div class="checkbox-wrapper size-${this.size}" part="wrapper">
|
|
3643
3762
|
<div class="checkbox-control">
|
|
3644
3763
|
<input
|
|
3645
3764
|
type="checkbox"
|
|
3646
3765
|
class="checkbox-input"
|
|
3647
|
-
id="${
|
|
3766
|
+
id="${e}"
|
|
3648
3767
|
${h ? `name="${h}"` : ""}
|
|
3649
3768
|
${this.value ? `value="${this.value}"` : ""}
|
|
3650
3769
|
${this._checked ? "checked" : ""}
|
|
@@ -3656,28 +3775,28 @@ class O extends c {
|
|
|
3656
3775
|
part="input"
|
|
3657
3776
|
/>
|
|
3658
3777
|
<div class="checkbox-indicator" part="indicator" aria-hidden="true">
|
|
3659
|
-
${
|
|
3660
|
-
${
|
|
3778
|
+
${Mt}
|
|
3779
|
+
${Kt}
|
|
3661
3780
|
</div>
|
|
3662
3781
|
</div>
|
|
3663
3782
|
${r || l || o ? `<div class="checkbox-content">
|
|
3664
|
-
${r ? `<label for="${
|
|
3783
|
+
${r ? `<label for="${e}" id="${i}" class="checkbox-label" part="label">${this.label}${this.required ? '<span class="checkbox-required" aria-hidden="true">*</span>' : ""}</label>` : ""}
|
|
3665
3784
|
${l ? `<div id="${s}" class="checkbox-hint" part="hint">${this.hint}</div>` : ""}
|
|
3666
3785
|
${o ? `<div id="${a}" class="checkbox-error" role="alert" part="error">${this.error}</div>` : ""}
|
|
3667
3786
|
</div>` : ""}
|
|
3668
3787
|
</div>
|
|
3669
|
-
`, this._input =
|
|
3788
|
+
`, this._input = t.querySelector("input"), this._input && this._indeterminate && (this._input.indeterminate = !0);
|
|
3670
3789
|
}
|
|
3671
3790
|
setupEventListeners() {
|
|
3672
|
-
var
|
|
3673
|
-
(
|
|
3791
|
+
var t;
|
|
3792
|
+
(t = this._input) == null || t.addEventListener("change", this.handleChange);
|
|
3674
3793
|
}
|
|
3675
3794
|
cleanupEventListeners() {
|
|
3676
|
-
var
|
|
3677
|
-
(
|
|
3795
|
+
var t;
|
|
3796
|
+
(t = this._input) == null || t.removeEventListener("change", this.handleChange);
|
|
3678
3797
|
}
|
|
3679
|
-
onAttributeChange(
|
|
3680
|
-
switch (
|
|
3798
|
+
onAttributeChange(t, e, i) {
|
|
3799
|
+
switch (t) {
|
|
3681
3800
|
case "checked":
|
|
3682
3801
|
this._checked = i !== null, this.updateVisualState();
|
|
3683
3802
|
break;
|
|
@@ -3717,9 +3836,9 @@ class O extends c {
|
|
|
3717
3836
|
* Update size class
|
|
3718
3837
|
*/
|
|
3719
3838
|
updateSizeClass() {
|
|
3720
|
-
var
|
|
3721
|
-
const
|
|
3722
|
-
|
|
3839
|
+
var e;
|
|
3840
|
+
const t = (e = this.shadowRoot) == null ? void 0 : e.querySelector(".checkbox-wrapper");
|
|
3841
|
+
t && (t.classList.remove("size-sm", "size-md", "size-lg"), t.classList.add(`size-${this.size}`));
|
|
3723
3842
|
}
|
|
3724
3843
|
/**
|
|
3725
3844
|
* Toggle the checkbox programmatically
|
|
@@ -3727,23 +3846,23 @@ class O extends c {
|
|
|
3727
3846
|
toggle() {
|
|
3728
3847
|
if (this.disabled) return;
|
|
3729
3848
|
this._indeterminate ? (this.indeterminate = !1, this.checked = !0) : this.checked = !this.checked;
|
|
3730
|
-
const
|
|
3731
|
-
p(`${
|
|
3849
|
+
const t = this.label || this.getAttribute("aria-label") || "Checkbox";
|
|
3850
|
+
p(`${t} ${this.checked ? "checked" : "unchecked"}`);
|
|
3732
3851
|
}
|
|
3733
3852
|
/**
|
|
3734
3853
|
* Set checked state programmatically
|
|
3735
3854
|
*/
|
|
3736
|
-
setChecked(
|
|
3737
|
-
this.checked =
|
|
3855
|
+
setChecked(t) {
|
|
3856
|
+
this.checked = t;
|
|
3738
3857
|
}
|
|
3739
3858
|
}
|
|
3740
|
-
class
|
|
3859
|
+
class Z extends d {
|
|
3741
3860
|
constructor() {
|
|
3742
|
-
super(...arguments), this._value = [], this.handleChildChange = (
|
|
3743
|
-
const
|
|
3744
|
-
if (!(
|
|
3745
|
-
const i =
|
|
3746
|
-
i && (
|
|
3861
|
+
super(...arguments), this._value = [], this.handleChildChange = (t) => {
|
|
3862
|
+
const e = t.target;
|
|
3863
|
+
if (!(e instanceof R) || e === this) return;
|
|
3864
|
+
const i = e.value;
|
|
3865
|
+
i && (e.checked ? this._value.includes(i) || (this._value = [...this._value, i]) : this._value = this._value.filter((s) => s !== i), this.emit("change", { value: this._value }));
|
|
3747
3866
|
};
|
|
3748
3867
|
}
|
|
3749
3868
|
static get observedAttributes() {
|
|
@@ -3762,8 +3881,8 @@ class J extends c {
|
|
|
3762
3881
|
get value() {
|
|
3763
3882
|
return [...this._value];
|
|
3764
3883
|
}
|
|
3765
|
-
set value(
|
|
3766
|
-
this._value = [...
|
|
3884
|
+
set value(t) {
|
|
3885
|
+
this._value = [...t], this.syncCheckboxStates();
|
|
3767
3886
|
}
|
|
3768
3887
|
/**
|
|
3769
3888
|
* Get/set the disabled state
|
|
@@ -3771,8 +3890,8 @@ class J extends c {
|
|
|
3771
3890
|
get disabled() {
|
|
3772
3891
|
return this.hasAttribute("disabled");
|
|
3773
3892
|
}
|
|
3774
|
-
set disabled(
|
|
3775
|
-
this.toggleAttribute("disabled",
|
|
3893
|
+
set disabled(t) {
|
|
3894
|
+
this.toggleAttribute("disabled", t), this.syncDisabledState();
|
|
3776
3895
|
}
|
|
3777
3896
|
/**
|
|
3778
3897
|
* Get/set the legend text
|
|
@@ -3780,8 +3899,8 @@ class J extends c {
|
|
|
3780
3899
|
get legend() {
|
|
3781
3900
|
return this.getAttribute("legend") || "";
|
|
3782
3901
|
}
|
|
3783
|
-
set legend(
|
|
3784
|
-
|
|
3902
|
+
set legend(t) {
|
|
3903
|
+
t ? this.setAttribute("legend", t) : this.removeAttribute("legend");
|
|
3785
3904
|
}
|
|
3786
3905
|
/**
|
|
3787
3906
|
* Get/set the error message
|
|
@@ -3789,8 +3908,8 @@ class J extends c {
|
|
|
3789
3908
|
get error() {
|
|
3790
3909
|
return this.getAttribute("error") || "";
|
|
3791
3910
|
}
|
|
3792
|
-
set error(
|
|
3793
|
-
|
|
3911
|
+
set error(t) {
|
|
3912
|
+
t ? this.setAttribute("error", t) : this.removeAttribute("error");
|
|
3794
3913
|
}
|
|
3795
3914
|
/**
|
|
3796
3915
|
* Get/set the orientation
|
|
@@ -3798,32 +3917,32 @@ class J extends c {
|
|
|
3798
3917
|
get orientation() {
|
|
3799
3918
|
return this.getAttribute("orientation") === "horizontal" ? "horizontal" : "vertical";
|
|
3800
3919
|
}
|
|
3801
|
-
set orientation(
|
|
3802
|
-
this.setAttribute("orientation",
|
|
3920
|
+
set orientation(t) {
|
|
3921
|
+
this.setAttribute("orientation", t);
|
|
3803
3922
|
}
|
|
3804
3923
|
setupAccessibility() {
|
|
3805
|
-
var
|
|
3806
|
-
typeof process < "u" && ((
|
|
3924
|
+
var t;
|
|
3925
|
+
typeof process < "u" && ((t = process.env) == null ? void 0 : t.NODE_ENV) !== "production" && !this.legend && !this.getAttribute("aria-label") && !this.getAttribute("aria-labelledby") && console.warn(
|
|
3807
3926
|
`[compa11y/CheckboxGroup] CheckboxGroup has no accessible label. Add legend="..." or aria-label="..." attribute.
|
|
3808
3927
|
💡 Suggestion: <a11y-checkbox-group legend="Select options"></a11y-checkbox-group>`
|
|
3809
3928
|
), this.initValueFromChildren();
|
|
3810
3929
|
}
|
|
3811
3930
|
render() {
|
|
3812
|
-
const
|
|
3813
|
-
|
|
3814
|
-
<style>${
|
|
3931
|
+
const t = this.attachShadow({ mode: "open" }), e = `${this._id}-error`, i = !!this.legend, s = !!this.error, a = this.getAttribute("aria-label"), r = this.getAttribute("aria-labelledby");
|
|
3932
|
+
t.innerHTML = `
|
|
3933
|
+
<style>${Dt}</style>
|
|
3815
3934
|
<fieldset
|
|
3816
3935
|
part="fieldset"
|
|
3817
3936
|
${a ? `aria-label="${a}"` : ""}
|
|
3818
3937
|
${r ? `aria-labelledby="${r}"` : ""}
|
|
3819
|
-
${s ? `aria-describedby="${
|
|
3938
|
+
${s ? `aria-describedby="${e}"` : ""}
|
|
3820
3939
|
${this.disabled ? "disabled" : ""}
|
|
3821
3940
|
>
|
|
3822
3941
|
${i ? `<legend part="legend">${this.legend}</legend>` : ""}
|
|
3823
3942
|
<div class="checkbox-group-items" part="items">
|
|
3824
3943
|
<slot></slot>
|
|
3825
3944
|
</div>
|
|
3826
|
-
${s ? `<div id="${
|
|
3945
|
+
${s ? `<div id="${e}" class="checkbox-group-error" role="alert" part="error">${this.error}</div>` : ""}
|
|
3827
3946
|
</fieldset>
|
|
3828
3947
|
`;
|
|
3829
3948
|
}
|
|
@@ -3833,8 +3952,8 @@ class J extends c {
|
|
|
3833
3952
|
cleanupEventListeners() {
|
|
3834
3953
|
this.removeEventListener("change", this.handleChildChange);
|
|
3835
3954
|
}
|
|
3836
|
-
onAttributeChange(
|
|
3837
|
-
switch (
|
|
3955
|
+
onAttributeChange(t, e, i) {
|
|
3956
|
+
switch (t) {
|
|
3838
3957
|
case "disabled":
|
|
3839
3958
|
this.syncDisabledState();
|
|
3840
3959
|
break;
|
|
@@ -3851,10 +3970,10 @@ class J extends c {
|
|
|
3851
3970
|
*/
|
|
3852
3971
|
initValueFromChildren() {
|
|
3853
3972
|
requestAnimationFrame(() => {
|
|
3854
|
-
const
|
|
3855
|
-
|
|
3856
|
-
i.hasAttribute("checked") && i.getAttribute("value") &&
|
|
3857
|
-
}), this._value =
|
|
3973
|
+
const t = this.querySelectorAll("a11y-checkbox"), e = [];
|
|
3974
|
+
t.forEach((i) => {
|
|
3975
|
+
i.hasAttribute("checked") && i.getAttribute("value") && e.push(i.getAttribute("value"));
|
|
3976
|
+
}), this._value = e;
|
|
3858
3977
|
});
|
|
3859
3978
|
}
|
|
3860
3979
|
/**
|
|
@@ -3863,56 +3982,56 @@ class J extends c {
|
|
|
3863
3982
|
syncCheckboxStates() {
|
|
3864
3983
|
this.querySelectorAll(
|
|
3865
3984
|
"a11y-checkbox"
|
|
3866
|
-
).forEach((
|
|
3867
|
-
const i =
|
|
3868
|
-
i && (
|
|
3985
|
+
).forEach((e) => {
|
|
3986
|
+
const i = e.value;
|
|
3987
|
+
i && (e.checked = this._value.includes(i));
|
|
3869
3988
|
});
|
|
3870
3989
|
}
|
|
3871
3990
|
/**
|
|
3872
3991
|
* Sync disabled state to children
|
|
3873
3992
|
*/
|
|
3874
3993
|
syncDisabledState() {
|
|
3875
|
-
var
|
|
3876
|
-
const
|
|
3877
|
-
|
|
3994
|
+
var e;
|
|
3995
|
+
const t = (e = this.shadowRoot) == null ? void 0 : e.querySelector("fieldset");
|
|
3996
|
+
t && (this.disabled ? t.setAttribute("disabled", "") : t.removeAttribute("disabled"));
|
|
3878
3997
|
}
|
|
3879
3998
|
}
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
class
|
|
3999
|
+
c("a11y-checkbox", R);
|
|
4000
|
+
c("a11y-checkbox-group", Z);
|
|
4001
|
+
class tt extends d {
|
|
3883
4002
|
constructor() {
|
|
3884
|
-
super(...arguments), this._value = "", this._disabled = !1, this._discoverable = !0, this._orientation = "vertical", this._required = !1, this._name = "", this.handleRadioSelect = (
|
|
4003
|
+
super(...arguments), this._value = "", this._disabled = !1, this._discoverable = !0, this._orientation = "vertical", this._required = !1, this._name = "", this.handleRadioSelect = (t) => {
|
|
3885
4004
|
var i;
|
|
3886
4005
|
if (this._disabled) return;
|
|
3887
|
-
const
|
|
3888
|
-
|
|
3889
|
-
}, this.handleKeyDown = (
|
|
4006
|
+
const e = (i = t.detail) == null ? void 0 : i.value;
|
|
4007
|
+
e !== void 0 && this.selectRadio(e);
|
|
4008
|
+
}, this.handleKeyDown = (t) => {
|
|
3890
4009
|
if (this._disabled) return;
|
|
3891
|
-
const
|
|
3892
|
-
if (
|
|
3893
|
-
const i =
|
|
4010
|
+
const e = this.getEnabledRadios();
|
|
4011
|
+
if (e.length === 0) return;
|
|
4012
|
+
const i = e.findIndex(
|
|
3894
4013
|
(a) => a.value === this._value
|
|
3895
4014
|
);
|
|
3896
4015
|
let s = null;
|
|
3897
|
-
switch (
|
|
4016
|
+
switch (t.key) {
|
|
3898
4017
|
case "ArrowDown":
|
|
3899
4018
|
case "ArrowRight":
|
|
3900
|
-
s = i < 0 ? 0 : (i + 1) %
|
|
4019
|
+
s = i < 0 ? 0 : (i + 1) % e.length;
|
|
3901
4020
|
break;
|
|
3902
4021
|
case "ArrowUp":
|
|
3903
4022
|
case "ArrowLeft":
|
|
3904
|
-
s = i < 0 ?
|
|
4023
|
+
s = i < 0 ? e.length - 1 : (i - 1 + e.length) % e.length;
|
|
3905
4024
|
break;
|
|
3906
4025
|
case "Home":
|
|
3907
4026
|
s = 0;
|
|
3908
4027
|
break;
|
|
3909
4028
|
case "End":
|
|
3910
|
-
s =
|
|
4029
|
+
s = e.length - 1;
|
|
3911
4030
|
break;
|
|
3912
4031
|
case " ":
|
|
3913
|
-
|
|
4032
|
+
t.preventDefault(), t.stopPropagation();
|
|
3914
4033
|
{
|
|
3915
|
-
const a =
|
|
4034
|
+
const a = e.find(
|
|
3916
4035
|
(r) => r === document.activeElement || r.contains(document.activeElement)
|
|
3917
4036
|
);
|
|
3918
4037
|
if (a && a.value !== this._value) {
|
|
@@ -3926,8 +4045,8 @@ class Q extends c {
|
|
|
3926
4045
|
return;
|
|
3927
4046
|
}
|
|
3928
4047
|
if (s !== null) {
|
|
3929
|
-
|
|
3930
|
-
const a =
|
|
4048
|
+
t.preventDefault(), t.stopPropagation();
|
|
4049
|
+
const a = e[s];
|
|
3931
4050
|
if (a) {
|
|
3932
4051
|
this.selectRadio(a.value), a.focus();
|
|
3933
4052
|
const r = a.getAttribute("label") || a.value;
|
|
@@ -3955,47 +4074,47 @@ class Q extends c {
|
|
|
3955
4074
|
get value() {
|
|
3956
4075
|
return this._value;
|
|
3957
4076
|
}
|
|
3958
|
-
set value(
|
|
3959
|
-
this._value !==
|
|
4077
|
+
set value(t) {
|
|
4078
|
+
this._value !== t && (this._value = t, this.setAttribute("value", t), this.syncRadioStates());
|
|
3960
4079
|
}
|
|
3961
4080
|
get disabled() {
|
|
3962
4081
|
return this._disabled;
|
|
3963
4082
|
}
|
|
3964
|
-
set disabled(
|
|
3965
|
-
const
|
|
3966
|
-
this._disabled !==
|
|
4083
|
+
set disabled(t) {
|
|
4084
|
+
const e = !!t;
|
|
4085
|
+
this._disabled !== e && (this._disabled = e, e ? (this.setAttribute("disabled", ""), this.setAttribute("aria-disabled", "true")) : (this.removeAttribute("disabled"), this.removeAttribute("aria-disabled")), this.syncRadioStates());
|
|
3967
4086
|
}
|
|
3968
4087
|
get discoverable() {
|
|
3969
4088
|
return this._discoverable;
|
|
3970
4089
|
}
|
|
3971
|
-
set discoverable(
|
|
3972
|
-
this._discoverable = !!
|
|
4090
|
+
set discoverable(t) {
|
|
4091
|
+
this._discoverable = !!t;
|
|
3973
4092
|
}
|
|
3974
4093
|
get required() {
|
|
3975
4094
|
return this._required;
|
|
3976
4095
|
}
|
|
3977
|
-
set required(
|
|
3978
|
-
this._required = !!
|
|
4096
|
+
set required(t) {
|
|
4097
|
+
this._required = !!t, this._required ? this.setAttribute("aria-required", "true") : this.removeAttribute("aria-required");
|
|
3979
4098
|
}
|
|
3980
4099
|
get name() {
|
|
3981
4100
|
return this._name;
|
|
3982
4101
|
}
|
|
3983
|
-
set name(
|
|
3984
|
-
this._name =
|
|
4102
|
+
set name(t) {
|
|
4103
|
+
this._name = t, this.setAttribute("name", t);
|
|
3985
4104
|
}
|
|
3986
4105
|
get orientation() {
|
|
3987
4106
|
return this._orientation;
|
|
3988
4107
|
}
|
|
3989
|
-
set orientation(
|
|
3990
|
-
this._orientation =
|
|
4108
|
+
set orientation(t) {
|
|
4109
|
+
this._orientation = t, this.setAttribute("orientation", t), this.setAttribute("aria-orientation", t);
|
|
3991
4110
|
}
|
|
3992
4111
|
// ===== Lifecycle =====
|
|
3993
4112
|
setupAccessibility() {
|
|
3994
4113
|
this.setAttribute("role", "radiogroup"), this.setAttribute("aria-orientation", this._orientation), !(this.hasAttribute("aria-label") || this.hasAttribute("aria-labelledby") || this.hasAttribute("legend")) && process.env.NODE_ENV !== "production" && console.warn(
|
|
3995
4114
|
"[Compa11y RadioGroup]: RadioGroup has no accessible label. Use legend, aria-label, or aria-labelledby."
|
|
3996
4115
|
);
|
|
3997
|
-
const
|
|
3998
|
-
|
|
4116
|
+
const e = this.getAttribute("value");
|
|
4117
|
+
e && (this._value = e), this._disabled = this.hasAttribute("disabled"), this._disabled && this.setAttribute("aria-disabled", "true");
|
|
3999
4118
|
const i = this.getAttribute("orientation");
|
|
4000
4119
|
(i === "horizontal" || i === "vertical") && (this._orientation = i), this._required = this.hasAttribute("required"), this._required && this.setAttribute("aria-required", "true"), this._name = this.getAttribute("name") || this._id;
|
|
4001
4120
|
const s = this.getAttribute("discoverable");
|
|
@@ -4003,11 +4122,11 @@ class Q extends c {
|
|
|
4003
4122
|
}
|
|
4004
4123
|
render() {
|
|
4005
4124
|
this.shadowRoot || this.attachShadow({ mode: "open" });
|
|
4006
|
-
const
|
|
4007
|
-
l ? this.setAttribute("aria-describedby", l) : this.removeAttribute("aria-describedby"),
|
|
4008
|
-
<style>${
|
|
4125
|
+
const t = this.shadowRoot, e = this.getAttribute("legend") || "", i = this.getAttribute("hint") || "", s = this.getAttribute("error") || "", a = i ? `${this._id}-hint` : "", r = s ? `${this._id}-error` : "", l = [a, r].filter(Boolean).join(" ");
|
|
4126
|
+
l ? this.setAttribute("aria-describedby", l) : this.removeAttribute("aria-describedby"), t.innerHTML = `
|
|
4127
|
+
<style>${qt}</style>
|
|
4009
4128
|
<fieldset part="fieldset">
|
|
4010
|
-
${
|
|
4129
|
+
${e ? `<legend part="legend">${e}${this._required ? '<span class="radio-group-required" aria-hidden="true"> *</span>' : ""}</legend>` : ""}
|
|
4011
4130
|
<div class="radio-group-items" part="items">
|
|
4012
4131
|
<slot></slot>
|
|
4013
4132
|
</div>
|
|
@@ -4017,13 +4136,13 @@ class Q extends c {
|
|
|
4017
4136
|
`;
|
|
4018
4137
|
}
|
|
4019
4138
|
setupEventListeners() {
|
|
4020
|
-
var
|
|
4139
|
+
var e;
|
|
4021
4140
|
this.addEventListener("keydown", this.handleKeyDown), this.addEventListener(
|
|
4022
4141
|
"radio-select",
|
|
4023
4142
|
this.handleRadioSelect
|
|
4024
4143
|
);
|
|
4025
|
-
const
|
|
4026
|
-
|
|
4144
|
+
const t = (e = this.shadowRoot) == null ? void 0 : e.querySelector("slot");
|
|
4145
|
+
t && t.addEventListener("slotchange", () => {
|
|
4027
4146
|
this.syncRadioStates();
|
|
4028
4147
|
});
|
|
4029
4148
|
}
|
|
@@ -4039,23 +4158,23 @@ class Q extends c {
|
|
|
4039
4158
|
}
|
|
4040
4159
|
getEnabledRadios() {
|
|
4041
4160
|
return this.getRadios().filter(
|
|
4042
|
-
(
|
|
4161
|
+
(t) => !t.disabled && !this._disabled
|
|
4043
4162
|
);
|
|
4044
4163
|
}
|
|
4045
4164
|
syncRadioStates() {
|
|
4046
|
-
const
|
|
4047
|
-
|
|
4165
|
+
const t = this.getRadios(), e = this.getEnabledRadios();
|
|
4166
|
+
t.forEach((i) => {
|
|
4048
4167
|
const s = i.value === this._value;
|
|
4049
|
-
i.checked = s, s || !this._value &&
|
|
4168
|
+
i.checked = s, s || !this._value && e[0] === i ? i.setAttribute("tabindex", "0") : i.setAttribute("tabindex", "-1");
|
|
4050
4169
|
});
|
|
4051
4170
|
}
|
|
4052
|
-
selectRadio(
|
|
4053
|
-
this._disabled || (this._value =
|
|
4171
|
+
selectRadio(t) {
|
|
4172
|
+
this._disabled || (this._value = t, this.setAttribute("value", t), this.syncRadioStates(), this.hasAttribute("aria-invalid") && this.removeAttribute("aria-invalid"), this.emit("change", { value: t }), this.emit("a11y-radiogroup-change", { value: t }));
|
|
4054
4173
|
}
|
|
4055
4174
|
// ===== Attribute Changes =====
|
|
4056
|
-
attributeChangedCallback(
|
|
4057
|
-
if (
|
|
4058
|
-
switch (
|
|
4175
|
+
attributeChangedCallback(t, e, i) {
|
|
4176
|
+
if (e !== i)
|
|
4177
|
+
switch (t) {
|
|
4059
4178
|
case "value":
|
|
4060
4179
|
this._value = i || "", this.syncRadioStates();
|
|
4061
4180
|
break;
|
|
@@ -4084,11 +4203,11 @@ class Q extends c {
|
|
|
4084
4203
|
}
|
|
4085
4204
|
}
|
|
4086
4205
|
}
|
|
4087
|
-
class
|
|
4206
|
+
class et extends d {
|
|
4088
4207
|
constructor() {
|
|
4089
|
-
super(...arguments), this._value = "", this._checked = !1, this._disabled = !1, this._discoverable = !0, this.handleClick = (
|
|
4208
|
+
super(...arguments), this._value = "", this._checked = !1, this._disabled = !1, this._discoverable = !0, this.handleClick = (t) => {
|
|
4090
4209
|
if (this._disabled) {
|
|
4091
|
-
|
|
4210
|
+
t.preventDefault();
|
|
4092
4211
|
return;
|
|
4093
4212
|
}
|
|
4094
4213
|
this.dispatchEvent(
|
|
@@ -4098,19 +4217,19 @@ class Z extends c {
|
|
|
4098
4217
|
composed: !0
|
|
4099
4218
|
})
|
|
4100
4219
|
);
|
|
4101
|
-
const
|
|
4102
|
-
p(`${
|
|
4103
|
-
}, this.handleKeyDown = (
|
|
4104
|
-
if (!this._disabled &&
|
|
4105
|
-
|
|
4220
|
+
const e = this.getAttribute("label") || this._value;
|
|
4221
|
+
p(`${e} selected`);
|
|
4222
|
+
}, this.handleKeyDown = (t) => {
|
|
4223
|
+
if (!this._disabled && t.key === "Enter") {
|
|
4224
|
+
t.preventDefault(), this.dispatchEvent(
|
|
4106
4225
|
new CustomEvent("radio-select", {
|
|
4107
4226
|
detail: { value: this._value },
|
|
4108
4227
|
bubbles: !0,
|
|
4109
4228
|
composed: !0
|
|
4110
4229
|
})
|
|
4111
4230
|
);
|
|
4112
|
-
const
|
|
4113
|
-
p(`${
|
|
4231
|
+
const e = this.getAttribute("label") || this._value;
|
|
4232
|
+
p(`${e} selected`);
|
|
4114
4233
|
}
|
|
4115
4234
|
};
|
|
4116
4235
|
}
|
|
@@ -4121,41 +4240,41 @@ class Z extends c {
|
|
|
4121
4240
|
get value() {
|
|
4122
4241
|
return this._value;
|
|
4123
4242
|
}
|
|
4124
|
-
set value(
|
|
4125
|
-
this._value =
|
|
4243
|
+
set value(t) {
|
|
4244
|
+
this._value = t, this.setAttribute("value", t);
|
|
4126
4245
|
}
|
|
4127
4246
|
get checked() {
|
|
4128
4247
|
return this._checked;
|
|
4129
4248
|
}
|
|
4130
|
-
set checked(
|
|
4131
|
-
const
|
|
4132
|
-
this._checked !==
|
|
4249
|
+
set checked(t) {
|
|
4250
|
+
const e = !!t;
|
|
4251
|
+
this._checked !== e && (this._checked = e, e ? this.setAttribute("checked", "") : this.removeAttribute("checked"), this.setAttribute("aria-checked", String(e)), this.updateVisual());
|
|
4133
4252
|
}
|
|
4134
4253
|
get disabled() {
|
|
4135
4254
|
return this._disabled;
|
|
4136
4255
|
}
|
|
4137
|
-
set disabled(
|
|
4138
|
-
const
|
|
4139
|
-
this._disabled !==
|
|
4256
|
+
set disabled(t) {
|
|
4257
|
+
const e = !!t;
|
|
4258
|
+
this._disabled !== e && (this._disabled = e, e ? (this.setAttribute("disabled", ""), this.setAttribute("aria-disabled", "true")) : (this.removeAttribute("disabled"), this.removeAttribute("aria-disabled")));
|
|
4140
4259
|
}
|
|
4141
4260
|
get discoverable() {
|
|
4142
4261
|
return this._discoverable;
|
|
4143
4262
|
}
|
|
4144
|
-
set discoverable(
|
|
4145
|
-
let
|
|
4146
|
-
typeof
|
|
4263
|
+
set discoverable(t) {
|
|
4264
|
+
let e;
|
|
4265
|
+
typeof t == "string" ? e = t !== "false" && t !== "0" : e = !!t, this._discoverable !== e && (this._discoverable = e, e ? this.setAttribute("discoverable", "") : this.removeAttribute("discoverable"));
|
|
4147
4266
|
}
|
|
4148
4267
|
// ===== Lifecycle =====
|
|
4149
4268
|
setupAccessibility() {
|
|
4150
4269
|
this.setAttribute("role", "radio"), this.setAttribute("aria-checked", "false"), this._value = this.getAttribute("value") || "", this._checked = this.hasAttribute("checked"), this._disabled = this.hasAttribute("disabled"), this._checked && this.setAttribute("aria-checked", "true"), this._disabled && this.setAttribute("aria-disabled", "true");
|
|
4151
|
-
const
|
|
4152
|
-
(
|
|
4270
|
+
const t = this.getAttribute("discoverable");
|
|
4271
|
+
(t === "false" || t === "0") && (this._discoverable = !1), this.hasAttribute("tabindex") || this.setAttribute("tabindex", "-1");
|
|
4153
4272
|
}
|
|
4154
4273
|
render() {
|
|
4155
4274
|
this.shadowRoot || this.attachShadow({ mode: "open" });
|
|
4156
|
-
const
|
|
4157
|
-
s && this.setAttribute("aria-labelledby", s), a && this.setAttribute("aria-describedby", a),
|
|
4158
|
-
<style>${
|
|
4275
|
+
const t = this.shadowRoot, e = this.getAttribute("label") || "", i = this.getAttribute("hint") || "", s = e ? `${this._id}-label` : "", a = i ? `${this._id}-hint` : "";
|
|
4276
|
+
s && this.setAttribute("aria-labelledby", s), a && this.setAttribute("aria-describedby", a), t.innerHTML = `
|
|
4277
|
+
<style>${Ot}</style>
|
|
4159
4278
|
<div class="radio-wrapper" part="wrapper">
|
|
4160
4279
|
<div class="radio-control" part="control">
|
|
4161
4280
|
<input
|
|
@@ -4169,8 +4288,8 @@ class Z extends c {
|
|
|
4169
4288
|
<div class="radio-dot" part="dot" aria-hidden="true"></div>
|
|
4170
4289
|
</div>
|
|
4171
4290
|
</div>
|
|
4172
|
-
${
|
|
4173
|
-
${
|
|
4291
|
+
${e || i ? `<div class="radio-content">
|
|
4292
|
+
${e ? `<span class="radio-label" id="${s}" part="label">${e}</span>` : ""}
|
|
4174
4293
|
${i ? `<span class="radio-hint" id="${a}" part="hint">${i}</span>` : ""}
|
|
4175
4294
|
</div>` : ""}
|
|
4176
4295
|
<slot></slot>
|
|
@@ -4186,17 +4305,17 @@ class Z extends c {
|
|
|
4186
4305
|
// ===== Visual Update =====
|
|
4187
4306
|
updateVisual() {
|
|
4188
4307
|
if (!this.shadowRoot) return;
|
|
4189
|
-
const
|
|
4190
|
-
|
|
4191
|
-
const
|
|
4308
|
+
const t = this.shadowRoot.querySelector(".radio-dot");
|
|
4309
|
+
t && (t.style.opacity = this._checked ? "1" : "0", t.style.transform = this._checked ? "scale(1)" : "scale(0)");
|
|
4310
|
+
const e = this.shadowRoot.querySelector(
|
|
4192
4311
|
".radio-circle"
|
|
4193
4312
|
);
|
|
4194
|
-
|
|
4313
|
+
e && (this._checked ? (e.style.background = "var(--compa11y-radio-checked-bg, #0066cc)", e.style.borderColor = "var(--compa11y-radio-checked-border, #0066cc)") : (e.style.background = "var(--compa11y-radio-bg, white)", e.style.borderColor = ""));
|
|
4195
4314
|
}
|
|
4196
4315
|
// ===== Attribute Changes =====
|
|
4197
|
-
attributeChangedCallback(
|
|
4198
|
-
if (
|
|
4199
|
-
switch (
|
|
4316
|
+
attributeChangedCallback(t, e, i) {
|
|
4317
|
+
if (e !== i)
|
|
4318
|
+
switch (t) {
|
|
4200
4319
|
case "value":
|
|
4201
4320
|
this._value = i || "";
|
|
4202
4321
|
break;
|
|
@@ -4216,93 +4335,233 @@ class Z extends c {
|
|
|
4216
4335
|
}
|
|
4217
4336
|
}
|
|
4218
4337
|
}
|
|
4219
|
-
|
|
4220
|
-
|
|
4338
|
+
c("a11y-radio-group", tt);
|
|
4339
|
+
c("a11y-radio", et);
|
|
4340
|
+
class it extends d {
|
|
4341
|
+
constructor() {
|
|
4342
|
+
super(...arguments), this._toasts = [], this._counter = 0, this._containerEl = null, this._maxToasts = 5, this._handleClick = (t) => {
|
|
4343
|
+
var a;
|
|
4344
|
+
const e = t.target, i = e.getAttribute("data-close-id");
|
|
4345
|
+
if (i) {
|
|
4346
|
+
this.remove(i);
|
|
4347
|
+
return;
|
|
4348
|
+
}
|
|
4349
|
+
const s = e.getAttribute("data-action-id");
|
|
4350
|
+
if (s) {
|
|
4351
|
+
const r = this._toasts.find((l) => l.id === s);
|
|
4352
|
+
(a = r == null ? void 0 : r.action) == null || a.onClick(), this.remove(s);
|
|
4353
|
+
}
|
|
4354
|
+
};
|
|
4355
|
+
}
|
|
4356
|
+
static get observedAttributes() {
|
|
4357
|
+
return ["position", "duration", "max-toasts", "label"];
|
|
4358
|
+
}
|
|
4359
|
+
get position() {
|
|
4360
|
+
return this.getAttribute("position") || "bottom-right";
|
|
4361
|
+
}
|
|
4362
|
+
get duration() {
|
|
4363
|
+
const t = this.getAttribute("duration");
|
|
4364
|
+
return t ? parseInt(t, 10) : 5e3;
|
|
4365
|
+
}
|
|
4366
|
+
get maxToasts() {
|
|
4367
|
+
const t = this.getAttribute("max-toasts");
|
|
4368
|
+
return t ? parseInt(t, 10) : 5;
|
|
4369
|
+
}
|
|
4370
|
+
get label() {
|
|
4371
|
+
return this.getAttribute("label") || "Notifications";
|
|
4372
|
+
}
|
|
4373
|
+
setupAccessibility() {
|
|
4374
|
+
}
|
|
4375
|
+
render() {
|
|
4376
|
+
const t = this.attachShadow({ mode: "open" });
|
|
4377
|
+
t.innerHTML = `
|
|
4378
|
+
<style>${Rt}</style>
|
|
4379
|
+
<div
|
|
4380
|
+
class="toast-container"
|
|
4381
|
+
role="region"
|
|
4382
|
+
aria-label="${this.label}"
|
|
4383
|
+
aria-live="polite"
|
|
4384
|
+
aria-relevant="additions removals"
|
|
4385
|
+
></div>
|
|
4386
|
+
`, this._containerEl = t.querySelector(".toast-container");
|
|
4387
|
+
}
|
|
4388
|
+
setupEventListeners() {
|
|
4389
|
+
var t;
|
|
4390
|
+
(t = this._containerEl) == null || t.addEventListener("click", this._handleClick);
|
|
4391
|
+
}
|
|
4392
|
+
cleanupEventListeners() {
|
|
4393
|
+
var t;
|
|
4394
|
+
(t = this._containerEl) == null || t.removeEventListener("click", this._handleClick);
|
|
4395
|
+
for (const e of this._toasts)
|
|
4396
|
+
e.timerId && clearTimeout(e.timerId);
|
|
4397
|
+
this._toasts = [];
|
|
4398
|
+
}
|
|
4399
|
+
onAttributeChange(t, e, i) {
|
|
4400
|
+
t === "max-toasts" && i && (this._maxToasts = parseInt(i, 10)), t === "label" && this._containerEl && this._containerEl.setAttribute("aria-label", i || "Notifications");
|
|
4401
|
+
}
|
|
4402
|
+
// ---------------------------------------------------------------------------
|
|
4403
|
+
// Public API
|
|
4404
|
+
// ---------------------------------------------------------------------------
|
|
4405
|
+
/**
|
|
4406
|
+
* Add a toast notification. Returns the toast ID.
|
|
4407
|
+
*/
|
|
4408
|
+
add(t) {
|
|
4409
|
+
const e = `toast-${++this._counter}`, i = t.duration ?? this.duration, s = {
|
|
4410
|
+
id: e,
|
|
4411
|
+
type: t.type || "info",
|
|
4412
|
+
title: t.title,
|
|
4413
|
+
description: t.description,
|
|
4414
|
+
duration: i,
|
|
4415
|
+
action: t.action,
|
|
4416
|
+
timerId: null,
|
|
4417
|
+
remaining: i,
|
|
4418
|
+
startTime: Date.now()
|
|
4419
|
+
};
|
|
4420
|
+
for (this._toasts.push(s); this._toasts.length > this._maxToasts; ) {
|
|
4421
|
+
const a = this._toasts.shift();
|
|
4422
|
+
a && (a.timerId && clearTimeout(a.timerId), this._removeElement(a.id));
|
|
4423
|
+
}
|
|
4424
|
+
return this._renderToast(s), this._startTimer(s), this.emit("a11y-toast-add", { id: e, ...t }), e;
|
|
4425
|
+
}
|
|
4426
|
+
/**
|
|
4427
|
+
* Remove a toast by ID.
|
|
4428
|
+
*/
|
|
4429
|
+
remove(t) {
|
|
4430
|
+
const e = this._toasts.findIndex((s) => s.id === t);
|
|
4431
|
+
if (e === -1) return;
|
|
4432
|
+
const i = this._toasts[e];
|
|
4433
|
+
i.timerId && clearTimeout(i.timerId), this._toasts.splice(e, 1), this._removeElement(t), this.emit("a11y-toast-remove", { id: t });
|
|
4434
|
+
}
|
|
4435
|
+
/**
|
|
4436
|
+
* Remove all toasts.
|
|
4437
|
+
*/
|
|
4438
|
+
clear() {
|
|
4439
|
+
for (const t of this._toasts)
|
|
4440
|
+
t.timerId && clearTimeout(t.timerId);
|
|
4441
|
+
this._toasts = [], this._containerEl && (this._containerEl.innerHTML = "");
|
|
4442
|
+
}
|
|
4443
|
+
// ---------------------------------------------------------------------------
|
|
4444
|
+
// Internal
|
|
4445
|
+
// ---------------------------------------------------------------------------
|
|
4446
|
+
_renderToast(t) {
|
|
4447
|
+
if (!this._containerEl) return;
|
|
4448
|
+
const e = t.type === "error" || t.type === "warning", i = document.createElement("div");
|
|
4449
|
+
i.className = "toast", i.setAttribute("data-toast-id", t.id), i.setAttribute("data-type", t.type), i.setAttribute("role", e ? "alert" : "status"), i.setAttribute("aria-atomic", "true"), i.setAttribute("tabindex", "0");
|
|
4450
|
+
let s = '<div class="toast-content">';
|
|
4451
|
+
t.title && (s += `<div class="toast-title">${this._escapeHtml(t.title)}</div>`), t.description && (s += `<div class="toast-description">${this._escapeHtml(t.description)}</div>`), t.action && (s += `<button type="button" class="toast-action" data-action-id="${t.id}" tabindex="0">${this._escapeHtml(t.action.label)}</button>`), s += "</div>", s += `<button type="button" class="toast-close" aria-label="Dismiss" data-close-id="${t.id}" tabindex="0">×</button>`, i.innerHTML = s, i.addEventListener("mouseenter", () => this._pauseTimer(t)), i.addEventListener("mouseleave", () => this._resumeTimer(t)), i.addEventListener("keydown", (a) => {
|
|
4452
|
+
a.key === "Escape" && this.remove(t.id);
|
|
4453
|
+
}), this._containerEl.appendChild(i);
|
|
4454
|
+
}
|
|
4455
|
+
_removeElement(t) {
|
|
4456
|
+
var i;
|
|
4457
|
+
const e = (i = this._containerEl) == null ? void 0 : i.querySelector(
|
|
4458
|
+
`[data-toast-id="${t}"]`
|
|
4459
|
+
);
|
|
4460
|
+
e == null || e.remove();
|
|
4461
|
+
}
|
|
4462
|
+
_startTimer(t) {
|
|
4463
|
+
t.duration !== 0 && (t.startTime = Date.now(), t.timerId = setTimeout(() => {
|
|
4464
|
+
this.remove(t.id);
|
|
4465
|
+
}, t.remaining));
|
|
4466
|
+
}
|
|
4467
|
+
_pauseTimer(t) {
|
|
4468
|
+
t.timerId && (clearTimeout(t.timerId), t.timerId = null, t.remaining -= Date.now() - t.startTime);
|
|
4469
|
+
}
|
|
4470
|
+
_resumeTimer(t) {
|
|
4471
|
+
this._startTimer(t);
|
|
4472
|
+
}
|
|
4473
|
+
_escapeHtml(t) {
|
|
4474
|
+
const e = document.createElement("div");
|
|
4475
|
+
return e.textContent = t, e.innerHTML;
|
|
4476
|
+
}
|
|
4477
|
+
}
|
|
4478
|
+
c("a11y-toast", it);
|
|
4221
4479
|
if (typeof window < "u") {
|
|
4222
4480
|
const n = () => {
|
|
4223
|
-
|
|
4481
|
+
B(), H();
|
|
4224
4482
|
};
|
|
4225
4483
|
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", n) : n(), window.compa11y = {
|
|
4226
4484
|
// Components (classes)
|
|
4227
|
-
A11yDialog:
|
|
4228
|
-
A11yMenu:
|
|
4229
|
-
A11yTabs:
|
|
4230
|
-
A11yCombobox:
|
|
4231
|
-
A11ySwitch:
|
|
4232
|
-
A11ySelect:
|
|
4233
|
-
A11yInput:
|
|
4234
|
-
A11yTextarea:
|
|
4235
|
-
A11yButton:
|
|
4236
|
-
A11yListbox:
|
|
4237
|
-
A11yOption:
|
|
4238
|
-
A11yOptgroup:
|
|
4239
|
-
A11yCheckbox:
|
|
4240
|
-
A11yCheckboxGroup:
|
|
4241
|
-
A11yRadioGroup:
|
|
4242
|
-
A11yRadio:
|
|
4485
|
+
A11yDialog: N,
|
|
4486
|
+
A11yMenu: F,
|
|
4487
|
+
A11yTabs: P,
|
|
4488
|
+
A11yCombobox: j,
|
|
4489
|
+
A11ySwitch: U,
|
|
4490
|
+
A11ySelect: Y,
|
|
4491
|
+
A11yInput: G,
|
|
4492
|
+
A11yTextarea: V,
|
|
4493
|
+
A11yButton: X,
|
|
4494
|
+
A11yListbox: Q,
|
|
4495
|
+
A11yOption: J,
|
|
4496
|
+
A11yOptgroup: W,
|
|
4497
|
+
A11yCheckbox: R,
|
|
4498
|
+
A11yCheckboxGroup: Z,
|
|
4499
|
+
A11yRadioGroup: tt,
|
|
4500
|
+
A11yRadio: et,
|
|
4501
|
+
A11yToast: it,
|
|
4243
4502
|
// Announcer utilities
|
|
4244
|
-
initAnnouncer:
|
|
4503
|
+
initAnnouncer: B,
|
|
4245
4504
|
announce: v,
|
|
4246
4505
|
announcePolite: p,
|
|
4247
|
-
announceAssertive:
|
|
4248
|
-
announceStatus:
|
|
4249
|
-
announceError:
|
|
4506
|
+
announceAssertive: O,
|
|
4507
|
+
announceStatus: ft,
|
|
4508
|
+
announceError: vt,
|
|
4250
4509
|
// Focus utilities
|
|
4251
|
-
initFocusVisible:
|
|
4252
|
-
createFocusTrap:
|
|
4253
|
-
createFocusScope:
|
|
4254
|
-
createRovingTabindex:
|
|
4510
|
+
initFocusVisible: H,
|
|
4511
|
+
createFocusTrap: gt,
|
|
4512
|
+
createFocusScope: mt,
|
|
4513
|
+
createRovingTabindex: pt,
|
|
4255
4514
|
// Keyboard utilities
|
|
4256
|
-
createKeyboardManager:
|
|
4257
|
-
KeyboardPatterns:
|
|
4515
|
+
createKeyboardManager: bt,
|
|
4516
|
+
KeyboardPatterns: ut,
|
|
4258
4517
|
createTypeAhead: q,
|
|
4259
4518
|
// ARIA utilities
|
|
4260
|
-
aria:
|
|
4261
|
-
buildAriaProps:
|
|
4262
|
-
hasAccessibleName:
|
|
4519
|
+
aria: ct,
|
|
4520
|
+
buildAriaProps: dt,
|
|
4521
|
+
hasAccessibleName: ht,
|
|
4263
4522
|
// Platform detection
|
|
4264
|
-
isBrowser:
|
|
4265
|
-
prefersReducedMotion:
|
|
4266
|
-
prefersHighContrast:
|
|
4267
|
-
prefersDarkMode:
|
|
4523
|
+
isBrowser: nt,
|
|
4524
|
+
prefersReducedMotion: lt,
|
|
4525
|
+
prefersHighContrast: ot,
|
|
4526
|
+
prefersDarkMode: rt
|
|
4268
4527
|
};
|
|
4269
4528
|
}
|
|
4270
4529
|
export {
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4530
|
+
X as A11yButton,
|
|
4531
|
+
R as A11yCheckbox,
|
|
4532
|
+
Z as A11yCheckboxGroup,
|
|
4533
|
+
j as A11yCombobox,
|
|
4534
|
+
N as A11yDialog,
|
|
4535
|
+
G as A11yInput,
|
|
4536
|
+
Q as A11yListbox,
|
|
4537
|
+
F as A11yMenu,
|
|
4538
|
+
W as A11yOptgroup,
|
|
4539
|
+
J as A11yOption,
|
|
4540
|
+
et as A11yRadio,
|
|
4541
|
+
tt as A11yRadioGroup,
|
|
4542
|
+
Y as A11ySelect,
|
|
4543
|
+
U as A11ySwitch,
|
|
4544
|
+
P as A11yTabs,
|
|
4545
|
+
V as A11yTextarea,
|
|
4546
|
+
it as A11yToast,
|
|
4547
|
+
jt as KeyboardPatterns,
|
|
4548
|
+
Ut as announce,
|
|
4549
|
+
Yt as announceAssertive,
|
|
4550
|
+
Gt as announceError,
|
|
4551
|
+
Vt as announcePolite,
|
|
4552
|
+
Xt as announceStatus,
|
|
4553
|
+
Wt as aria,
|
|
4554
|
+
Jt as buildAriaProps,
|
|
4555
|
+
Qt as createFocusScope,
|
|
4556
|
+
Zt as createFocusTrap,
|
|
4557
|
+
te as createKeyboardManager,
|
|
4558
|
+
ee as createRovingTabindex,
|
|
4559
|
+
ie as createTypeAhead,
|
|
4560
|
+
se as hasAccessibleName,
|
|
4561
|
+
ae as initAnnouncer,
|
|
4562
|
+
re as initFocusVisible,
|
|
4563
|
+
oe as isBrowser,
|
|
4564
|
+
le as prefersDarkMode,
|
|
4565
|
+
ne as prefersHighContrast,
|
|
4566
|
+
he as prefersReducedMotion
|
|
4307
4567
|
};
|
|
4308
|
-
//# sourceMappingURL=compa11y.js.map
|