@italia/globals 1.0.0-alpha.8 → 1.0.0-alpha.9
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/custom-elements.json +23 -17
- package/dist/src/controllers/focus-trap-controller.d.ts +26 -20
- package/dist/src/controllers/focus-trap-controller.d.ts.map +1 -1
- package/dist/src/controllers/focus-trap-controller.js +95 -111
- package/dist/src/controllers/focus-trap-controller.js.map +1 -1
- package/dist/src/controllers/roving-tabindex-controller.d.ts +9 -2
- package/dist/src/controllers/roving-tabindex-controller.d.ts.map +1 -1
- package/dist/src/controllers/roving-tabindex-controller.js +11 -5
- package/dist/src/controllers/roving-tabindex-controller.js.map +1 -1
- package/dist/src/form/form-controller.d.ts.map +1 -1
- package/dist/src/form/form-controller.js +8 -0
- package/dist/src/form/form-controller.js.map +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/package.json +2 -2
package/custom-elements.json
CHANGED
|
@@ -810,7 +810,7 @@
|
|
|
810
810
|
"declarations": [
|
|
811
811
|
{
|
|
812
812
|
"kind": "class",
|
|
813
|
-
"description": "
|
|
813
|
+
"description": "Safari/VoiceOver iOS workarounds catalogue — why timers exist here:\n\n1. `activate()` rAF + setTimeout(50): Safari does not reliably update the VoiceOver\n accessibility tree synchronously. rAF ensures the element is painted before we\n attempt to focus it. setTimeout(50) yields 50ms so VoiceOver can settle its\n accessibility tree before announcing the newly focused element.\n Empirically, VoiceOver iOS needs 100–300ms; the animated path in it-modal already\n provides ~316ms naturally via animation.finished, so the 50ms here only truly\n matters for the no-animation / prefers-reduced-motion path.\n\n2. `_restoreFocus()` setTimeout(0): Same settle reason on close. The caller\n (it-modal finishHide) adds a belt-and-suspenders 20ms setTimeout; _restoreFocus\n is skipped via { skipFocusRestore: true } in that case to avoid double-focus.\n\n3. `activate()` iOS body-focus fallback: On iOS Safari, tapping a button does not\n reliably move document.activeElement away from body. We fall back to getTrigger()\n so _previousActiveElement is always a real DOM element to restore focus to on close.\n\nThere is no WebKit/Safari API to detect when VoiceOver has settled its accessibility\ntree. setTimeout-based workarounds are the same pattern used by Bootstrap 5, the\nfocus-trap npm package, and a11y-dialog.",
|
|
814
814
|
"name": "FocusTrapController",
|
|
815
815
|
"members": [
|
|
816
816
|
{
|
|
@@ -883,6 +883,16 @@
|
|
|
883
883
|
},
|
|
884
884
|
"privacy": "private"
|
|
885
885
|
},
|
|
886
|
+
{
|
|
887
|
+
"kind": "field",
|
|
888
|
+
"name": "_pendingFocusTimer",
|
|
889
|
+
"type": {
|
|
890
|
+
"text": "ReturnType<typeof setTimeout> | null"
|
|
891
|
+
},
|
|
892
|
+
"privacy": "private",
|
|
893
|
+
"default": "null",
|
|
894
|
+
"description": "Timer ID for the focus call scheduled inside activate(). Cancelled by deactivate()\nto prevent focus firing after the trap has been torn down (fast open/close, unmount)."
|
|
895
|
+
},
|
|
886
896
|
{
|
|
887
897
|
"kind": "field",
|
|
888
898
|
"name": "FOCUSABLE_SELECTORS",
|
|
@@ -924,7 +934,6 @@
|
|
|
924
934
|
"type": {
|
|
925
935
|
"text": "boolean"
|
|
926
936
|
},
|
|
927
|
-
"description": "Indica se il focus trap è attivo",
|
|
928
937
|
"readonly": true
|
|
929
938
|
},
|
|
930
939
|
{
|
|
@@ -934,8 +943,7 @@
|
|
|
934
943
|
"type": {
|
|
935
944
|
"text": "void"
|
|
936
945
|
}
|
|
937
|
-
}
|
|
938
|
-
"description": "Attiva il focus trap.\nSalva l'elemento attivo corrente e attiva i listener.\nNOTA: chiamare updateFocusableElements() e focusFirst() separatamente quando necessario."
|
|
946
|
+
}
|
|
939
947
|
},
|
|
940
948
|
{
|
|
941
949
|
"kind": "method",
|
|
@@ -945,7 +953,15 @@
|
|
|
945
953
|
"text": "void"
|
|
946
954
|
}
|
|
947
955
|
},
|
|
948
|
-
"
|
|
956
|
+
"parameters": [
|
|
957
|
+
{
|
|
958
|
+
"name": "options",
|
|
959
|
+
"optional": true,
|
|
960
|
+
"type": {
|
|
961
|
+
"text": "{ skipFocusRestore?: boolean }"
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
]
|
|
949
965
|
},
|
|
950
966
|
{
|
|
951
967
|
"kind": "method",
|
|
@@ -988,16 +1004,6 @@
|
|
|
988
1004
|
},
|
|
989
1005
|
"description": "Ritorna l'elemento attivo corrente, attraversando shadow DOM e slot"
|
|
990
1006
|
},
|
|
991
|
-
{
|
|
992
|
-
"kind": "method",
|
|
993
|
-
"name": "focusInitial",
|
|
994
|
-
"return": {
|
|
995
|
-
"type": {
|
|
996
|
-
"text": "void"
|
|
997
|
-
}
|
|
998
|
-
},
|
|
999
|
-
"description": "Metti a fuoco l'elemento iniziale specificato nella config, se presente.\nSe non è fornito, fallback sul primo elemento tabbabile."
|
|
1000
|
-
},
|
|
1001
1007
|
{
|
|
1002
1008
|
"kind": "field",
|
|
1003
1009
|
"name": "_handleKeyDown",
|
|
@@ -1067,10 +1073,10 @@
|
|
|
1067
1073
|
"kind": "field",
|
|
1068
1074
|
"name": "config",
|
|
1069
1075
|
"type": {
|
|
1070
|
-
"text": "RovingTabindexConfig<T> & {\n wrap: boolean;\n direction: 'horizontal' | 'vertical' | 'both';\n selectOnFocus: boolean;\n skipItem: (item: T) => boolean;\n }"
|
|
1076
|
+
"text": "RovingTabindexConfig<T> & {\n wrap: boolean;\n direction: 'horizontal' | 'vertical' | 'both' | (() => 'horizontal' | 'vertical' | 'both');\n selectOnFocus: boolean;\n selectOnHomeEnd: boolean;\n skipItem: (item: T) => boolean;\n }"
|
|
1071
1077
|
},
|
|
1072
1078
|
"privacy": "private",
|
|
1073
|
-
"default": "{ wrap: true, direction: 'both', selectOnFocus: false, skipItem: (item) => item.hasAttribute('disabled') || (item as any).disabled === true, ...config, }"
|
|
1079
|
+
"default": "{ wrap: true, direction: 'both', selectOnFocus: false, selectOnHomeEnd: false, skipItem: (item) => item.hasAttribute('disabled') || (item as any).disabled === true, ...config, }"
|
|
1074
1080
|
},
|
|
1075
1081
|
{
|
|
1076
1082
|
"kind": "method",
|
|
@@ -12,11 +12,27 @@ export interface FocusTrapConfig {
|
|
|
12
12
|
disableEscape?: boolean;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
* Implementa le linee guida WAI-ARIA per i dialog modali.
|
|
15
|
+
* Safari/VoiceOver iOS workarounds catalogue — why timers exist here:
|
|
17
16
|
*
|
|
18
|
-
|
|
19
|
-
*
|
|
17
|
+
* 1. `activate()` rAF + setTimeout(50): Safari does not reliably update the VoiceOver
|
|
18
|
+
* accessibility tree synchronously. rAF ensures the element is painted before we
|
|
19
|
+
* attempt to focus it. setTimeout(50) yields 50ms so VoiceOver can settle its
|
|
20
|
+
* accessibility tree before announcing the newly focused element.
|
|
21
|
+
* Empirically, VoiceOver iOS needs 100–300ms; the animated path in it-modal already
|
|
22
|
+
* provides ~316ms naturally via animation.finished, so the 50ms here only truly
|
|
23
|
+
* matters for the no-animation / prefers-reduced-motion path.
|
|
24
|
+
*
|
|
25
|
+
* 2. `_restoreFocus()` setTimeout(0): Same settle reason on close. The caller
|
|
26
|
+
* (it-modal finishHide) adds a belt-and-suspenders 20ms setTimeout; _restoreFocus
|
|
27
|
+
* is skipped via { skipFocusRestore: true } in that case to avoid double-focus.
|
|
28
|
+
*
|
|
29
|
+
* 3. `activate()` iOS body-focus fallback: On iOS Safari, tapping a button does not
|
|
30
|
+
* reliably move document.activeElement away from body. We fall back to getTrigger()
|
|
31
|
+
* so _previousActiveElement is always a real DOM element to restore focus to on close.
|
|
32
|
+
*
|
|
33
|
+
* There is no WebKit/Safari API to detect when VoiceOver has settled its accessibility
|
|
34
|
+
* tree. setTimeout-based workarounds are the same pattern used by Bootstrap 5, the
|
|
35
|
+
* focus-trap npm package, and a11y-dialog.
|
|
20
36
|
*/
|
|
21
37
|
export declare class FocusTrapController implements ReactiveController {
|
|
22
38
|
private host;
|
|
@@ -27,6 +43,9 @@ export declare class FocusTrapController implements ReactiveController {
|
|
|
27
43
|
private _focusableElements;
|
|
28
44
|
private _first;
|
|
29
45
|
private _last;
|
|
46
|
+
/** Timer ID for the focus call scheduled inside activate(). Cancelled by deactivate()
|
|
47
|
+
* to prevent focus firing after the trap has been torn down (fast open/close, unmount). */
|
|
48
|
+
private _pendingFocusTimer;
|
|
30
49
|
private static readonly FOCUSABLE_SELECTORS;
|
|
31
50
|
/**
|
|
32
51
|
* Verifica se un elemento è effettivamente focusabile e tabbabile.
|
|
@@ -36,19 +55,11 @@ export declare class FocusTrapController implements ReactiveController {
|
|
|
36
55
|
constructor(host: ReactiveControllerHost & HTMLElement, config: FocusTrapConfig);
|
|
37
56
|
hostConnected(): void;
|
|
38
57
|
hostDisconnected(): void;
|
|
39
|
-
/** Indica se il focus trap è attivo */
|
|
40
58
|
get isActive(): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Attiva il focus trap.
|
|
43
|
-
* Salva l'elemento attivo corrente e attiva i listener.
|
|
44
|
-
* NOTA: chiamare updateFocusableElements() e focusFirst() separatamente quando necessario.
|
|
45
|
-
*/
|
|
46
59
|
activate(): void;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*/
|
|
51
|
-
deactivate(): void;
|
|
60
|
+
deactivate(options?: {
|
|
61
|
+
skipFocusRestore?: boolean;
|
|
62
|
+
}): void;
|
|
52
63
|
/**
|
|
53
64
|
* Aggiorna la lista degli elementi focusabili.
|
|
54
65
|
* Chiamare dopo modifiche al DOM.
|
|
@@ -60,11 +71,6 @@ export declare class FocusTrapController implements ReactiveController {
|
|
|
60
71
|
focusLast(): void;
|
|
61
72
|
/** Ritorna l'elemento attivo corrente, attraversando shadow DOM e slot */
|
|
62
73
|
static getActiveElement(): HTMLElement | null;
|
|
63
|
-
/**
|
|
64
|
-
* Metti a fuoco l'elemento iniziale specificato nella config, se presente.
|
|
65
|
-
* Se non è fornito, fallback sul primo elemento tabbabile.
|
|
66
|
-
*/
|
|
67
|
-
focusInitial(): void;
|
|
68
74
|
private _handleKeyDown;
|
|
69
75
|
private _handleTab;
|
|
70
76
|
private _restoreFocus;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focus-trap-controller.d.ts","sourceRoot":"","sources":["../../../src/controllers/focus-trap-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,KAAK,CAAC;AAEjE,MAAM,WAAW,eAAe;IAC9B,2DAA2D;IAC3D,YAAY,EAAE,MAAM,WAAW,GAAG,UAAU,GAAG,IAAI,CAAC;IACpD,4EAA4E;IAC5E,UAAU,EAAE,MAAM,WAAW,GAAG,UAAU,GAAG,IAAI,CAAC;IAClD,0GAA0G;IAC1G,YAAY,CAAC,EAAE,MAAM,WAAW,GAAG,IAAI,CAAC;IACxC,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,qCAAqC;IACrC,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED
|
|
1
|
+
{"version":3,"file":"focus-trap-controller.d.ts","sourceRoot":"","sources":["../../../src/controllers/focus-trap-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,KAAK,CAAC;AAEjE,MAAM,WAAW,eAAe;IAC9B,2DAA2D;IAC3D,YAAY,EAAE,MAAM,WAAW,GAAG,UAAU,GAAG,IAAI,CAAC;IACpD,4EAA4E;IAC5E,UAAU,EAAE,MAAM,WAAW,GAAG,UAAU,GAAG,IAAI,CAAC;IAClD,0GAA0G;IAC1G,YAAY,CAAC,EAAE,MAAM,WAAW,GAAG,IAAI,CAAC;IACxC,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,qCAAqC;IACrC,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,mBAAoB,YAAW,kBAAkB;IAC5D,OAAO,CAAC,IAAI,CAAuC;IAEnD,OAAO,CAAC,MAAM,CAAkB;IAEhC,OAAO,CAAC,QAAQ,CAAiC;IAEjD,OAAO,CAAC,SAAS,CAAS;IAE1B,OAAO,CAAC,sBAAsB,CAA4B;IAE1D,OAAO,CAAC,kBAAkB,CAAa;IAEvC,OAAO,CAAC,MAAM,CAAM;IAEpB,OAAO,CAAC,KAAK,CAAM;IAEnB;gGAC4F;IAC5F,OAAO,CAAC,kBAAkB,CAA8C;IAExE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAQ/B;IAEZ;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;gBAoBd,IAAI,EAAE,sBAAsB,GAAG,WAAW,EAAE,MAAM,EAAE,eAAe;IAM/E,aAAa;IAMb,gBAAgB;IAQhB,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,QAAQ,IAAI,IAAI;IAgChB,UAAU,CAAC,OAAO,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAiB1D;;;OAGG;IACH,uBAAuB,IAAI,IAAI;IAuC/B,oDAAoD;IACpD,UAAU,IAAI,IAAI;IAIlB,sDAAsD;IACtD,SAAS,IAAI,IAAI;IAMjB,0EAA0E;IAC1E,MAAM,CAAC,gBAAgB,IAAI,WAAW,GAAG,IAAI;IAQ7C,OAAO,CAAC,cAAc,CAepB;IAEF,OAAO,CAAC,UAAU;IAyBlB,OAAO,CAAC,aAAa;CActB"}
|
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Implementa le linee guida WAI-ARIA per i dialog modali.
|
|
2
|
+
* Safari/VoiceOver iOS workarounds catalogue — why timers exist here:
|
|
4
3
|
*
|
|
5
|
-
|
|
6
|
-
*
|
|
4
|
+
* 1. `activate()` rAF + setTimeout(50): Safari does not reliably update the VoiceOver
|
|
5
|
+
* accessibility tree synchronously. rAF ensures the element is painted before we
|
|
6
|
+
* attempt to focus it. setTimeout(50) yields 50ms so VoiceOver can settle its
|
|
7
|
+
* accessibility tree before announcing the newly focused element.
|
|
8
|
+
* Empirically, VoiceOver iOS needs 100–300ms; the animated path in it-modal already
|
|
9
|
+
* provides ~316ms naturally via animation.finished, so the 50ms here only truly
|
|
10
|
+
* matters for the no-animation / prefers-reduced-motion path.
|
|
11
|
+
*
|
|
12
|
+
* 2. `_restoreFocus()` setTimeout(0): Same settle reason on close. The caller
|
|
13
|
+
* (it-modal finishHide) adds a belt-and-suspenders 20ms setTimeout; _restoreFocus
|
|
14
|
+
* is skipped via { skipFocusRestore: true } in that case to avoid double-focus.
|
|
15
|
+
*
|
|
16
|
+
* 3. `activate()` iOS body-focus fallback: On iOS Safari, tapping a button does not
|
|
17
|
+
* reliably move document.activeElement away from body. We fall back to getTrigger()
|
|
18
|
+
* so _previousActiveElement is always a real DOM element to restore focus to on close.
|
|
19
|
+
*
|
|
20
|
+
* There is no WebKit/Safari API to detect when VoiceOver has settled its accessibility
|
|
21
|
+
* tree. setTimeout-based workarounds are the same pattern used by Bootstrap 5, the
|
|
22
|
+
* focus-trap npm package, and a11y-dialog.
|
|
7
23
|
*/
|
|
8
24
|
export class FocusTrapController {
|
|
9
25
|
/**
|
|
@@ -13,39 +29,22 @@ export class FocusTrapController {
|
|
|
13
29
|
static isFocusable(el) {
|
|
14
30
|
if (typeof el.focus !== 'function')
|
|
15
31
|
return false;
|
|
16
|
-
|
|
17
|
-
if (el.hasAttribute('disabled'))
|
|
32
|
+
if (el.hasAttribute('disabled') || el.hasAttribute('inert') || el.hasAttribute('it-inert'))
|
|
18
33
|
return false;
|
|
19
|
-
// Escludi elementi con tabindex negativo (focusabili programmaticamente ma non tabbabili)
|
|
20
34
|
const tabindex = el.getAttribute('tabindex');
|
|
21
|
-
if (tabindex && parseInt(tabindex, 10) < 0)
|
|
35
|
+
if (tabindex && parseInt(tabindex, 10) < 0)
|
|
22
36
|
return false;
|
|
23
|
-
}
|
|
24
|
-
// Per custom elements (it-*), controlla anche il loro tabindex
|
|
25
37
|
if (el.tagName.toLowerCase().startsWith('it-')) {
|
|
26
|
-
|
|
27
|
-
if (tabindex && parseInt(tabindex, 10) < 0) {
|
|
38
|
+
if (tabindex && parseInt(tabindex, 10) < 0)
|
|
28
39
|
return false;
|
|
29
|
-
}
|
|
30
40
|
return true;
|
|
31
41
|
}
|
|
32
|
-
//
|
|
33
|
-
// Alcuni elementi (es. inline anchors, elementi dentro container positionati) possono
|
|
34
|
-
// avere offsetParent === null pur essendo visibili/focusabili. Usiamo quindi getClientRects
|
|
35
|
-
// e computedStyle come controllo più affidabile.
|
|
42
|
+
// Fix Race Condition Safari: durante l'apertura non fidarti di getClientRects o opacità
|
|
36
43
|
try {
|
|
37
|
-
// Se non ci sono bounding rects, probabilmente non è visibile
|
|
38
|
-
if (el.getClientRects()?.length === 0)
|
|
39
|
-
return false;
|
|
40
44
|
const style = window.getComputedStyle(el);
|
|
41
|
-
|
|
42
|
-
return false;
|
|
43
|
-
if (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0')
|
|
44
|
-
return false;
|
|
45
|
-
// Altrimenti consideriamo l'elemento focusabile
|
|
46
|
-
return true;
|
|
45
|
+
return style && style.display !== 'none' && style.visibility !== 'hidden';
|
|
47
46
|
}
|
|
48
|
-
catch
|
|
47
|
+
catch {
|
|
49
48
|
return false;
|
|
50
49
|
}
|
|
51
50
|
}
|
|
@@ -54,6 +53,9 @@ export class FocusTrapController {
|
|
|
54
53
|
this._isActive = false;
|
|
55
54
|
this._previousActiveElement = null;
|
|
56
55
|
this._focusableElements = [];
|
|
56
|
+
/** Timer ID for the focus call scheduled inside activate(). Cancelled by deactivate()
|
|
57
|
+
* to prevent focus firing after the trap has been torn down (fast open/close, unmount). */
|
|
58
|
+
this._pendingFocusTimer = null;
|
|
57
59
|
this._handleKeyDown = (event) => {
|
|
58
60
|
if (!this._isActive)
|
|
59
61
|
return;
|
|
@@ -75,15 +77,8 @@ export class FocusTrapController {
|
|
|
75
77
|
this.config = config;
|
|
76
78
|
this.host.addController(this);
|
|
77
79
|
}
|
|
78
|
-
// eslint-disable-next-line class-methods-use-this
|
|
79
80
|
hostConnected() {
|
|
80
|
-
|
|
81
|
-
// Set up our MutationObserver
|
|
82
|
-
const observerOptions = {
|
|
83
|
-
childList: true,
|
|
84
|
-
attributes: true,
|
|
85
|
-
subtree: true,
|
|
86
|
-
};
|
|
81
|
+
const observerOptions = { childList: true, attributes: true, subtree: true };
|
|
87
82
|
this.observer = new MutationObserver(this.updateFocusableElements.bind(this));
|
|
88
83
|
this.observer.observe(this.host, observerOptions);
|
|
89
84
|
}
|
|
@@ -94,37 +89,57 @@ export class FocusTrapController {
|
|
|
94
89
|
this.observer = null;
|
|
95
90
|
}
|
|
96
91
|
}
|
|
97
|
-
/** Indica se il focus trap è attivo */
|
|
98
92
|
get isActive() {
|
|
99
93
|
return this._isActive;
|
|
100
94
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Attiva il focus trap.
|
|
103
|
-
* Salva l'elemento attivo corrente e attiva i listener.
|
|
104
|
-
* NOTA: chiamare updateFocusableElements() e focusFirst() separatamente quando necessario.
|
|
105
|
-
*/
|
|
106
95
|
activate() {
|
|
107
96
|
if (this._isActive)
|
|
108
97
|
return;
|
|
109
98
|
this._isActive = true;
|
|
110
|
-
|
|
111
|
-
|
|
99
|
+
// FIX iOS: Safari non dà focus al tap. Se activeElement è body, salviamo il trigger della config.
|
|
100
|
+
const currentActive = FocusTrapController.getActiveElement();
|
|
101
|
+
this._previousActiveElement =
|
|
102
|
+
!currentActive || currentActive === document.body ? this.config.getTrigger() : currentActive;
|
|
103
|
+
// Usa document capture: cattura Tab/Escape prima di qualsiasi handler,
|
|
104
|
+
// indipendentemente da shadow DOM, delegatesFocus e slot retargeting.
|
|
105
|
+
document.addEventListener('keydown', this._handleKeyDown, true);
|
|
112
106
|
this.updateFocusableElements();
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
this.
|
|
107
|
+
// FIX Safari: trick engine
|
|
108
|
+
// Diamo al browser un istante per processare il ricalcolo del layout
|
|
109
|
+
requestAnimationFrame(() => {
|
|
110
|
+
if (this.config.initialFocus) {
|
|
111
|
+
const el = this.config.initialFocus();
|
|
112
|
+
if (el) {
|
|
113
|
+
// 50ms gives VoiceOver iOS time to settle its accessibility tree before
|
|
114
|
+
// announcing the focused element. See class-level comment for details.
|
|
115
|
+
this._pendingFocusTimer = setTimeout(() => {
|
|
116
|
+
this._pendingFocusTimer = null;
|
|
117
|
+
el.focus({ preventScroll: true });
|
|
118
|
+
}, 50);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
console.warn("FocusTrap: missing 'initialFocus' callback, provide one");
|
|
123
|
+
}
|
|
124
|
+
});
|
|
117
125
|
}
|
|
118
|
-
|
|
119
|
-
* Disattiva il focus trap.
|
|
120
|
-
* Ripristina il focus all'elemento precedentemente attivo.
|
|
121
|
-
*/
|
|
122
|
-
deactivate() {
|
|
126
|
+
deactivate(options) {
|
|
123
127
|
if (!this._isActive)
|
|
124
128
|
return;
|
|
129
|
+
// Cancel any in-flight focus timer so it cannot fire after the trap is torn down
|
|
130
|
+
// (e.g. fast open/close cycle, component unmounted while opening).
|
|
131
|
+
if (this._pendingFocusTimer !== null) {
|
|
132
|
+
clearTimeout(this._pendingFocusTimer);
|
|
133
|
+
this._pendingFocusTimer = null;
|
|
134
|
+
}
|
|
125
135
|
this._isActive = false;
|
|
126
|
-
|
|
127
|
-
|
|
136
|
+
document.removeEventListener('keydown', this._handleKeyDown, true);
|
|
137
|
+
if (!options?.skipFocusRestore) {
|
|
138
|
+
this._restoreFocus();
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
this._previousActiveElement = null;
|
|
142
|
+
}
|
|
128
143
|
}
|
|
129
144
|
/**
|
|
130
145
|
* Aggiorna la lista degli elementi focusabili.
|
|
@@ -140,7 +155,6 @@ export class FocusTrapController {
|
|
|
140
155
|
return;
|
|
141
156
|
}
|
|
142
157
|
const candidates = [];
|
|
143
|
-
// Tutti gli elementi focusable direttamente nel container
|
|
144
158
|
const direct = Array.from(container.querySelectorAll(FocusTrapController.FOCUSABLE_SELECTORS));
|
|
145
159
|
candidates.push(...direct);
|
|
146
160
|
// Tutti gli elementi slottati
|
|
@@ -149,14 +163,10 @@ export class FocusTrapController {
|
|
|
149
163
|
slot.assignedElements({ flatten: true }).forEach((el) => {
|
|
150
164
|
if (!(el instanceof HTMLElement))
|
|
151
165
|
return;
|
|
152
|
-
if (el === trigger)
|
|
166
|
+
if (el === trigger)
|
|
153
167
|
return;
|
|
154
|
-
|
|
155
|
-
// focusable diretto
|
|
156
|
-
if (el.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {
|
|
168
|
+
if (el.matches(FocusTrapController.FOCUSABLE_SELECTORS))
|
|
157
169
|
candidates.push(el);
|
|
158
|
-
}
|
|
159
|
-
// nested focusable dentro l'elemento assegnato
|
|
160
170
|
Array.from(el.querySelectorAll(FocusTrapController.FOCUSABLE_SELECTORS)).forEach((nested) => candidates.push(nested));
|
|
161
171
|
});
|
|
162
172
|
});
|
|
@@ -173,9 +183,8 @@ export class FocusTrapController {
|
|
|
173
183
|
}
|
|
174
184
|
/** Sposta il focus sul primo elemento focusabile */
|
|
175
185
|
focusFirst() {
|
|
176
|
-
if (this._first)
|
|
186
|
+
if (this._first)
|
|
177
187
|
this._first.focus();
|
|
178
|
-
}
|
|
179
188
|
}
|
|
180
189
|
/** Sposta il focus sull'ultimo elemento focusabile */
|
|
181
190
|
focusLast() {
|
|
@@ -191,70 +200,47 @@ export class FocusTrapController {
|
|
|
191
200
|
}
|
|
192
201
|
return active;
|
|
193
202
|
}
|
|
194
|
-
/**
|
|
195
|
-
* Metti a fuoco l'elemento iniziale specificato nella config, se presente.
|
|
196
|
-
* Se non è fornito, fallback sul primo elemento tabbabile.
|
|
197
|
-
*/
|
|
198
|
-
focusInitial() {
|
|
199
|
-
if (this.config.initialFocus) {
|
|
200
|
-
const el = this.config.initialFocus();
|
|
201
|
-
if (el && typeof el.focus === 'function') {
|
|
202
|
-
el.focus();
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
this.focusFirst();
|
|
207
|
-
}
|
|
208
203
|
_handleTab(event) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
204
|
+
// ANTI RACE CONDITION: se l'utente è troppo veloce, forza un ricalcolo immediato
|
|
205
|
+
if (this._focusableElements.length === 0)
|
|
206
|
+
this.updateFocusableElements();
|
|
207
|
+
if (this._focusableElements.length === 0)
|
|
208
|
+
return; // Se è ancora vuoto, non bloccare il Tab
|
|
214
209
|
event.preventDefault();
|
|
215
|
-
const firstElement = this._first;
|
|
216
|
-
const lastElement = this._last;
|
|
217
210
|
const activeElement = FocusTrapController.getActiveElement();
|
|
218
|
-
// Trova l'indice dell'elemento attivo
|
|
219
|
-
// Se activeElement è dentro uno shadow DOM di un custom element,
|
|
220
|
-
// cerca il custom element host nella lista
|
|
221
211
|
let currentIndex = this._focusableElements.indexOf(activeElement);
|
|
222
|
-
// Se non trovato, potrebbe essere un elemento interno ad un custom element
|
|
223
212
|
if (currentIndex === -1 && activeElement) {
|
|
224
|
-
// Risali attraverso gli shadow host
|
|
225
213
|
let parent = activeElement.getRootNode()?.host;
|
|
226
214
|
while (parent && currentIndex === -1) {
|
|
227
215
|
currentIndex = this._focusableElements.indexOf(parent);
|
|
228
|
-
if (currentIndex === -1)
|
|
216
|
+
if (currentIndex === -1)
|
|
229
217
|
parent = parent.getRootNode()?.host;
|
|
230
|
-
}
|
|
231
218
|
}
|
|
232
219
|
}
|
|
233
220
|
if (event.shiftKey) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
lastElement?.focus();
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
// Vai al precedente
|
|
221
|
+
if (currentIndex <= 0)
|
|
222
|
+
this._last?.focus();
|
|
223
|
+
else
|
|
241
224
|
this._focusableElements[currentIndex - 1]?.focus();
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
else if (currentIndex === -1 || currentIndex >= this._focusableElements.length - 1) {
|
|
245
|
-
// Tab: se non sei nella lista o sei sull'ultimo, vai al primo
|
|
246
|
-
firstElement?.focus();
|
|
247
225
|
}
|
|
248
|
-
else
|
|
249
|
-
|
|
226
|
+
else if (currentIndex === -1 || currentIndex >= this._focusableElements.length - 1)
|
|
227
|
+
this._first?.focus();
|
|
228
|
+
else
|
|
250
229
|
this._focusableElements[currentIndex + 1]?.focus();
|
|
251
|
-
}
|
|
252
230
|
}
|
|
253
231
|
_restoreFocus() {
|
|
254
|
-
|
|
255
|
-
this._previousActiveElement.focus();
|
|
256
|
-
}
|
|
232
|
+
const target = this._previousActiveElement;
|
|
257
233
|
this._previousActiveElement = null;
|
|
234
|
+
if (target && typeof target.focus === 'function' && document.contains(target)) {
|
|
235
|
+
// FIX Safari: blur the current element first so VoiceOver doesn't stay on the
|
|
236
|
+
// modal element while the accessibility tree processes the focus change.
|
|
237
|
+
FocusTrapController.getActiveElement()?.blur();
|
|
238
|
+
// FIX Safari/VoiceOver iOS: defer to the next macrotask so the accessibility
|
|
239
|
+
// tree has time to process the DOM mutation before announcing the restored element.
|
|
240
|
+
setTimeout(() => {
|
|
241
|
+
target.focus({ preventScroll: true });
|
|
242
|
+
}, 0);
|
|
243
|
+
}
|
|
258
244
|
}
|
|
259
245
|
}
|
|
260
246
|
FocusTrapController.FOCUSABLE_SELECTORS = [
|
|
@@ -264,8 +250,6 @@ FocusTrapController.FOCUSABLE_SELECTORS = [
|
|
|
264
250
|
'input:not([disabled]):not([type="hidden"])',
|
|
265
251
|
'select:not([disabled])',
|
|
266
252
|
'[tabindex]',
|
|
267
|
-
// '[role="dialog"]',
|
|
268
|
-
// Custom elements focusabili
|
|
269
253
|
'it-button:not([disabled])',
|
|
270
254
|
].join(',');
|
|
271
255
|
//# sourceMappingURL=focus-trap-controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focus-trap-controller.js","sourceRoot":"","sources":["../../../src/controllers/focus-trap-controller.ts"],"names":[],"mappings":"AAeA;;;;;;GAMG;AACH,MAAM,OAAO,mBAAmB;IA6B9B;;;OAGG;IACK,MAAM,CAAC,WAAW,CAAC,EAAe;QACxC,IAAI,OAAO,EAAE,CAAC,KAAK,KAAK,UAAU;YAAE,OAAO,KAAK,CAAC;QAEjD,gCAAgC;QAChC,IAAI,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC;YAAE,OAAO,KAAK,CAAC;QAE9C,0FAA0F;QAC1F,MAAM,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QAC7C,IAAI,QAAQ,IAAI,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3C,OAAO,KAAK,CAAC;QACf,CAAC;QAED,+DAA+D;QAC/D,IAAI,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/C,qDAAqD;YACrD,IAAI,QAAQ,IAAI,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC3C,OAAO,KAAK,CAAC;YACf,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,wEAAwE;QACxE,sFAAsF;QACtF,4FAA4F;QAC5F,iDAAiD;QACjD,IAAI,CAAC;YACH,8DAA8D;YAC9D,IAAI,EAAE,CAAC,cAAc,EAAE,EAAE,MAAM,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC;YAEpD,MAAM,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;YAC1C,IAAI,CAAC,KAAK;gBAAE,OAAO,KAAK,CAAC;YACzB,IAAI,KAAK,CAAC,OAAO,KAAK,MAAM,IAAI,KAAK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AK,CAAC,QAAQ,EAAE,CAAC;YACnB,iCAAiC;YACjC,IAAI,YAAY,IAAI,CAAC,EAAE,CAAC;gBACtB,yDAAyD;gBACzD,WAAW,EAAE,KAAK,EAAE,CAAC;YACvB,CAAC;iBAAM,CAAC;gBACN,oBAAoB;gBACpB,IAAI,CAAC,kBAAkB,CAAC,YAAY,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;YACrD,CAAC;QACH,CAAC;aAAM,IAAI,YAAY,KAAK,CAAC,CAAC,IAAI,YAAY,IAAI,IAAI,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrF,8DAA8D;YAC9D,YAAY,EAAE,KAAK,EAAE,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,oBAAoB;YACpB,IAAI,CAAC,kBAAkB,CAAC,YAAY,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;QACrD,CAAC;IACH,CAAC;IAEO,aAAa;QACnB,IAAI,IAAI,CAAC,sBAAsB,IAAI,OAAO,IAAI,CAAC,sBAAsB,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;YAC3F,IAAI,CAAC,sBAAsB,CAAC,KAAK,EAAE,CAAC;QACtC,CAAC;QACD,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC;IACrC,CAAC;;AAtRuB,uCAAmB,GAAG;IAC5C,SAAS;IACT,wBAAwB;IACxB,0BAA0B;IAC1B,4CAA4C;IAC5C,wBAAwB;IACxB,YAAY;IACZ,qBAAqB;IACrB,6BAA6B;IAC7B,2BAA2B;CAC5B,CAAC,IAAI,CAAC,GAAG,CAAC,AAVgC,CAU/B","sourcesContent":["import { ReactiveController, ReactiveControllerHost } from 'lit';\n\nexport interface FocusTrapConfig {\n /** Funzione che ritorna l'elemento contenitore del trap */\n getContainer: () => HTMLElement | ShadowRoot | null;\n /** Funzione che ritorna l'elemento trigger che ha attivato il focus trap */\n getTrigger: () => HTMLElement | ShadowRoot | null;\n /** Opzionale: funzione che ritorna l'elemento da mettere a fuoco all'apertura (può essere tabindex -1) */\n initialFocus?: () => HTMLElement | null;\n /** Callback quando viene premuto Escape */\n onEscape?: () => void;\n /** Se true, non chiude con Escape */\n disableEscape?: boolean;\n}\n\n/**\n * Controller per gestire il focus trap all'interno di un elemento.\n * Implementa le linee guida WAI-ARIA per i dialog modali.\n *\n\n * ```\n */\nexport class FocusTrapController implements ReactiveController {\n private host: ReactiveControllerHost & HTMLElement;\n\n private config: FocusTrapConfig;\n\n private observer: MutationObserver | null = null;\n\n private _isActive = false;\n\n private _previousActiveElement: HTMLElement | null = null;\n\n private _focusableElements: any[] = [];\n\n private _first: any;\n\n private _last: any;\n\n private static readonly FOCUSABLE_SELECTORS = [\n 'a[href]',\n 'button:not([disabled])',\n 'textarea:not([disabled])',\n 'input:not([disabled]):not([type=\"hidden\"])',\n 'select:not([disabled])',\n '[tabindex]',\n // '[role=\"dialog\"]',\n // Custom elements focusabili\n 'it-button:not([disabled])',\n ].join(',');\n\n /**\n * Verifica se un elemento è effettivamente focusabile e tabbabile.\n * Elementi con tabindex=\"-1\" sono focusabili programmaticamente ma non tabbabili.\n */\n private static isFocusable(el: HTMLElement): boolean {\n if (typeof el.focus !== 'function') return false;\n\n // Escludi elementi disabilitati\n if (el.hasAttribute('disabled')) return false;\n\n // Escludi elementi con tabindex negativo (focusabili programmaticamente ma non tabbabili)\n const tabindex = el.getAttribute('tabindex');\n if (tabindex && parseInt(tabindex, 10) < 0) {\n return false;\n }\n\n // Per custom elements (it-*), controlla anche il loro tabindex\n if (el.tagName.toLowerCase().startsWith('it-')) {\n // Se ha tabindex esplicito negativo, non è tabbabile\n if (tabindex && parseInt(tabindex, 10) < 0) {\n return false;\n }\n return true;\n }\n\n // Per elementi standard, controlliamo anche visibilità in modo robusto.\n // Alcuni elementi (es. inline anchors, elementi dentro container positionati) possono\n // avere offsetParent === null pur essendo visibili/focusabili. Usiamo quindi getClientRects\n // e computedStyle come controllo più affidabile.\n try {\n // Se non ci sono bounding rects, probabilmente non è visibile\n if (el.getClientRects()?.length === 0) return false;\n\n const style = window.getComputedStyle(el);\n if (!style) return false;\n if (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0') return false;\n\n // Altrimenti consideriamo l'elemento focusabile\n return true;\n } catch (e) {\n return false;\n }\n }\n\n constructor(host: ReactiveControllerHost & HTMLElement, config: FocusTrapConfig) {\n this.host = host;\n this.config = config;\n this.host.addController(this);\n }\n\n // eslint-disable-next-line class-methods-use-this\n hostConnected() {\n // Controller ready\n // Set up our MutationObserver\n const observerOptions = {\n childList: true,\n attributes: true,\n subtree: true,\n };\n this.observer = new MutationObserver(this.updateFocusableElements.bind(this));\n this.observer.observe(this.host, observerOptions);\n }\n\n hostDisconnected() {\n this.deactivate();\n if (this.observer) {\n this.observer.disconnect();\n this.observer = null;\n }\n }\n\n /** Indica se il focus trap è attivo */\n get isActive(): boolean {\n return this._isActive;\n }\n\n /**\n * Attiva il focus trap.\n * Salva l'elemento attivo corrente e attiva i listener.\n * NOTA: chiamare updateFocusableElements() e focusFirst() separatamente quando necessario.\n */\n activate(): void {\n if (this._isActive) return;\n\n this._isActive = true;\n this._previousActiveElement = FocusTrapController.getActiveElement();\n\n this.host.addEventListener('keydown', this._handleKeyDown);\n this.updateFocusableElements();\n if (typeof this.focusInitial === 'function') this.focusInitial();\n else this.focusFirst();\n }\n\n /**\n * Disattiva il focus trap.\n * Ripristina il focus all'elemento precedentemente attivo.\n */\n deactivate(): void {\n if (!this._isActive) return;\n\n this._isActive = false;\n this.host.removeEventListener('keydown', this._handleKeyDown);\n this._restoreFocus();\n }\n\n /**\n * Aggiorna la lista degli elementi focusabili.\n * Chiamare dopo modifiche al DOM.\n */\n updateFocusableElements(): void {\n const container = this.config.getContainer();\n const trigger = this.config.getTrigger();\n if (!container) {\n this._focusableElements = [];\n this._first = undefined;\n this._last = undefined;\n return;\n }\n\n const candidates: HTMLElement[] = [];\n\n // Tutti gli elementi focusable direttamente nel container\n const direct = Array.from(container.querySelectorAll<HTMLElement>(FocusTrapController.FOCUSABLE_SELECTORS));\n candidates.push(...direct);\n\n // Tutti gli elementi slottati\n const slots = Array.from(container.querySelectorAll('slot'));\n slots.forEach((slot) => {\n slot.assignedElements({ flatten: true }).forEach((el) => {\n if (!(el instanceof HTMLElement)) return;\n if (el === trigger) {\n return;\n }\n // focusable diretto\n if (el.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {\n candidates.push(el);\n }\n\n // nested focusable dentro l'elemento assegnato\n Array.from(el.querySelectorAll<HTMLElement>(FocusTrapController.FOCUSABLE_SELECTORS)).forEach((nested) =>\n candidates.push(nested),\n );\n });\n });\n // Filtra solo elementi veramente focusabili e rimuovi duplicati\n this._focusableElements = Array.from(new Set(candidates)).filter((el) => {\n // Escludi esplicitamente il container/dialog stesso\n if (el === this.config.getContainer()) return false;\n return FocusTrapController.isFocusable(el);\n });\n\n // Aggiorna primo/ultimo\n this._first = this._focusableElements?.[0];\n this._last = this._focusableElements[this._focusableElements.length - 1];\n }\n\n /** Sposta il focus sul primo elemento focusabile */\n focusFirst(): void {\n if (this._first) {\n this._first.focus();\n }\n }\n\n /** Sposta il focus sull'ultimo elemento focusabile */\n focusLast(): void {\n if (this._last) {\n this._last.focus();\n }\n }\n\n /** Ritorna l'elemento attivo corrente, attraversando shadow DOM e slot */\n static getActiveElement(): HTMLElement | null {\n let active = document.activeElement;\n while (active && active.shadowRoot && active.shadowRoot.activeElement) {\n active = active.shadowRoot.activeElement;\n }\n return active as HTMLElement | null;\n }\n\n /**\n * Metti a fuoco l'elemento iniziale specificato nella config, se presente.\n * Se non è fornito, fallback sul primo elemento tabbabile.\n */\n focusInitial(): void {\n if (this.config.initialFocus) {\n const el = this.config.initialFocus();\n if (el && typeof el.focus === 'function') {\n el.focus();\n return;\n }\n }\n\n this.focusFirst();\n }\n\n private _handleKeyDown = (event: KeyboardEvent): void => {\n if (!this._isActive) return;\n\n switch (event.key) {\n case 'Escape':\n if (!this.config.disableEscape && this.config.onEscape) {\n event.preventDefault();\n this.config.onEscape();\n }\n break;\n case 'Tab':\n this._handleTab(event);\n break;\n default:\n break;\n }\n };\n\n private _handleTab(event: KeyboardEvent): void {\n if (this._focusableElements.length === 0) {\n event.preventDefault();\n return;\n }\n\n // SEMPRE previeni il default - gestiamo noi la navigazione\n event.preventDefault();\n\n const firstElement = this._first;\n const lastElement = this._last;\n const activeElement = FocusTrapController.getActiveElement();\n\n // Trova l'indice dell'elemento attivo\n // Se activeElement è dentro uno shadow DOM di un custom element,\n // cerca il custom element host nella lista\n let currentIndex = this._focusableElements.indexOf(activeElement as HTMLElement);\n\n // Se non trovato, potrebbe essere un elemento interno ad un custom element\n if (currentIndex === -1 && activeElement) {\n // Risali attraverso gli shadow host\n let parent = (activeElement.getRootNode() as ShadowRoot)?.host;\n while (parent && currentIndex === -1) {\n currentIndex = this._focusableElements.indexOf(parent as HTMLElement);\n if (currentIndex === -1) {\n parent = (parent.getRootNode() as ShadowRoot)?.host;\n }\n }\n }\n\n if (event.shiftKey) {\n // Shift + Tab: vai al precedente\n if (currentIndex <= 0) {\n // Se sei sul primo o non sei nella lista, vai all'ultimo\n lastElement?.focus();\n } else {\n // Vai al precedente\n this._focusableElements[currentIndex - 1]?.focus();\n }\n } else if (currentIndex === -1 || currentIndex >= this._focusableElements.length - 1) {\n // Tab: se non sei nella lista o sei sull'ultimo, vai al primo\n firstElement?.focus();\n } else {\n // Vai al successivo\n this._focusableElements[currentIndex + 1]?.focus();\n }\n }\n\n private _restoreFocus(): void {\n if (this._previousActiveElement && typeof this._previousActiveElement.focus === 'function') {\n this._previousActiveElement.focus();\n }\n this._previousActiveElement = null;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"focus-trap-controller.js","sourceRoot":"","sources":["../../../src/controllers/focus-trap-controller.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,mBAAmB;IA+B9B;;;OAGG;IACK,MAAM,CAAC,WAAW,CAA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AC,CAAC,EAAE,KAAK,EAAE,CAAC;QAC1D,CAAC;aAAM,IAAI,YAAY,KAAK,CAAC,CAAC,IAAI,YAAY,IAAI,IAAI,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC;YAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;;YACtG,IAAI,CAAC,kBAAkB,CAAC,YAAY,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;IAC1D,CAAC;IAEO,aAAa;QACnB,MAAM,MAAM,GAAG,IAAI,CAAC,sBAAsB,CAAC;QAC3C,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC;QACnC,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,UAAU,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9E,8EAA8E;YAC9E,yEAAyE;YACzE,mBAAmB,CAAC,gBAAgB,EAAE,EAAE,IAAI,EAAE,CAAC;YAC/C,6EAA6E;YAC7E,oFAAoF;YACpF,UAAU,CAAC,GAAG,EAAE;gBACd,MAAM,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;YACxC,CAAC,EAAE,CAAC,CAAC,CAAC;QACR,CAAC;IACH,CAAC;;AAlOuB,uCAAmB,GAAG;IAC5C,SAAS;IACT,wBAAwB;IACxB,0BAA0B;IAC1B,4CAA4C;IAC5C,wBAAwB;IACxB,YAAY;IACZ,2BAA2B;CAC5B,CAAC,IAAI,CAAC,GAAG,CAAC,AARgC,CAQ/B","sourcesContent":["import { ReactiveController, ReactiveControllerHost } from 'lit';\n\nexport interface FocusTrapConfig {\n /** Funzione che ritorna l'elemento contenitore del trap */\n getContainer: () => HTMLElement | ShadowRoot | null;\n /** Funzione che ritorna l'elemento trigger che ha attivato il focus trap */\n getTrigger: () => HTMLElement | ShadowRoot | null;\n /** Opzionale: funzione che ritorna l'elemento da mettere a fuoco all'apertura (può essere tabindex -1) */\n initialFocus?: () => HTMLElement | null;\n /** Callback quando viene premuto Escape */\n onEscape?: () => void;\n /** Se true, non chiude con Escape */\n disableEscape?: boolean;\n}\n\n/**\n * Safari/VoiceOver iOS workarounds catalogue — why timers exist here:\n *\n * 1. `activate()` rAF + setTimeout(50): Safari does not reliably update the VoiceOver\n * accessibility tree synchronously. rAF ensures the element is painted before we\n * attempt to focus it. setTimeout(50) yields 50ms so VoiceOver can settle its\n * accessibility tree before announcing the newly focused element.\n * Empirically, VoiceOver iOS needs 100–300ms; the animated path in it-modal already\n * provides ~316ms naturally via animation.finished, so the 50ms here only truly\n * matters for the no-animation / prefers-reduced-motion path.\n *\n * 2. `_restoreFocus()` setTimeout(0): Same settle reason on close. The caller\n * (it-modal finishHide) adds a belt-and-suspenders 20ms setTimeout; _restoreFocus\n * is skipped via { skipFocusRestore: true } in that case to avoid double-focus.\n *\n * 3. `activate()` iOS body-focus fallback: On iOS Safari, tapping a button does not\n * reliably move document.activeElement away from body. We fall back to getTrigger()\n * so _previousActiveElement is always a real DOM element to restore focus to on close.\n *\n * There is no WebKit/Safari API to detect when VoiceOver has settled its accessibility\n * tree. setTimeout-based workarounds are the same pattern used by Bootstrap 5, the\n * focus-trap npm package, and a11y-dialog.\n */\nexport class FocusTrapController implements ReactiveController {\n private host: ReactiveControllerHost & HTMLElement;\n\n private config: FocusTrapConfig;\n\n private observer: MutationObserver | null = null;\n\n private _isActive = false;\n\n private _previousActiveElement: HTMLElement | null = null;\n\n private _focusableElements: any[] = [];\n\n private _first: any;\n\n private _last: any;\n\n /** Timer ID for the focus call scheduled inside activate(). Cancelled by deactivate()\n * to prevent focus firing after the trap has been torn down (fast open/close, unmount). */\n private _pendingFocusTimer: ReturnType<typeof setTimeout> | null = null;\n\n private static readonly FOCUSABLE_SELECTORS = [\n 'a[href]',\n 'button:not([disabled])',\n 'textarea:not([disabled])',\n 'input:not([disabled]):not([type=\"hidden\"])',\n 'select:not([disabled])',\n '[tabindex]',\n 'it-button:not([disabled])',\n ].join(',');\n\n /**\n * Verifica se un elemento è effettivamente focusabile e tabbabile.\n * Elementi con tabindex=\"-1\" sono focusabili programmaticamente ma non tabbabili.\n */\n private static isFocusable(el: HTMLElement): boolean {\n if (typeof el.focus !== 'function') return false;\n if (el.hasAttribute('disabled') || el.hasAttribute('inert') || el.hasAttribute('it-inert')) return false;\n const tabindex = el.getAttribute('tabindex');\n if (tabindex && parseInt(tabindex, 10) < 0) return false;\n\n if (el.tagName.toLowerCase().startsWith('it-')) {\n if (tabindex && parseInt(tabindex, 10) < 0) return false;\n return true;\n }\n\n // Fix Race Condition Safari: durante l'apertura non fidarti di getClientRects o opacità\n try {\n const style = window.getComputedStyle(el);\n return style && style.display !== 'none' && style.visibility !== 'hidden';\n } catch {\n return false;\n }\n }\n\n constructor(host: ReactiveControllerHost & HTMLElement, config: FocusTrapConfig) {\n this.host = host;\n this.config = config;\n this.host.addController(this);\n }\n\n hostConnected() {\n const observerOptions = { childList: true, attributes: true, subtree: true };\n this.observer = new MutationObserver(this.updateFocusableElements.bind(this));\n this.observer.observe(this.host, observerOptions);\n }\n\n hostDisconnected() {\n this.deactivate();\n if (this.observer) {\n this.observer.disconnect();\n this.observer = null;\n }\n }\n\n get isActive(): boolean {\n return this._isActive;\n }\n\n activate(): void {\n if (this._isActive) return;\n this._isActive = true;\n\n // FIX iOS: Safari non dà focus al tap. Se activeElement è body, salviamo il trigger della config.\n const currentActive = FocusTrapController.getActiveElement();\n this._previousActiveElement =\n !currentActive || currentActive === document.body ? (this.config.getTrigger() as HTMLElement) : currentActive;\n\n // Usa document capture: cattura Tab/Escape prima di qualsiasi handler,\n // indipendentemente da shadow DOM, delegatesFocus e slot retargeting.\n document.addEventListener('keydown', this._handleKeyDown, true);\n this.updateFocusableElements();\n // FIX Safari: trick engine\n // Diamo al browser un istante per processare il ricalcolo del layout\n requestAnimationFrame(() => {\n if (this.config.initialFocus) {\n const el = this.config.initialFocus();\n if (el) {\n // 50ms gives VoiceOver iOS time to settle its accessibility tree before\n // announcing the focused element. See class-level comment for details.\n this._pendingFocusTimer = setTimeout(() => {\n this._pendingFocusTimer = null;\n el.focus({ preventScroll: true });\n }, 50);\n }\n } else {\n console.warn(\"FocusTrap: missing 'initialFocus' callback, provide one\");\n }\n });\n }\n\n deactivate(options?: { skipFocusRestore?: boolean }): void {\n if (!this._isActive) return;\n // Cancel any in-flight focus timer so it cannot fire after the trap is torn down\n // (e.g. fast open/close cycle, component unmounted while opening).\n if (this._pendingFocusTimer !== null) {\n clearTimeout(this._pendingFocusTimer);\n this._pendingFocusTimer = null;\n }\n this._isActive = false;\n document.removeEventListener('keydown', this._handleKeyDown, true);\n if (!options?.skipFocusRestore) {\n this._restoreFocus();\n } else {\n this._previousActiveElement = null;\n }\n }\n\n /**\n * Aggiorna la lista degli elementi focusabili.\n * Chiamare dopo modifiche al DOM.\n */\n updateFocusableElements(): void {\n const container = this.config.getContainer();\n const trigger = this.config.getTrigger();\n if (!container) {\n this._focusableElements = [];\n this._first = undefined;\n this._last = undefined;\n return;\n }\n\n const candidates: HTMLElement[] = [];\n const direct = Array.from(container.querySelectorAll<HTMLElement>(FocusTrapController.FOCUSABLE_SELECTORS));\n candidates.push(...direct);\n\n // Tutti gli elementi slottati\n const slots = Array.from(container.querySelectorAll('slot'));\n slots.forEach((slot) => {\n slot.assignedElements({ flatten: true }).forEach((el) => {\n if (!(el instanceof HTMLElement)) return;\n if (el === trigger) return;\n if (el.matches(FocusTrapController.FOCUSABLE_SELECTORS)) candidates.push(el);\n Array.from(el.querySelectorAll<HTMLElement>(FocusTrapController.FOCUSABLE_SELECTORS)).forEach((nested) =>\n candidates.push(nested),\n );\n });\n });\n\n // Filtra solo elementi veramente focusabili e rimuovi duplicati\n this._focusableElements = Array.from(new Set(candidates)).filter((el) => {\n // Escludi esplicitamente il container/dialog stesso\n if (el === this.config.getContainer()) return false;\n return FocusTrapController.isFocusable(el);\n });\n\n // Aggiorna primo/ultimo\n this._first = this._focusableElements?.[0];\n this._last = this._focusableElements[this._focusableElements.length - 1];\n }\n\n /** Sposta il focus sul primo elemento focusabile */\n focusFirst(): void {\n if (this._first) this._first.focus();\n }\n\n /** Sposta il focus sull'ultimo elemento focusabile */\n focusLast(): void {\n if (this._last) {\n this._last.focus();\n }\n }\n\n /** Ritorna l'elemento attivo corrente, attraversando shadow DOM e slot */\n static getActiveElement(): HTMLElement | null {\n let active = document.activeElement;\n while (active && active.shadowRoot && active.shadowRoot.activeElement) {\n active = active.shadowRoot.activeElement;\n }\n return active as HTMLElement | null;\n }\n\n private _handleKeyDown = (event: KeyboardEvent): void => {\n if (!this._isActive) return;\n switch (event.key) {\n case 'Escape':\n if (!this.config.disableEscape && this.config.onEscape) {\n event.preventDefault();\n this.config.onEscape();\n }\n break;\n case 'Tab':\n this._handleTab(event);\n break;\n default:\n break;\n }\n };\n\n private _handleTab(event: KeyboardEvent): void {\n // ANTI RACE CONDITION: se l'utente è troppo veloce, forza un ricalcolo immediato\n if (this._focusableElements.length === 0) this.updateFocusableElements();\n if (this._focusableElements.length === 0) return; // Se è ancora vuoto, non bloccare il Tab\n\n event.preventDefault();\n\n const activeElement = FocusTrapController.getActiveElement();\n let currentIndex = this._focusableElements.indexOf(activeElement as HTMLElement);\n\n if (currentIndex === -1 && activeElement) {\n let parent = (activeElement.getRootNode() as ShadowRoot)?.host;\n while (parent && currentIndex === -1) {\n currentIndex = this._focusableElements.indexOf(parent as HTMLElement);\n if (currentIndex === -1) parent = (parent.getRootNode() as ShadowRoot)?.host;\n }\n }\n\n if (event.shiftKey) {\n if (currentIndex <= 0) this._last?.focus();\n else this._focusableElements[currentIndex - 1]?.focus();\n } else if (currentIndex === -1 || currentIndex >= this._focusableElements.length - 1) this._first?.focus();\n else this._focusableElements[currentIndex + 1]?.focus();\n }\n\n private _restoreFocus(): void {\n const target = this._previousActiveElement;\n this._previousActiveElement = null;\n if (target && typeof target.focus === 'function' && document.contains(target)) {\n // FIX Safari: blur the current element first so VoiceOver doesn't stay on the\n // modal element while the accessibility tree processes the focus change.\n FocusTrapController.getActiveElement()?.blur();\n // FIX Safari/VoiceOver iOS: defer to the next macrotask so the accessibility\n // tree has time to process the DOM mutation before announcing the restored element.\n setTimeout(() => {\n target.focus({ preventScroll: true });\n }, 0);\n }\n }\n}\n"]}
|
|
@@ -14,15 +14,22 @@ export interface RovingTabindexConfig<T extends HTMLElement> {
|
|
|
14
14
|
*/
|
|
15
15
|
wrap?: boolean;
|
|
16
16
|
/**
|
|
17
|
-
* Direction of navigation
|
|
17
|
+
* Direction of navigation. Può essere una stringa statica o una funzione
|
|
18
|
+
* che restituisce la direzione dinamicamente (utile quando la direzione
|
|
19
|
+
* dipende dallo stato del componente, es. orientamento verticale/orizzontale).
|
|
18
20
|
* @default 'both'
|
|
19
21
|
*/
|
|
20
|
-
direction?: 'horizontal' | 'vertical' | 'both';
|
|
22
|
+
direction?: 'horizontal' | 'vertical' | 'both' | (() => 'horizontal' | 'vertical' | 'both');
|
|
21
23
|
/**
|
|
22
24
|
* Whether to select items on focus (vs just focusing)
|
|
23
25
|
* @default false
|
|
24
26
|
*/
|
|
25
27
|
selectOnFocus?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Whether Home/End should *activate* (select) the item in addition to focusing it.
|
|
30
|
+
* Default false to avoid changing downstream components; opt-in when needed.
|
|
31
|
+
*/
|
|
32
|
+
selectOnHomeEnd?: boolean;
|
|
26
33
|
/**
|
|
27
34
|
* Custom logic to determine if an item should be skipped
|
|
28
35
|
* @default (item) => item.hasAttribute('disabled')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roving-tabindex-controller.d.ts","sourceRoot":"","sources":["../../../src/controllers/roving-tabindex-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,KAAK,CAAC;AAEjE,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,WAAW;IACzD;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC;IAEp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B;;;OAGG;IACH,gBAAgB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IA8B5C;;;;;OAKG;IACH,aAAa,CAAC,WAAW,EAAE,CAAC,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO;IA+E5D;;OAEG;IACH,OAAO,CAAC,YAAY;IAmBpB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAkB1B;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAUxB;;OAEG;IACH,UAAU,IAAI,IAAI;IASlB;;OAEG;IACH,SAAS,IAAI,IAAI;CAQlB"}
|
|
@@ -19,6 +19,7 @@ export class RovingTabindexController {
|
|
|
19
19
|
wrap: true,
|
|
20
20
|
direction: 'both',
|
|
21
21
|
selectOnFocus: false,
|
|
22
|
+
selectOnHomeEnd: false,
|
|
22
23
|
skipItem: (item) => item.hasAttribute('disabled') || item.disabled === true,
|
|
23
24
|
...config,
|
|
24
25
|
};
|
|
@@ -70,7 +71,7 @@ export class RovingTabindexController {
|
|
|
70
71
|
* @returns true if the event was handled, false otherwise
|
|
71
72
|
*/
|
|
72
73
|
handleKeydown(currentItem, event) {
|
|
73
|
-
const
|
|
74
|
+
const direction = typeof this.config.direction === 'function' ? this.config.direction() : this.config.direction;
|
|
74
75
|
const { key } = event;
|
|
75
76
|
// Determine if this key should be handled based on direction
|
|
76
77
|
const isVertical = key === 'ArrowUp' || key === 'ArrowDown';
|
|
@@ -111,16 +112,21 @@ export class RovingTabindexController {
|
|
|
111
112
|
nextIndex = this.getNextIndex(items, currentIndex, -1);
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
|
-
// Skip disabled items
|
|
115
|
-
|
|
115
|
+
// Skip disabled items — Home always searches forward, End always searches backward
|
|
116
|
+
// eslint-disable-next-line no-nested-ternary
|
|
117
|
+
const searchDirection = isHome ? 1 : isEnd ? -1 : nextIndex > currentIndex ? 1 : -1;
|
|
118
|
+
nextIndex = this.findNextValidIndex(items, nextIndex, searchDirection);
|
|
116
119
|
if (nextIndex !== -1 && nextIndex !== currentIndex) {
|
|
117
120
|
const nextItem = items[nextIndex];
|
|
118
121
|
// Update tabindices
|
|
119
122
|
this.updateTabindices(nextIndex);
|
|
120
123
|
// Focus the next item
|
|
121
124
|
nextItem.focus();
|
|
122
|
-
// Optionally select/activate the item
|
|
123
|
-
|
|
125
|
+
// Optionally select/activate the item.
|
|
126
|
+
// Select when `selectOnFocus` is enabled, or when Home/End keys
|
|
127
|
+
// were used and the consumer explicitly opted in via `selectOnHomeEnd`.
|
|
128
|
+
const shouldSelect = this.config.selectOnFocus === true || ((isHome || isEnd) && this.config.selectOnHomeEnd === true);
|
|
129
|
+
if (shouldSelect && this.config.onSelect) {
|
|
124
130
|
this.config.onSelect(nextItem, event);
|
|
125
131
|
}
|
|
126
132
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roving-tabindex-controller.js","sourceRoot":"","sources":["../../../src/controllers/roving-tabindex-controller.ts"],"names":[],"mappings":"AAsCA;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,wBAAwB;IAUnC,YAAY,IAA4B,EAAE,MAA+B;QACvE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG;YACZ,IAAI,EAAE,IAAI;YACV,SAAS,EAAE,MAAM;YACjB,aAAa,EAAE,KAAK;YACpB,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAK,IAAY,CAAC,QAAQ,KAAK,IAAI;YACpF,GAAG,MAAM;SACV,CAAC;QACF,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,kDAAkD;IAClD,aAAa;QACX,yCAAyC;IAC3C,CAAC;IAED,kDAAkD;IAClD,gBAAgB;QACd,oBAAoB;IACtB,CAAC;IAED;;;OAGG;IACH,gBAAgB,CAAC,WAAoB;QACnC,MAAM,KA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AI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAE7D,IAAI,eAAe,KAAK,CAAC,CAAC,EAAE,CAAC;YAC3B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,SAAS;QACP,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrC,MAAM,cAAc,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAE5E,IAAI,cAAc,KAAK,CAAC,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF","sourcesContent":["import { ReactiveController, ReactiveControllerHost } from 'lit';\n\nexport interface RovingTabindexConfig<T extends HTMLElement> {\n /**\n * Selector or function to get the items to manage\n */\n getItems: () => T[];\n\n /**\n * Callback when an item is selected/activated\n */\n onSelect?: (item: T, event: KeyboardEvent | PointerEvent | MouseEvent) => void;\n\n /**\n * Whether items wrap around (last -> first and vice versa)\n * @default true\n */\n wrap?: boolean;\n\n /**\n * Direction of navigation\n * @default 'both'\n */\n direction?: 'horizontal' | 'vertical' | 'both';\n\n /**\n * Whether to select items on focus (vs just focusing)\n * @default false\n */\n selectOnFocus?: boolean;\n\n /**\n * Custom logic to determine if an item should be skipped\n * @default (item) => item.hasAttribute('disabled')\n */\n skipItem?: (item: T) => boolean;\n}\n\n/**\n * Roving Tabindex Controller\n *\n * Implements the ARIA roving tabindex pattern for keyboard navigation.\n * See: https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_roving_tabindex\n *\n * Usage:\n * ```ts\n * private rovingTabindex = new RovingTabindexController(this, {\n * getItems: () => Array.from(this.querySelectorAll('my-item')),\n * onSelect: (item) => this.selectItem(item),\n * });\n * ```\n */\nexport class RovingTabindexController<T extends HTMLElement> implements ReactiveController {\n private host: ReactiveControllerHost;\n\n private config: RovingTabindexConfig<T> & {\n wrap: boolean;\n direction: 'horizontal' | 'vertical' | 'both';\n selectOnFocus: boolean;\n skipItem: (item: T) => boolean;\n };\n\n constructor(host: ReactiveControllerHost, config: RovingTabindexConfig<T>) {\n this.host = host;\n this.config = {\n wrap: true,\n direction: 'both',\n selectOnFocus: false,\n skipItem: (item) => item.hasAttribute('disabled') || (item as any).disabled === true,\n ...config,\n };\n host.addController(this);\n }\n\n // eslint-disable-next-line class-methods-use-this\n hostConnected(): void {\n // Controller is ready when host connects\n }\n\n // eslint-disable-next-line class-methods-use-this\n hostDisconnected(): void {\n // Cleanup if needed\n }\n\n /**\n * Update tabindex values for all items\n * @param activeIndex - Index of the item that should be tabbable (default: 0 or first non-disabled)\n */\n updateTabindices(activeIndex?: number): void {\n const items = this.config.getItems();\n if (!items || items.length === 0) {\n return;\n }\n\n // Find the active index\n let targetIndex = activeIndex ?? 0;\n\n // If no active index specified, use first non-disabled item\n if (activeIndex === undefined) {\n targetIndex = items.findIndex((item) => !this.config.skipItem(item));\n if (targetIndex === -1) {\n targetIndex = 0; // Fallback to first item if all disabled\n }\n }\n\n // Set tabindex for all items\n items.forEach((item, index) => {\n const itemElement = item;\n if (this.config.skipItem(itemElement)) {\n // eslint-disable-next-line no-param-reassign\n itemElement.tabIndex = -1;\n } else {\n // eslint-disable-next-line no-param-reassign\n itemElement.tabIndex = index === targetIndex ? 0 : -1;\n }\n });\n }\n\n /**\n * Handle keyboard navigation\n * @param currentItem - The currently focused item\n * @param event - The keyboard event\n * @returns true if the event was handled, false otherwise\n */\n handleKeydown(currentItem: T, event: KeyboardEvent): boolean {\n const { direction } = this.config;\n const { key } = event;\n\n // Determine if this key should be handled based on direction\n const isVertical = key === 'ArrowUp' || key === 'ArrowDown';\n const isHorizontal = key === 'ArrowLeft' || key === 'ArrowRight';\n const isHome = key === 'Home';\n const isEnd = key === 'End';\n\n const shouldHandle =\n isHome ||\n isEnd ||\n (direction === 'both' && (isVertical || isHorizontal)) ||\n (direction === 'vertical' && isVertical) ||\n (direction === 'horizontal' && isHorizontal);\n\n if (!shouldHandle) {\n return false;\n }\n\n // Prevent default behavior (page scrolling)\n event.preventDefault();\n\n const items = this.config.getItems();\n const currentIndex = items.indexOf(currentItem);\n\n if (currentIndex === -1) {\n return false;\n }\n\n let nextIndex = currentIndex;\n\n // Handle Home/End keys\n if (isHome) {\n nextIndex = 0;\n } else if (isEnd) {\n nextIndex = items.length - 1;\n } else {\n // Handle arrow keys\n const isNext = key === 'ArrowDown' || key === 'ArrowRight';\n const isPrev = key === 'ArrowUp' || key === 'ArrowLeft';\n\n if (isNext) {\n nextIndex = this.getNextIndex(items, currentIndex, 1);\n } else if (isPrev) {\n nextIndex = this.getNextIndex(items, currentIndex, -1);\n }\n }\n\n // Skip disabled items\n nextIndex = this.findNextValidIndex(items, nextIndex, nextIndex > currentIndex ? 1 : -1);\n\n if (nextIndex !== -1 && nextIndex !== currentIndex) {\n const nextItem = items[nextIndex];\n\n // Update tabindices\n this.updateTabindices(nextIndex);\n\n // Focus the next item\n nextItem.focus();\n\n // Optionally select/activate the item\n if (this.config.selectOnFocus && this.config.onSelect) {\n this.config.onSelect(nextItem, event);\n }\n\n return true;\n }\n\n return false;\n }\n\n /**\n * Get the next index based on direction\n */\n private getNextIndex(items: T[], currentIndex: number, direction: 1 | -1): number {\n const { wrap } = this.config;\n let nextIndex = currentIndex + direction;\n\n if (wrap) {\n // Wrap around\n if (nextIndex < 0) {\n nextIndex = items.length - 1;\n } else if (nextIndex >= items.length) {\n nextIndex = 0;\n }\n } else {\n // Clamp to bounds\n nextIndex = Math.max(0, Math.min(items.length - 1, nextIndex));\n }\n\n return nextIndex;\n }\n\n /**\n * Find the next valid (non-disabled) index\n */\n private findNextValidIndex(items: T[], startIndex: number, direction: 1 | -1): number {\n const maxAttempts = items.length;\n let attempts = 0;\n let index = startIndex;\n\n while (attempts < maxAttempts) {\n if (!this.config.skipItem(items[index])) {\n return index;\n }\n\n index = this.getNextIndex(items, index, direction);\n attempts += 1;\n }\n\n // All items are disabled\n return -1;\n }\n\n /**\n * Set focus to a specific item\n */\n focusItem(item: T): void {\n const items = this.config.getItems();\n const index = items.indexOf(item);\n\n if (index !== -1) {\n this.updateTabindices(index);\n item.focus();\n }\n }\n\n /**\n * Set focus to the first non-disabled item\n */\n focusFirst(): void {\n const items = this.config.getItems();\n const firstValidIndex = this.findNextValidIndex(items, 0, 1);\n\n if (firstValidIndex !== -1) {\n this.focusItem(items[firstValidIndex]);\n }\n }\n\n /**\n * Set focus to the last non-disabled item\n */\n focusLast(): void {\n const items = this.config.getItems();\n const lastValidIndex = this.findNextValidIndex(items, items.length - 1, -1);\n\n if (lastValidIndex !== -1) {\n this.focusItem(items[lastValidIndex]);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"roving-tabindex-controller.js","sourceRoot":"","sources":["../../../src/controllers/roving-tabindex-controller.ts"],"names":[],"mappings":"AA8CA;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,wBAAwB;IAWnC,YAAY,IAA4B,EAAE,MAA+B;QACvE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG;YACZ,IAAI,EAAE,IAAI;YACV,SAAS,EAAE,MAAM;YACjB,aAAa,EAAE,KAAK;YACpB,eAAe,EAAE,KAAK;YACtB,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAK,IAAY,CAAC,QAAQ,KAAK,IAAI;YACpF,GAAG,MAAM;SACV,CAAC;QACF,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,kDAAkD;IAClD,aAAa;QACX,yCAAyC;IAC3C,CAAC;IAED,kDAAkD;IAClD,gBAAgB;QACd,oBAAo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AAC,CAAC;QAChB,CAAC;QAED,yBAAyB;QACzB,OAAO,CAAC,CAAC,CAAC;IACZ,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,IAAO;QACf,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAElC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACjB,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;YAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;IACH,CAAC;IAED;;OAEG;IACH,UAAU;QACR,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrC,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAE7D,IAAI,eAAe,KAAK,CAAC,CAAC,EAAE,CAAC;YAC3B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,SAAS;QACP,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrC,MAAM,cAAc,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAE5E,IAAI,cAAc,KAAK,CAAC,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF","sourcesContent":["import { ReactiveController, ReactiveControllerHost } from 'lit';\n\nexport interface RovingTabindexConfig<T extends HTMLElement> {\n /**\n * Selector or function to get the items to manage\n */\n getItems: () => T[];\n\n /**\n * Callback when an item is selected/activated\n */\n onSelect?: (item: T, event: KeyboardEvent | PointerEvent | MouseEvent) => void;\n\n /**\n * Whether items wrap around (last -> first and vice versa)\n * @default true\n */\n wrap?: boolean;\n\n /**\n * Direction of navigation. Può essere una stringa statica o una funzione\n * che restituisce la direzione dinamicamente (utile quando la direzione\n * dipende dallo stato del componente, es. orientamento verticale/orizzontale).\n * @default 'both'\n */\n direction?: 'horizontal' | 'vertical' | 'both' | (() => 'horizontal' | 'vertical' | 'both');\n\n /**\n * Whether to select items on focus (vs just focusing)\n * @default false\n */\n selectOnFocus?: boolean;\n\n /**\n * Whether Home/End should *activate* (select) the item in addition to focusing it.\n * Default false to avoid changing downstream components; opt-in when needed.\n */\n selectOnHomeEnd?: boolean;\n\n /**\n * Custom logic to determine if an item should be skipped\n * @default (item) => item.hasAttribute('disabled')\n */\n skipItem?: (item: T) => boolean;\n}\n\n/**\n * Roving Tabindex Controller\n *\n * Implements the ARIA roving tabindex pattern for keyboard navigation.\n * See: https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_roving_tabindex\n *\n * Usage:\n * ```ts\n * private rovingTabindex = new RovingTabindexController(this, {\n * getItems: () => Array.from(this.querySelectorAll('my-item')),\n * onSelect: (item) => this.selectItem(item),\n * });\n * ```\n */\nexport class RovingTabindexController<T extends HTMLElement> implements ReactiveController {\n private host: ReactiveControllerHost;\n\n private config: RovingTabindexConfig<T> & {\n wrap: boolean;\n direction: 'horizontal' | 'vertical' | 'both' | (() => 'horizontal' | 'vertical' | 'both');\n selectOnFocus: boolean;\n selectOnHomeEnd: boolean;\n skipItem: (item: T) => boolean;\n };\n\n constructor(host: ReactiveControllerHost, config: RovingTabindexConfig<T>) {\n this.host = host;\n this.config = {\n wrap: true,\n direction: 'both',\n selectOnFocus: false,\n selectOnHomeEnd: false,\n skipItem: (item) => item.hasAttribute('disabled') || (item as any).disabled === true,\n ...config,\n };\n host.addController(this);\n }\n\n // eslint-disable-next-line class-methods-use-this\n hostConnected(): void {\n // Controller is ready when host connects\n }\n\n // eslint-disable-next-line class-methods-use-this\n hostDisconnected(): void {\n // Cleanup if needed\n }\n\n /**\n * Update tabindex values for all items\n * @param activeIndex - Index of the item that should be tabbable (default: 0 or first non-disabled)\n */\n updateTabindices(activeIndex?: number): void {\n const items = this.config.getItems();\n if (!items || items.length === 0) {\n return;\n }\n\n // Find the active index\n let targetIndex = activeIndex ?? 0;\n\n // If no active index specified, use first non-disabled item\n if (activeIndex === undefined) {\n targetIndex = items.findIndex((item) => !this.config.skipItem(item));\n if (targetIndex === -1) {\n targetIndex = 0; // Fallback to first item if all disabled\n }\n }\n\n // Set tabindex for all items\n items.forEach((item, index) => {\n const itemElement = item;\n if (this.config.skipItem(itemElement)) {\n // eslint-disable-next-line no-param-reassign\n itemElement.tabIndex = -1;\n } else {\n // eslint-disable-next-line no-param-reassign\n itemElement.tabIndex = index === targetIndex ? 0 : -1;\n }\n });\n }\n\n /**\n * Handle keyboard navigation\n * @param currentItem - The currently focused item\n * @param event - The keyboard event\n * @returns true if the event was handled, false otherwise\n */\n handleKeydown(currentItem: T, event: KeyboardEvent): boolean {\n const direction = typeof this.config.direction === 'function' ? this.config.direction() : this.config.direction;\n const { key } = event;\n\n // Determine if this key should be handled based on direction\n const isVertical = key === 'ArrowUp' || key === 'ArrowDown';\n const isHorizontal = key === 'ArrowLeft' || key === 'ArrowRight';\n const isHome = key === 'Home';\n const isEnd = key === 'End';\n const shouldHandle =\n isHome ||\n isEnd ||\n (direction === 'both' && (isVertical || isHorizontal)) ||\n (direction === 'vertical' && isVertical) ||\n (direction === 'horizontal' && isHorizontal);\n\n if (!shouldHandle) {\n return false;\n }\n\n // Prevent default behavior (page scrolling)\n event.preventDefault();\n\n const items = this.config.getItems();\n const currentIndex = items.indexOf(currentItem);\n\n if (currentIndex === -1) {\n return false;\n }\n\n let nextIndex = currentIndex;\n\n // Handle Home/End keys\n if (isHome) {\n nextIndex = 0;\n } else if (isEnd) {\n nextIndex = items.length - 1;\n } else {\n // Handle arrow keys\n const isNext = key === 'ArrowDown' || key === 'ArrowRight';\n const isPrev = key === 'ArrowUp' || key === 'ArrowLeft';\n\n if (isNext) {\n nextIndex = this.getNextIndex(items, currentIndex, 1);\n } else if (isPrev) {\n nextIndex = this.getNextIndex(items, currentIndex, -1);\n }\n }\n\n // Skip disabled items — Home always searches forward, End always searches backward\n // eslint-disable-next-line no-nested-ternary\n const searchDirection: 1 | -1 = isHome ? 1 : isEnd ? -1 : nextIndex > currentIndex ? 1 : -1;\n nextIndex = this.findNextValidIndex(items, nextIndex, searchDirection);\n\n if (nextIndex !== -1 && nextIndex !== currentIndex) {\n const nextItem = items[nextIndex];\n\n // Update tabindices\n this.updateTabindices(nextIndex);\n\n // Focus the next item\n nextItem.focus();\n\n // Optionally select/activate the item.\n // Select when `selectOnFocus` is enabled, or when Home/End keys\n // were used and the consumer explicitly opted in via `selectOnHomeEnd`.\n const shouldSelect =\n this.config.selectOnFocus === true || ((isHome || isEnd) && this.config.selectOnHomeEnd === true);\n\n if (shouldSelect && this.config.onSelect) {\n this.config.onSelect(nextItem, event);\n }\n\n return true;\n }\n\n return false;\n }\n\n /**\n * Get the next index based on direction\n */\n private getNextIndex(items: T[], currentIndex: number, direction: 1 | -1): number {\n const { wrap } = this.config;\n let nextIndex = currentIndex + direction;\n\n if (wrap) {\n // Wrap around\n if (nextIndex < 0) {\n nextIndex = items.length - 1;\n } else if (nextIndex >= items.length) {\n nextIndex = 0;\n }\n } else {\n // Clamp to bounds\n nextIndex = Math.max(0, Math.min(items.length - 1, nextIndex));\n }\n\n return nextIndex;\n }\n\n /**\n * Find the next valid (non-disabled) index\n */\n private findNextValidIndex(items: T[], startIndex: number, direction: 1 | -1): number {\n const maxAttempts = items.length;\n let attempts = 0;\n let index = startIndex;\n\n while (attempts < maxAttempts) {\n if (!this.config.skipItem(items[index])) {\n return index;\n }\n\n index = this.getNextIndex(items, index, direction);\n attempts += 1;\n }\n\n // All items are disabled\n return -1;\n }\n\n /**\n * Set focus to a specific item\n */\n focusItem(item: T): void {\n const items = this.config.getItems();\n const index = items.indexOf(item);\n\n if (index !== -1) {\n this.updateTabindices(index);\n item.focus();\n }\n }\n\n /**\n * Set focus to the first non-disabled item\n */\n focusFirst(): void {\n const items = this.config.getItems();\n const firstValidIndex = this.findNextValidIndex(items, 0, 1);\n\n if (firstValidIndex !== -1) {\n this.focusItem(items[firstValidIndex]);\n }\n }\n\n /**\n * Set focus to the last non-disabled item\n */\n focusLast(): void {\n const items = this.config.getItems();\n const lastValidIndex = this.findNextValidIndex(items, items.length - 1, -1);\n\n if (lastValidIndex !== -1) {\n this.focusItem(items[lastValidIndex]);\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-controller.d.ts","sourceRoot":"","sources":["../../../src/form/form-controller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,KAAK,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOhD,eAAO,MAAM,eAAe,EAAE,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,WAAW,CAAC,CAAiB,CAAC;AAoBzF,MAAM,WAAW,4BAA4B;IAC3C,oEAAoE;IACpE,IAAI,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,eAAe,GAAG,IAAI,CAAC;IACrD,mGAAmG;IACnG,IAAI,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,CAAC;IACrC,gEAAgE;IAChE,KAAK,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,GAAG,OAAO,EAAE,CAAC;IACnD,oHAAoH;IACpH,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IAK1C,cAAc,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IAMhD,aAAa,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IAC/C,oDAAoD;IACpD,QAAQ,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E,KAAK;CAgB9C"}
|
|
@@ -57,6 +57,14 @@ export class FormControlController {
|
|
|
57
57
|
case 'it-toggle-group':
|
|
58
58
|
// non settare valori in formData, perchè ogni singola checkbox setta il suo valore
|
|
59
59
|
break;
|
|
60
|
+
case 'it-upload':
|
|
61
|
+
// value is File[] — append each File object directly (not as string)
|
|
62
|
+
if (Array.isArray(value)) {
|
|
63
|
+
value.forEach((file) => {
|
|
64
|
+
event.formData.append(name, file);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
60
68
|
default:
|
|
61
69
|
if (Array.isArray(value)) {
|
|
62
70
|
value.forEach((val) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-controller.js","sourceRoot":"","sources":["../../../src/form/form-controller.ts"],"names":[],"mappings":"AAIA,EAAE;AACF,8GAA8G;AAC9G,oHAAoH;AACpH,uDAAuD;AACvD,EAAE;AACF,MAAM,CAAC,MAAM,eAAe,GAA+C,IAAI,OAAO,EAAE,CAAC;AAEzF,EAAE;AACF,mHAAmH;AACnH,sDAAsD;AACtD,EAAE;AACF,MAAM,uBAAuB,GAA4C,IAAI,OAAO,EAAE,CAAC;AACvF,MAAM,sBAAsB,GAA4C,IAAI,OAAO,EAAE,CAAC;AAEtF,EAAE;AACF,gHAAgH;AAChH,6DAA6D;AAC7D,EAAE;AACF,MAAM,sBAAsB,GAAyB,IAAI,OAAO,EAAE,CAAC;AAEnE,EAAE;AACF,uHAAuH;AACvH,EAAE;AACF,MAAM,YAAY,GAAG,IAAI,OAAO,EAAyB,CAAC;AA8B1D,uGAAuG;AACvG,MAAM,OAAO,qBAAqB;IAShC,YAAY,IAA0C,EAAE,OAA+C;QAFvG,kBAAa,GAAY,KAAK,CAAC;QAqJvB,mBAAc,GAAG,CAAC,KAAoB,EAAE,EAAE;YAChD,iCAAiC;YACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,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EAAE,CAAC;YAC7C,oBAAoB,EAAE,cAAc,EAAE,CAAC;QACzC,CAAC;IACH,CAAC;CACF","sourcesContent":["/* eslint-disable prefer-destructuring */\nimport type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport { FormControl } from './form-control.js';\n\n//\n// We store a WeakMap of forms + controls so we can keep references to all FormControl within a given form. As\n// elements connect and disconnect to/from the DOM, their containing form is used as the key and the form control is\n// added and removed from the form's set, respectively.\n//\nexport const formCollections: WeakMap<HTMLFormElement, Set<FormControl>> = new WeakMap();\n\n//\n// We store a WeakMap of reportValidity() overloads so we can override it when form controls connect to the DOM and\n// restore the original behavior when they disconnect.\n//\nconst reportValidityOverloads: WeakMap<HTMLFormElement, () => boolean> = new WeakMap();\nconst checkValidityOverloads: WeakMap<HTMLFormElement, () => boolean> = new WeakMap();\n\n//\n// We store a Set of controls that users have interacted with. This allows us to determine the interaction state\n// without littering the DOM with additional data attributes.\n//\nconst userInteractedControls: WeakSet<FormControl> = new WeakSet();\n\n//\n// We store a WeakMap of interactions for each form control so we can track when all conditions are met for validation.\n//\nconst interactions = new WeakMap<FormControl, string[]>();\n\nexport interface FormControlControllerOptions {\n /** A function that returns the form containing the form control. */\n form: (input: FormControl) => HTMLFormElement | null;\n /** A function that returns the form control's name, which will be submitted with the form data. */\n name: (input: FormControl) => string;\n /** A function that returns the form control's current value. */\n value: (input: FormControl) => unknown | unknown[];\n /** A function that returns the form control's current disabled state. If disabled, the value won't be submitted. */\n disabled: (input: FormControl) => boolean;\n // /**\n // * A function that maps to the form control's reportValidity() function. When the control is invalid, this will\n // * prevent submission and trigger the browser's constraint violation warning.\n // */\n reportValidity: (input: FormControl) => boolean;\n\n // /**\n // * A function that maps to the form control's `checkValidity()` function. When the control is invalid, this will return false.\n // * this is helpful is you want to check validation without triggering the native browser constraint violation warning.\n // */\n checkValidity: (input: FormControl) => boolean;\n /** A function that sets the form control's value */\n setValue: (input: FormControl, value: unknown) => void;\n /**\n * An array of event names to listen to. When all events in the list are emitted, the control will receive validity\n * states such as user-valid and user-invalid.user interacted validity states. */\n assumeInteractionOn: string[];\n}\n\n/** A reactive controller to allow form controls to participate in form submission, validation, etc. */\nexport class FormControlController implements ReactiveController {\n host: FormControl & ReactiveControllerHost;\n\n form?: HTMLFormElement | null;\n\n options: FormControlControllerOptions;\n\n submittedOnce: boolean = false;\n\n constructor(host: ReactiveControllerHost & FormControl, options?: Partial<FormControlControllerOptions>) {\n (this.host = host).addController(this);\n this.options = {\n form: (input) => {\n // If there's a form attribute, use it to find the target form by id\n // Controls may not always reflect the 'form' property. For example, `<it-button>` doesn't reflect.\n const formId = input.form;\n\n if (formId) {\n const root = input.getRootNode() as Document | ShadowRoot | HTMLElement;\n const form = root.querySelector(`#${formId}`);\n\n if (form) {\n return form as HTMLFormElement;\n }\n }\n\n return input.closest('form');\n },\n name: (input) => input.name,\n value: (input) => input.value,\n disabled: (input) => input.disabled ?? false,\n reportValidity: (input: FormControl) =>\n typeof input.reportValidity === 'function' ? input.reportValidity() : true,\n checkValidity: (input: FormControl) => (typeof input.checkValidity === 'function' ? input.checkValidity() : true),\n setValue: (input, value) => {\n // eslint-disable-next-line no-param-reassign\n input.value = value as string;\n },\n assumeInteractionOn: ['it-input'],\n ...options,\n };\n }\n\n hostConnected() {\n const form = this.options.form(this.host);\n if (form) {\n this.attachForm(form);\n }\n\n // Listen for interactions\n interactions.set(this.host, []);\n this.options.assumeInteractionOn.forEach((event) => {\n this.host.addEventListener(event, this.handleInteraction);\n });\n }\n\n hostDisconnected() {\n this.detachForm();\n\n // Clean up interactions\n interactions.delete(this.host);\n this.options.assumeInteractionOn.forEach((event) => {\n this.host.removeEventListener(event, this.handleInteraction);\n });\n }\n\n hostUpdated() {\n const form = this.options.form(this.host);\n\n // Detach if the form no longer exists\n if (!form) {\n this.detachForm();\n }\n\n // If the form has changed, reattach it\n if (form && this.form !== form) {\n this.detachForm();\n this.attachForm(form);\n }\n\n if (this.host.hasUpdated) {\n this.setValidity(this.host.validity.valid);\n }\n }\n\n private attachForm(form?: HTMLFormElement) {\n if (form) {\n this.form = form;\n\n // Add this element to the form's collection\n if (formCollections.has(this.form)) {\n formCollections.get(this.form)!.add(this.host);\n } else {\n formCollections.set(this.form, new Set<FormControl>([this.host]));\n }\n\n this.form.addEventListener('formdata', this.handleFormData);\n this.form.addEventListener('submit', this.handleFormSubmit);\n this.form.addEventListener('reset', this.handleFormReset);\n\n // Overload the form's reportValidity() method so it looks at FormControl\n if (!reportValidityOverloads.has(this.form)) {\n reportValidityOverloads.set(this.form, this.form.reportValidity);\n this.form.reportValidity = () => this.reportFormValidity();\n }\n\n // Overload the form's checkValidity() method so it looks at FormControl\n if (!checkValidityOverloads.has(this.form)) {\n checkValidityOverloads.set(this.form, this.form.checkValidity);\n this.form.checkValidity = () => this.checkFormValidity();\n }\n } else {\n this.form = undefined;\n }\n }\n\n private detachForm() {\n if (!this.form) return;\n\n const formCollection = formCollections.get(this.form);\n\n if (!formCollection) {\n return;\n }\n this.submittedOnce = false;\n\n // Remove this host from the form's collection\n formCollection.delete(this.host);\n\n // Check to make sure there's no other form controls in the collection. If we do this\n // without checking if any other controls are still in the collection, then we will wipe out the\n // validity checks for all other elements.\n // see: https://github.com/shoelace-style/shoelace/issues/1703\n if (formCollection.size <= 0) {\n this.form.removeEventListener('formdata', this.handleFormData);\n this.form.removeEventListener('submit', this.handleFormSubmit);\n this.form.removeEventListener('reset', this.handleFormReset);\n\n // Remove the overload and restore the original method\n if (reportValidityOverloads.has(this.form)) {\n this.form.reportValidity = reportValidityOverloads.get(this.form)!;\n reportValidityOverloads.delete(this.form);\n }\n\n if (checkValidityOverloads.has(this.form)) {\n this.form.checkValidity = checkValidityOverloads.get(this.form)!;\n checkValidityOverloads.delete(this.form);\n }\n\n // So it looks weird here to not always set the form to undefined. But I _think_ if we unattach this.form here,\n // we end up in this fun spot where future validity checks don't have a reference to the form validity handler.\n // First form element in sets the validity handler. So we can't clean up `this.form` until there are no other form elements in the form.\n this.form = undefined;\n }\n }\n\n private handleFormData = (event: FormDataEvent) => {\n // console.log('handleFormData');\n const disabled = this.options.disabled(this.host);\n const name = this.options.name(this.host);\n const value = this.options.value(this.host);\n const tagName = this.host.tagName.toLowerCase();\n\n // For buttons, we only submit the value if they were the submitter. This is currently done in doAction() by\n // injecting the name/value on a temporary button, so we can just skip them here.\n const isButton = tagName === 'it-button';\n\n if (\n this.host.isConnected &&\n !disabled &&\n !isButton &&\n typeof name === 'string' &&\n name.length > 0 &&\n typeof value !== 'undefined'\n ) {\n switch (tagName) {\n case 'it-radio':\n if ((this.host as any).checked) {\n event.formData.append(name, value as string);\n }\n break;\n case 'it-checkbox':\n case 'it-toggle':\n if ((this.host as any).checked) {\n if (event.formData.getAll(name).indexOf(value as string) < 0) {\n // handle group checkbox\n event.formData.append(name, value as string);\n }\n }\n break;\n case 'it-checkbox-group':\n case 'it-toggle-group':\n // non settare valori in formData, perchè ogni singola checkbox setta il suo valore\n break;\n default:\n if (Array.isArray(value)) {\n (value as unknown[]).forEach((val) => {\n event.formData.append(name, (val as string | number | boolean).toString());\n });\n } else {\n event.formData.append(name, (value as string | number | boolean).toString());\n }\n }\n }\n };\n\n private handleFormSubmit = (event: Event) => {\n const disabled = this.options.disabled(this.host);\n const reportValidity = this.options.reportValidity;\n\n // Update the interacted state for all controls when the form is submitted\n if (this.form && !this.form.noValidate) {\n formCollections.get(this.form)?.forEach((control) => {\n this.setUserInteracted(control, true);\n });\n }\n\n const resReportValidity = reportValidity(this.host);\n\n if (this.form && !this.form.noValidate && !disabled && !resReportValidity) {\n event.preventDefault();\n // event.stopImmediatePropagation(); // se lo attiviamo, valida un campo alla volta\n\n // Scroll al primo controllo non valido\n const formControls = formCollections.get(this.form);\n if (formControls) {\n for (const control of formControls) {\n if (!control.validity?.valid) {\n // Scroll smooth verso il controllo non valido\n control.scrollIntoView({\n behavior: 'smooth',\n block: 'center',\n });\n break;\n }\n }\n }\n }\n this.submittedOnce = true;\n };\n\n private handleFormReset = () => {\n this.options.setValue(this.host, '');\n this.submittedOnce = false;\n this.setUserInteracted(this.host, false);\n interactions.set(this.host, []);\n };\n\n private handleInteraction = (event: Event) => {\n const emittedEvents = interactions.get(this.host)!;\n\n if (!emittedEvents.includes(event.type)) {\n emittedEvents.push(event.type);\n }\n\n // Mark it as user-interacted as soon as all associated events have been emitted\n if (emittedEvents.length === this.options.assumeInteractionOn.length) {\n this.setUserInteracted(this.host, true);\n }\n };\n\n private checkFormValidity = () => {\n // console.log('checkFormValidity');\n //\n // This is very similar to the `reportFormValidity` function, but it does not trigger native constraint validation\n // Allow the user to simply check if the form is valid and handling validity in their own way.\n //\n // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger\n // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't\n // be necessary once we can use ElementInternals.\n //\n // Note that we're also honoring the form's novalidate attribute.\n //\n if (this.form && !this.form.noValidate) {\n // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom\n // elements that support the constraint validation API.\n const elements = this.form.querySelectorAll<HTMLInputElement>('*');\n\n for (const element of elements) {\n if (typeof element.checkValidity === 'function') {\n if (!element.checkValidity()) {\n return false;\n }\n }\n }\n }\n\n return true;\n };\n\n private reportFormValidity = () => {\n // console.log('reportFormValidity');\n //\n // FormControl work hard to act like regular form controls. They support the Constraint Validation API\n // and its associated methods such as setCustomValidity() and reportValidity(). However, the HTMLFormElement also\n // has a reportValidity() method that will trigger validation on all child controls. Since we're not yet using\n // ElementInternals, we need to overload this method so it looks for any element with the reportValidity() method.\n //\n // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger\n // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't\n // be necessary once we can use ElementInternals.\n //\n // Note that we're also honoring the form's novalidate attribute.\n //\n if (this.form && !this.form.noValidate) {\n // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom\n // elements that support the constraint validation API.\n const elements = this.form.querySelectorAll<HTMLInputElement>('*');\n\n for (const element of elements) {\n if (typeof element.reportValidity === 'function') {\n if (!element.reportValidity()) {\n return false;\n }\n }\n }\n }\n\n return true;\n };\n\n // eslint-disable-next-line class-methods-use-this\n private setUserInteracted(el: FormControl, hasInteracted: boolean) {\n if (hasInteracted) {\n userInteractedControls.add(el);\n } else {\n userInteractedControls.delete(el);\n }\n\n el.requestUpdate();\n }\n\n private doAction(type: 'submit' | 'reset', submitter?: HTMLInputElement | any) {\n // console.log('doaction', type);\n if (this.form) {\n const button = document.createElement('button');\n button.type = type;\n button.style.position = 'absolute';\n button.style.width = '0';\n button.style.height = '0';\n button.style.clipPath = 'inset(50%)';\n button.style.overflow = 'hidden';\n button.style.whiteSpace = 'nowrap';\n\n // Pass name, value, and form attributes through to the temporary button\n if (submitter) {\n button.name = submitter.name;\n button.value = submitter.value;\n\n ['formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget'].forEach((attr) => {\n if (submitter.hasAttribute(attr)) {\n button.setAttribute(attr, submitter.getAttribute(attr)!);\n }\n });\n }\n\n this.form.append(button);\n button.click();\n button.remove();\n }\n }\n\n /** Returns the associated `<form>` element, if one exists. */\n getForm() {\n return this.form ?? null;\n }\n\n /** Resets the form, restoring all the control to their default value */\n reset(submitter?: HTMLInputElement | any) {\n this.doAction('reset', submitter);\n }\n\n /** Submits the form, triggering validation and form data injection. */\n submit(submitter?: HTMLInputElement | any) {\n // Calling form.submit() bypasses the submit event and constraint validation. To prevent this, we can inject a\n // native submit button into the form, \"click\" it, then remove it to simulate a standard form submission.\n this.doAction('submit', submitter);\n }\n\n /**\n * Synchronously sets the form control's validity. Call this when you know the future validity but need to update\n * the host element immediately, i.e. before Lit updates the component in the next update.\n */\n setValidity(isValid: boolean) {\n const host = this.host;\n const hasInteracted = Boolean(userInteractedControls.has(host));\n const required = Boolean(host.required);\n\n //\n // We're mapping the following \"states\" to data attributes. In the future, we can use ElementInternals.states to\n // create a similar mapping, but instead of [data-invalid] it will look like :--invalid.\n //\n // See this RFC for more details: https://github.com/shoelace-style/shoelace/issues/1011\n //\n host.toggleAttribute('data-required', required);\n host.toggleAttribute('data-optional', !required);\n host.toggleAttribute('data-invalid', !isValid);\n host.toggleAttribute('data-valid', isValid);\n host.toggleAttribute('data-user-invalid', !isValid && hasInteracted);\n host.toggleAttribute('data-user-valid', isValid && hasInteracted);\n }\n\n userInteracted() {\n const hasInteracted = Boolean(userInteractedControls.has(this.host));\n\n return hasInteracted;\n }\n\n /**\n * Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything\n * that affects constraint validation changes so the component receives the correct validity states.\n */\n updateValidity() {\n const host = this.host;\n this.setValidity(host.validity.valid);\n }\n\n /**\n * Dispatches a non-bubbling, cancelable custom event of type `it-invalid`.\n * If the `it-invalid` event will be cancelled then the original `invalid`\n * event (which may have been passed as argument) will also be cancelled.\n * If no original `invalid` event has been passed then the `it-invalid`\n * event will be cancelled before being dispatched.\n */\n emitInvalidEvent(originalInvalidEvent?: Event) {\n const itInvalidEvent = new CustomEvent<Record<PropertyKey, never>>('it-invalid', {\n bubbles: false,\n composed: false,\n cancelable: true,\n detail: {},\n });\n\n if (!originalInvalidEvent) {\n itInvalidEvent.preventDefault();\n }\n\n if (!this.host.dispatchEvent(itInvalidEvent)) {\n originalInvalidEvent?.preventDefault();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"form-controller.js","sourceRoot":"","sources":["../../../src/form/form-controller.ts"],"names":[],"mappings":"AAIA,EAAE;AACF,8GAA8G;AAC9G,oHAAoH;AACpH,uDAAuD;AACvD,EAAE;AACF,MAAM,CAAC,MAAM,eAAe,GAA+C,IAAI,OAAO,EAAE,CAAC;AAEzF,EAAE;AACF,mHAAmH;AACnH,sDAAsD;AACtD,EAAE;AACF,MAAM,uBAAuB,GAA4C,IAAI,OAAO,EAAE,CAAC;AACvF,MAAM,sBAAsB,GAA4C,IAAI,OAAO,EAAE,CAAC;AAEtF,EAAE;AACF,gHAAgH;AAChH,6DAA6D;AAC7D,EAAE;AACF,MAAM,sBAAsB,GAAyB,I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GAAG,OAAO,CAAC,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAErE,OAAO,aAAa,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,cAAc;QACZ,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACH,gBAAgB,CAAC,oBAA4B;QAC3C,MAAM,cAAc,GAAG,IAAI,WAAW,CAA6B,YAAY,EAAE;YAC/E,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,KAAK;YACf,UAAU,EAAE,IAAI;YAChB,MAAM,EAAE,EAAE;SACX,CAAC,CAAC;QAEH,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC1B,cAAc,CAAC,cAAc,EAAE,CAAC;QAClC,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,EAAE,CAAC;YAC7C,oBAAoB,EAAE,cAAc,EAAE,CAAC;QACzC,CAAC;IACH,CAAC;CACF","sourcesContent":["/* eslint-disable prefer-destructuring */\nimport type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport { FormControl } from './form-control.js';\n\n//\n// We store a WeakMap of forms + controls so we can keep references to all FormControl within a given form. As\n// elements connect and disconnect to/from the DOM, their containing form is used as the key and the form control is\n// added and removed from the form's set, respectively.\n//\nexport const formCollections: WeakMap<HTMLFormElement, Set<FormControl>> = new WeakMap();\n\n//\n// We store a WeakMap of reportValidity() overloads so we can override it when form controls connect to the DOM and\n// restore the original behavior when they disconnect.\n//\nconst reportValidityOverloads: WeakMap<HTMLFormElement, () => boolean> = new WeakMap();\nconst checkValidityOverloads: WeakMap<HTMLFormElement, () => boolean> = new WeakMap();\n\n//\n// We store a Set of controls that users have interacted with. This allows us to determine the interaction state\n// without littering the DOM with additional data attributes.\n//\nconst userInteractedControls: WeakSet<FormControl> = new WeakSet();\n\n//\n// We store a WeakMap of interactions for each form control so we can track when all conditions are met for validation.\n//\nconst interactions = new WeakMap<FormControl, string[]>();\n\nexport interface FormControlControllerOptions {\n /** A function that returns the form containing the form control. */\n form: (input: FormControl) => HTMLFormElement | null;\n /** A function that returns the form control's name, which will be submitted with the form data. */\n name: (input: FormControl) => string;\n /** A function that returns the form control's current value. */\n value: (input: FormControl) => unknown | unknown[];\n /** A function that returns the form control's current disabled state. If disabled, the value won't be submitted. */\n disabled: (input: FormControl) => boolean;\n // /**\n // * A function that maps to the form control's reportValidity() function. When the control is invalid, this will\n // * prevent submission and trigger the browser's constraint violation warning.\n // */\n reportValidity: (input: FormControl) => boolean;\n\n // /**\n // * A function that maps to the form control's `checkValidity()` function. When the control is invalid, this will return false.\n // * this is helpful is you want to check validation without triggering the native browser constraint violation warning.\n // */\n checkValidity: (input: FormControl) => boolean;\n /** A function that sets the form control's value */\n setValue: (input: FormControl, value: unknown) => void;\n /**\n * An array of event names to listen to. When all events in the list are emitted, the control will receive validity\n * states such as user-valid and user-invalid.user interacted validity states. */\n assumeInteractionOn: string[];\n}\n\n/** A reactive controller to allow form controls to participate in form submission, validation, etc. */\nexport class FormControlController implements ReactiveController {\n host: FormControl & ReactiveControllerHost;\n\n form?: HTMLFormElement | null;\n\n options: FormControlControllerOptions;\n\n submittedOnce: boolean = false;\n\n constructor(host: ReactiveControllerHost & FormControl, options?: Partial<FormControlControllerOptions>) {\n (this.host = host).addController(this);\n this.options = {\n form: (input) => {\n // If there's a form attribute, use it to find the target form by id\n // Controls may not always reflect the 'form' property. For example, `<it-button>` doesn't reflect.\n const formId = input.form;\n\n if (formId) {\n const root = input.getRootNode() as Document | ShadowRoot | HTMLElement;\n const form = root.querySelector(`#${formId}`);\n\n if (form) {\n return form as HTMLFormElement;\n }\n }\n\n return input.closest('form');\n },\n name: (input) => input.name,\n value: (input) => input.value,\n disabled: (input) => input.disabled ?? false,\n reportValidity: (input: FormControl) =>\n typeof input.reportValidity === 'function' ? input.reportValidity() : true,\n checkValidity: (input: FormControl) => (typeof input.checkValidity === 'function' ? input.checkValidity() : true),\n setValue: (input, value) => {\n // eslint-disable-next-line no-param-reassign\n input.value = value as string;\n },\n assumeInteractionOn: ['it-input'],\n ...options,\n };\n }\n\n hostConnected() {\n const form = this.options.form(this.host);\n if (form) {\n this.attachForm(form);\n }\n\n // Listen for interactions\n interactions.set(this.host, []);\n this.options.assumeInteractionOn.forEach((event) => {\n this.host.addEventListener(event, this.handleInteraction);\n });\n }\n\n hostDisconnected() {\n this.detachForm();\n\n // Clean up interactions\n interactions.delete(this.host);\n this.options.assumeInteractionOn.forEach((event) => {\n this.host.removeEventListener(event, this.handleInteraction);\n });\n }\n\n hostUpdated() {\n const form = this.options.form(this.host);\n\n // Detach if the form no longer exists\n if (!form) {\n this.detachForm();\n }\n\n // If the form has changed, reattach it\n if (form && this.form !== form) {\n this.detachForm();\n this.attachForm(form);\n }\n\n if (this.host.hasUpdated) {\n this.setValidity(this.host.validity.valid);\n }\n }\n\n private attachForm(form?: HTMLFormElement) {\n if (form) {\n this.form = form;\n\n // Add this element to the form's collection\n if (formCollections.has(this.form)) {\n formCollections.get(this.form)!.add(this.host);\n } else {\n formCollections.set(this.form, new Set<FormControl>([this.host]));\n }\n\n this.form.addEventListener('formdata', this.handleFormData);\n this.form.addEventListener('submit', this.handleFormSubmit);\n this.form.addEventListener('reset', this.handleFormReset);\n\n // Overload the form's reportValidity() method so it looks at FormControl\n if (!reportValidityOverloads.has(this.form)) {\n reportValidityOverloads.set(this.form, this.form.reportValidity);\n this.form.reportValidity = () => this.reportFormValidity();\n }\n\n // Overload the form's checkValidity() method so it looks at FormControl\n if (!checkValidityOverloads.has(this.form)) {\n checkValidityOverloads.set(this.form, this.form.checkValidity);\n this.form.checkValidity = () => this.checkFormValidity();\n }\n } else {\n this.form = undefined;\n }\n }\n\n private detachForm() {\n if (!this.form) return;\n\n const formCollection = formCollections.get(this.form);\n\n if (!formCollection) {\n return;\n }\n this.submittedOnce = false;\n\n // Remove this host from the form's collection\n formCollection.delete(this.host);\n\n // Check to make sure there's no other form controls in the collection. If we do this\n // without checking if any other controls are still in the collection, then we will wipe out the\n // validity checks for all other elements.\n // see: https://github.com/shoelace-style/shoelace/issues/1703\n if (formCollection.size <= 0) {\n this.form.removeEventListener('formdata', this.handleFormData);\n this.form.removeEventListener('submit', this.handleFormSubmit);\n this.form.removeEventListener('reset', this.handleFormReset);\n\n // Remove the overload and restore the original method\n if (reportValidityOverloads.has(this.form)) {\n this.form.reportValidity = reportValidityOverloads.get(this.form)!;\n reportValidityOverloads.delete(this.form);\n }\n\n if (checkValidityOverloads.has(this.form)) {\n this.form.checkValidity = checkValidityOverloads.get(this.form)!;\n checkValidityOverloads.delete(this.form);\n }\n\n // So it looks weird here to not always set the form to undefined. But I _think_ if we unattach this.form here,\n // we end up in this fun spot where future validity checks don't have a reference to the form validity handler.\n // First form element in sets the validity handler. So we can't clean up `this.form` until there are no other form elements in the form.\n this.form = undefined;\n }\n }\n\n private handleFormData = (event: FormDataEvent) => {\n // console.log('handleFormData');\n const disabled = this.options.disabled(this.host);\n const name = this.options.name(this.host);\n const value = this.options.value(this.host);\n const tagName = this.host.tagName.toLowerCase();\n\n // For buttons, we only submit the value if they were the submitter. This is currently done in doAction() by\n // injecting the name/value on a temporary button, so we can just skip them here.\n const isButton = tagName === 'it-button';\n\n if (\n this.host.isConnected &&\n !disabled &&\n !isButton &&\n typeof name === 'string' &&\n name.length > 0 &&\n typeof value !== 'undefined'\n ) {\n switch (tagName) {\n case 'it-radio':\n if ((this.host as any).checked) {\n event.formData.append(name, value as string);\n }\n break;\n case 'it-checkbox':\n case 'it-toggle':\n if ((this.host as any).checked) {\n if (event.formData.getAll(name).indexOf(value as string) < 0) {\n // handle group checkbox\n event.formData.append(name, value as string);\n }\n }\n break;\n case 'it-checkbox-group':\n case 'it-toggle-group':\n // non settare valori in formData, perchè ogni singola checkbox setta il suo valore\n break;\n case 'it-upload':\n // value is File[] — append each File object directly (not as string)\n if (Array.isArray(value)) {\n (value as File[]).forEach((file) => {\n event.formData.append(name, file);\n });\n }\n break;\n default:\n if (Array.isArray(value)) {\n (value as unknown[]).forEach((val) => {\n event.formData.append(name, (val as string | number | boolean).toString());\n });\n } else {\n event.formData.append(name, (value as string | number | boolean).toString());\n }\n }\n }\n };\n\n private handleFormSubmit = (event: Event) => {\n const disabled = this.options.disabled(this.host);\n const reportValidity = this.options.reportValidity;\n\n // Update the interacted state for all controls when the form is submitted\n if (this.form && !this.form.noValidate) {\n formCollections.get(this.form)?.forEach((control) => {\n this.setUserInteracted(control, true);\n });\n }\n\n const resReportValidity = reportValidity(this.host);\n\n if (this.form && !this.form.noValidate && !disabled && !resReportValidity) {\n event.preventDefault();\n // event.stopImmediatePropagation(); // se lo attiviamo, valida un campo alla volta\n\n // Scroll al primo controllo non valido\n const formControls = formCollections.get(this.form);\n if (formControls) {\n for (const control of formControls) {\n if (!control.validity?.valid) {\n // Scroll smooth verso il controllo non valido\n control.scrollIntoView({\n behavior: 'smooth',\n block: 'center',\n });\n break;\n }\n }\n }\n }\n this.submittedOnce = true;\n };\n\n private handleFormReset = () => {\n this.options.setValue(this.host, '');\n this.submittedOnce = false;\n this.setUserInteracted(this.host, false);\n interactions.set(this.host, []);\n };\n\n private handleInteraction = (event: Event) => {\n const emittedEvents = interactions.get(this.host)!;\n\n if (!emittedEvents.includes(event.type)) {\n emittedEvents.push(event.type);\n }\n\n // Mark it as user-interacted as soon as all associated events have been emitted\n if (emittedEvents.length === this.options.assumeInteractionOn.length) {\n this.setUserInteracted(this.host, true);\n }\n };\n\n private checkFormValidity = () => {\n // console.log('checkFormValidity');\n //\n // This is very similar to the `reportFormValidity` function, but it does not trigger native constraint validation\n // Allow the user to simply check if the form is valid and handling validity in their own way.\n //\n // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger\n // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't\n // be necessary once we can use ElementInternals.\n //\n // Note that we're also honoring the form's novalidate attribute.\n //\n if (this.form && !this.form.noValidate) {\n // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom\n // elements that support the constraint validation API.\n const elements = this.form.querySelectorAll<HTMLInputElement>('*');\n\n for (const element of elements) {\n if (typeof element.checkValidity === 'function') {\n if (!element.checkValidity()) {\n return false;\n }\n }\n }\n }\n\n return true;\n };\n\n private reportFormValidity = () => {\n // console.log('reportFormValidity');\n //\n // FormControl work hard to act like regular form controls. They support the Constraint Validation API\n // and its associated methods such as setCustomValidity() and reportValidity(). However, the HTMLFormElement also\n // has a reportValidity() method that will trigger validation on all child controls. Since we're not yet using\n // ElementInternals, we need to overload this method so it looks for any element with the reportValidity() method.\n //\n // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger\n // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't\n // be necessary once we can use ElementInternals.\n //\n // Note that we're also honoring the form's novalidate attribute.\n //\n if (this.form && !this.form.noValidate) {\n // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom\n // elements that support the constraint validation API.\n const elements = this.form.querySelectorAll<HTMLInputElement>('*');\n\n for (const element of elements) {\n if (typeof element.reportValidity === 'function') {\n if (!element.reportValidity()) {\n return false;\n }\n }\n }\n }\n\n return true;\n };\n\n // eslint-disable-next-line class-methods-use-this\n private setUserInteracted(el: FormControl, hasInteracted: boolean) {\n if (hasInteracted) {\n userInteractedControls.add(el);\n } else {\n userInteractedControls.delete(el);\n }\n\n el.requestUpdate();\n }\n\n private doAction(type: 'submit' | 'reset', submitter?: HTMLInputElement | any) {\n // console.log('doaction', type);\n if (this.form) {\n const button = document.createElement('button');\n button.type = type;\n button.style.position = 'absolute';\n button.style.width = '0';\n button.style.height = '0';\n button.style.clipPath = 'inset(50%)';\n button.style.overflow = 'hidden';\n button.style.whiteSpace = 'nowrap';\n\n // Pass name, value, and form attributes through to the temporary button\n if (submitter) {\n button.name = submitter.name;\n button.value = submitter.value;\n\n ['formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget'].forEach((attr) => {\n if (submitter.hasAttribute(attr)) {\n button.setAttribute(attr, submitter.getAttribute(attr)!);\n }\n });\n }\n\n this.form.append(button);\n button.click();\n button.remove();\n }\n }\n\n /** Returns the associated `<form>` element, if one exists. */\n getForm() {\n return this.form ?? null;\n }\n\n /** Resets the form, restoring all the control to their default value */\n reset(submitter?: HTMLInputElement | any) {\n this.doAction('reset', submitter);\n }\n\n /** Submits the form, triggering validation and form data injection. */\n submit(submitter?: HTMLInputElement | any) {\n // Calling form.submit() bypasses the submit event and constraint validation. To prevent this, we can inject a\n // native submit button into the form, \"click\" it, then remove it to simulate a standard form submission.\n this.doAction('submit', submitter);\n }\n\n /**\n * Synchronously sets the form control's validity. Call this when you know the future validity but need to update\n * the host element immediately, i.e. before Lit updates the component in the next update.\n */\n setValidity(isValid: boolean) {\n const host = this.host;\n const hasInteracted = Boolean(userInteractedControls.has(host));\n const required = Boolean(host.required);\n\n //\n // We're mapping the following \"states\" to data attributes. In the future, we can use ElementInternals.states to\n // create a similar mapping, but instead of [data-invalid] it will look like :--invalid.\n //\n // See this RFC for more details: https://github.com/shoelace-style/shoelace/issues/1011\n //\n host.toggleAttribute('data-required', required);\n host.toggleAttribute('data-optional', !required);\n host.toggleAttribute('data-invalid', !isValid);\n host.toggleAttribute('data-valid', isValid);\n host.toggleAttribute('data-user-invalid', !isValid && hasInteracted);\n host.toggleAttribute('data-user-valid', isValid && hasInteracted);\n }\n\n userInteracted() {\n const hasInteracted = Boolean(userInteractedControls.has(this.host));\n\n return hasInteracted;\n }\n\n /**\n * Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything\n * that affects constraint validation changes so the component receives the correct validity states.\n */\n updateValidity() {\n const host = this.host;\n this.setValidity(host.validity.valid);\n }\n\n /**\n * Dispatches a non-bubbling, cancelable custom event of type `it-invalid`.\n * If the `it-invalid` event will be cancelled then the original `invalid`\n * event (which may have been passed as argument) will also be cancelled.\n * If no original `invalid` event has been passed then the `it-invalid`\n * event will be cancelled before being dispatched.\n */\n emitInvalidEvent(originalInvalidEvent?: Event) {\n const itInvalidEvent = new CustomEvent<Record<PropertyKey, never>>('it-invalid', {\n bubbles: false,\n composed: false,\n cancelable: true,\n detail: {},\n });\n\n if (!originalInvalidEvent) {\n itInvalidEvent.preventDefault();\n }\n\n if (!this.host.dispatchEvent(itInvalidEvent)) {\n originalInvalidEvent?.preventDefault();\n }\n }\n}\n"]}
|
package/dist/src/index.js
CHANGED
|
@@ -6,7 +6,7 @@ if (typeof window !== 'undefined') {
|
|
|
6
6
|
window._itAnalytics = window._itAnalytics || {};
|
|
7
7
|
window._itAnalytics = {
|
|
8
8
|
...window._itAnalytics,
|
|
9
|
-
version: '1.0.0-alpha.
|
|
9
|
+
version: '1.0.0-alpha.9',
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
export { TrackFocus, setAttributes, AriaKeyboardListController };
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,0BAA0B,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AAUzF,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;IAChD,MAAM,CAAC,YAAY,GAAG;QACpB,GAAG,MAAM,CAAC,YAAY;QACtB,OAAO,EAAE,eAAe;KACzB,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,0BAA0B,EAAE,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AAEvF,OAAO,EACL,aAAa,EAGb,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,+BAA+B,GAEhC,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAwB,MAAM,wCAAwC,CAAC;AAEnG,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAgC,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACjH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAyC,MAAM,qBAAqB,CAAC;AAE3F,OAAO,EAAE,8BAA8B,EAAE,CAAC","sourcesContent":["import TrackFocus from './utils/track-focus.js';\n\nimport setAttributes from './directives/setAttributes.js';\nimport AriaKeyboardListController from './controllers/aria-keyboard-list-controller.js';\nimport { StoryFormControlMethodAndProps } from './stories/formControlReusableStories.js';\n\ndeclare global {\n interface Window {\n _itAnalytics: {\n version: string;\n };\n }\n}\n\nif (typeof window !== 'undefined') {\n window._itAnalytics = window._itAnalytics || {};\n window._itAnalytics = {\n ...window._itAnalytics,\n version: '1.0.0-alpha.
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,0BAA0B,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AAUzF,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;IAChD,MAAM,CAAC,YAAY,GAAG;QACpB,GAAG,MAAM,CAAC,YAAY;QACtB,OAAO,EAAE,eAAe;KACzB,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,0BAA0B,EAAE,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AAEvF,OAAO,EACL,aAAa,EAGb,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,+BAA+B,GAEhC,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAwB,MAAM,wCAAwC,CAAC;AAEnG,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAgC,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACjH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAyC,MAAM,qBAAqB,CAAC;AAE3F,OAAO,EAAE,8BAA8B,EAAE,CAAC","sourcesContent":["import TrackFocus from './utils/track-focus.js';\n\nimport setAttributes from './directives/setAttributes.js';\nimport AriaKeyboardListController from './controllers/aria-keyboard-list-controller.js';\nimport { StoryFormControlMethodAndProps } from './stories/formControlReusableStories.js';\n\ndeclare global {\n interface Window {\n _itAnalytics: {\n version: string;\n };\n }\n}\n\nif (typeof window !== 'undefined') {\n window._itAnalytics = window._itAnalytics || {};\n window._itAnalytics = {\n ...window._itAnalytics,\n version: '1.0.0-alpha.9',\n };\n}\n\nexport { TrackFocus, setAttributes, AriaKeyboardListController };\nexport type { AriaKeyboardConfig } from './controllers/aria-keyboard-list-controller.js';\nexport { RovingTabindexController } from './controllers/roving-tabindex-controller.js';\nexport type { RovingTabindexConfig } from './controllers/roving-tabindex-controller.js';\nexport {\n BaseComponent,\n BaseComponentInterface,\n BaseComponentType,\n BaseLocalizedComponent,\n} from './base-component/base-component.js';\nexport {\n AriaKeyboardAccordionController,\n type AriaKeyboardAccordionConfig,\n} from './controllers/aria-keyboard-accordion-controller.js';\nexport { CollapseAnimationController } from './controllers/collapse-controller.js';\nexport { FocusTrapController, type FocusTrapConfig } from './controllers/focus-trap-controller.js';\n\nexport { FormControl } from './form/form-control.js';\nexport { formCollections, FormControlControllerOptions, FormControlController } from './form/form-controller.js';\nexport { cookies } from './utils/cookies.js';\nexport type Constructor<T = {}> = new (...args: any[]) => T;\nexport { WindowManager, type ScrollCallback, type ScrollState } from './window-manager.js';\n\nexport { StoryFormControlMethodAndProps };\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@italia/globals",
|
|
3
3
|
"description": "Utilities per i Web components del Design System .italia",
|
|
4
|
-
"version": "1.0.0-alpha.
|
|
4
|
+
"version": "1.0.0-alpha.9",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@floating-ui/dom": "^1.7.1",
|
|
36
36
|
"clsx": "^2.1.1",
|
|
37
37
|
"lit": "^3.3.0",
|
|
38
|
-
"@italia/i18n": "^1.0.0-alpha.
|
|
38
|
+
"@italia/i18n": "^1.0.0-alpha.9"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@custom-elements-manifest/analyzer": "^0.10.3",
|