@italia/globals 1.0.0-alpha.4 → 1.0.0-alpha.6
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 +310 -28
- package/dist/src/controllers/focus-trap-controller.d.ts +72 -0
- package/dist/src/controllers/focus-trap-controller.d.ts.map +1 -0
- package/dist/src/controllers/focus-trap-controller.js +271 -0
- package/dist/src/controllers/focus-trap-controller.js.map +1 -0
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/stories/formControlReusableStories.js +3 -3
- package/dist/src/stories/formControlReusableStories.js.map +1 -1
- package/dist/src/window-manager.d.ts +13 -0
- package/dist/src/window-manager.d.ts.map +1 -1
- package/dist/src/window-manager.js +31 -0
- package/dist/src/window-manager.js.map +1 -1
- package/package.json +2 -2
- package/dist/src/stories/reusableUsageGuidelinesStories.d.ts +0 -13
- package/dist/src/stories/reusableUsageGuidelinesStories.d.ts.map +0 -1
- package/dist/src/stories/reusableUsageGuidelinesStories.js +0 -39
- package/dist/src/stories/reusableUsageGuidelinesStories.js.map +0 -1
package/custom-elements.json
CHANGED
|
@@ -111,6 +111,22 @@
|
|
|
111
111
|
"module": "./controllers/collapse-controller.js"
|
|
112
112
|
}
|
|
113
113
|
},
|
|
114
|
+
{
|
|
115
|
+
"kind": "js",
|
|
116
|
+
"name": "FocusTrapController",
|
|
117
|
+
"declaration": {
|
|
118
|
+
"name": "FocusTrapController",
|
|
119
|
+
"module": "./controllers/focus-trap-controller.js"
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"kind": "js",
|
|
124
|
+
"name": "FocusTrapConfig",
|
|
125
|
+
"declaration": {
|
|
126
|
+
"name": "FocusTrapConfig",
|
|
127
|
+
"module": "./controllers/focus-trap-controller.js"
|
|
128
|
+
}
|
|
129
|
+
},
|
|
114
130
|
{
|
|
115
131
|
"kind": "js",
|
|
116
132
|
"name": "FormControl",
|
|
@@ -182,14 +198,6 @@
|
|
|
182
198
|
"name": "StoryFormControlMethodAndProps",
|
|
183
199
|
"module": "src/index.ts"
|
|
184
200
|
}
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
"kind": "js",
|
|
188
|
-
"name": "CollapsibleOrHiddenContentGuidelines",
|
|
189
|
-
"declaration": {
|
|
190
|
-
"name": "CollapsibleOrHiddenContentGuidelines",
|
|
191
|
-
"module": "src/index.ts"
|
|
192
|
-
}
|
|
193
201
|
}
|
|
194
202
|
]
|
|
195
203
|
},
|
|
@@ -259,6 +267,26 @@
|
|
|
259
267
|
"static": true,
|
|
260
268
|
"default": "false"
|
|
261
269
|
},
|
|
270
|
+
{
|
|
271
|
+
"kind": "field",
|
|
272
|
+
"name": "scrollLockCount",
|
|
273
|
+
"type": {
|
|
274
|
+
"text": "number"
|
|
275
|
+
},
|
|
276
|
+
"privacy": "private",
|
|
277
|
+
"static": true,
|
|
278
|
+
"default": "0"
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
"kind": "field",
|
|
282
|
+
"name": "scrollbarWidth",
|
|
283
|
+
"type": {
|
|
284
|
+
"text": "number"
|
|
285
|
+
},
|
|
286
|
+
"privacy": "private",
|
|
287
|
+
"static": true,
|
|
288
|
+
"default": "0"
|
|
289
|
+
},
|
|
262
290
|
{
|
|
263
291
|
"kind": "method",
|
|
264
292
|
"name": "init",
|
|
@@ -315,6 +343,39 @@
|
|
|
315
343
|
}
|
|
316
344
|
}
|
|
317
345
|
]
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
"kind": "method",
|
|
349
|
+
"name": "lockBodyScroll",
|
|
350
|
+
"static": true,
|
|
351
|
+
"return": {
|
|
352
|
+
"type": {
|
|
353
|
+
"text": "void"
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
"description": "Blocca lo scroll del body. Usa ref counting per gestire modal nested.\nChiamare unlockBodyScroll() per ogni lockBodyScroll()."
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
"kind": "method",
|
|
360
|
+
"name": "unlockBodyScroll",
|
|
361
|
+
"static": true,
|
|
362
|
+
"return": {
|
|
363
|
+
"type": {
|
|
364
|
+
"text": "void"
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
"description": "Sblocca lo scroll del body. Rimuove il lock solo quando tutti i consumer hanno chiamato unlock."
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
"kind": "method",
|
|
371
|
+
"name": "getScrollbarWidth",
|
|
372
|
+
"static": true,
|
|
373
|
+
"return": {
|
|
374
|
+
"type": {
|
|
375
|
+
"text": "number"
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
"description": "Ritorna la larghezza della scrollbar (utile per compensazioni)"
|
|
318
379
|
}
|
|
319
380
|
]
|
|
320
381
|
}
|
|
@@ -743,6 +804,247 @@
|
|
|
743
804
|
}
|
|
744
805
|
]
|
|
745
806
|
},
|
|
807
|
+
{
|
|
808
|
+
"kind": "javascript-module",
|
|
809
|
+
"path": "src/controllers/focus-trap-controller.ts",
|
|
810
|
+
"declarations": [
|
|
811
|
+
{
|
|
812
|
+
"kind": "class",
|
|
813
|
+
"description": "Controller per gestire il focus trap all'interno di un elemento.\nImplementa le linee guida WAI-ARIA per i dialog modali.\n\n\n```",
|
|
814
|
+
"name": "FocusTrapController",
|
|
815
|
+
"members": [
|
|
816
|
+
{
|
|
817
|
+
"kind": "field",
|
|
818
|
+
"name": "host",
|
|
819
|
+
"type": {
|
|
820
|
+
"text": "ReactiveControllerHost & HTMLElement"
|
|
821
|
+
},
|
|
822
|
+
"privacy": "private",
|
|
823
|
+
"default": "host"
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
"kind": "field",
|
|
827
|
+
"name": "config",
|
|
828
|
+
"type": {
|
|
829
|
+
"text": "FocusTrapConfig"
|
|
830
|
+
},
|
|
831
|
+
"privacy": "private",
|
|
832
|
+
"default": "config"
|
|
833
|
+
},
|
|
834
|
+
{
|
|
835
|
+
"kind": "field",
|
|
836
|
+
"name": "observer",
|
|
837
|
+
"type": {
|
|
838
|
+
"text": "MutationObserver | null"
|
|
839
|
+
},
|
|
840
|
+
"privacy": "private",
|
|
841
|
+
"default": "null"
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
"kind": "field",
|
|
845
|
+
"name": "_isActive",
|
|
846
|
+
"type": {
|
|
847
|
+
"text": "boolean"
|
|
848
|
+
},
|
|
849
|
+
"privacy": "private",
|
|
850
|
+
"default": "false"
|
|
851
|
+
},
|
|
852
|
+
{
|
|
853
|
+
"kind": "field",
|
|
854
|
+
"name": "_previousActiveElement",
|
|
855
|
+
"type": {
|
|
856
|
+
"text": "HTMLElement | null"
|
|
857
|
+
},
|
|
858
|
+
"privacy": "private",
|
|
859
|
+
"default": "null"
|
|
860
|
+
},
|
|
861
|
+
{
|
|
862
|
+
"kind": "field",
|
|
863
|
+
"name": "_focusableElements",
|
|
864
|
+
"type": {
|
|
865
|
+
"text": "any[]"
|
|
866
|
+
},
|
|
867
|
+
"privacy": "private",
|
|
868
|
+
"default": "[]"
|
|
869
|
+
},
|
|
870
|
+
{
|
|
871
|
+
"kind": "field",
|
|
872
|
+
"name": "_first",
|
|
873
|
+
"type": {
|
|
874
|
+
"text": "any"
|
|
875
|
+
},
|
|
876
|
+
"privacy": "private"
|
|
877
|
+
},
|
|
878
|
+
{
|
|
879
|
+
"kind": "field",
|
|
880
|
+
"name": "_last",
|
|
881
|
+
"type": {
|
|
882
|
+
"text": "any"
|
|
883
|
+
},
|
|
884
|
+
"privacy": "private"
|
|
885
|
+
},
|
|
886
|
+
{
|
|
887
|
+
"kind": "field",
|
|
888
|
+
"name": "FOCUSABLE_SELECTORS",
|
|
889
|
+
"privacy": "private",
|
|
890
|
+
"static": true,
|
|
891
|
+
"readonly": true
|
|
892
|
+
},
|
|
893
|
+
{
|
|
894
|
+
"kind": "method",
|
|
895
|
+
"name": "isFocusable",
|
|
896
|
+
"privacy": "private",
|
|
897
|
+
"static": true,
|
|
898
|
+
"return": {
|
|
899
|
+
"type": {
|
|
900
|
+
"text": "boolean"
|
|
901
|
+
}
|
|
902
|
+
},
|
|
903
|
+
"parameters": [
|
|
904
|
+
{
|
|
905
|
+
"name": "el",
|
|
906
|
+
"type": {
|
|
907
|
+
"text": "HTMLElement"
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
],
|
|
911
|
+
"description": "Verifica se un elemento è effettivamente focusabile e tabbabile.\nElementi con tabindex=\"-1\" sono focusabili programmaticamente ma non tabbabili."
|
|
912
|
+
},
|
|
913
|
+
{
|
|
914
|
+
"kind": "method",
|
|
915
|
+
"name": "hostConnected"
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
"kind": "method",
|
|
919
|
+
"name": "hostDisconnected"
|
|
920
|
+
},
|
|
921
|
+
{
|
|
922
|
+
"kind": "field",
|
|
923
|
+
"name": "isActive",
|
|
924
|
+
"type": {
|
|
925
|
+
"text": "boolean"
|
|
926
|
+
},
|
|
927
|
+
"description": "Indica se il focus trap è attivo",
|
|
928
|
+
"readonly": true
|
|
929
|
+
},
|
|
930
|
+
{
|
|
931
|
+
"kind": "method",
|
|
932
|
+
"name": "activate",
|
|
933
|
+
"return": {
|
|
934
|
+
"type": {
|
|
935
|
+
"text": "void"
|
|
936
|
+
}
|
|
937
|
+
},
|
|
938
|
+
"description": "Attiva il focus trap.\nSalva l'elemento attivo corrente e attiva i listener.\nNOTA: chiamare updateFocusableElements() e focusFirst() separatamente quando necessario."
|
|
939
|
+
},
|
|
940
|
+
{
|
|
941
|
+
"kind": "method",
|
|
942
|
+
"name": "deactivate",
|
|
943
|
+
"return": {
|
|
944
|
+
"type": {
|
|
945
|
+
"text": "void"
|
|
946
|
+
}
|
|
947
|
+
},
|
|
948
|
+
"description": "Disattiva il focus trap.\nRipristina il focus all'elemento precedentemente attivo."
|
|
949
|
+
},
|
|
950
|
+
{
|
|
951
|
+
"kind": "method",
|
|
952
|
+
"name": "updateFocusableElements",
|
|
953
|
+
"return": {
|
|
954
|
+
"type": {
|
|
955
|
+
"text": "void"
|
|
956
|
+
}
|
|
957
|
+
},
|
|
958
|
+
"description": "Aggiorna la lista degli elementi focusabili.\nChiamare dopo modifiche al DOM."
|
|
959
|
+
},
|
|
960
|
+
{
|
|
961
|
+
"kind": "method",
|
|
962
|
+
"name": "focusFirst",
|
|
963
|
+
"return": {
|
|
964
|
+
"type": {
|
|
965
|
+
"text": "void"
|
|
966
|
+
}
|
|
967
|
+
},
|
|
968
|
+
"description": "Sposta il focus sul primo elemento focusabile"
|
|
969
|
+
},
|
|
970
|
+
{
|
|
971
|
+
"kind": "method",
|
|
972
|
+
"name": "focusLast",
|
|
973
|
+
"return": {
|
|
974
|
+
"type": {
|
|
975
|
+
"text": "void"
|
|
976
|
+
}
|
|
977
|
+
},
|
|
978
|
+
"description": "Sposta il focus sull'ultimo elemento focusabile"
|
|
979
|
+
},
|
|
980
|
+
{
|
|
981
|
+
"kind": "method",
|
|
982
|
+
"name": "getActiveElement",
|
|
983
|
+
"static": true,
|
|
984
|
+
"return": {
|
|
985
|
+
"type": {
|
|
986
|
+
"text": "HTMLElement | null"
|
|
987
|
+
}
|
|
988
|
+
},
|
|
989
|
+
"description": "Ritorna l'elemento attivo corrente, attraversando shadow DOM e slot"
|
|
990
|
+
},
|
|
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
|
+
{
|
|
1002
|
+
"kind": "field",
|
|
1003
|
+
"name": "_handleKeyDown",
|
|
1004
|
+
"privacy": "private"
|
|
1005
|
+
},
|
|
1006
|
+
{
|
|
1007
|
+
"kind": "method",
|
|
1008
|
+
"name": "_handleTab",
|
|
1009
|
+
"privacy": "private",
|
|
1010
|
+
"return": {
|
|
1011
|
+
"type": {
|
|
1012
|
+
"text": "void"
|
|
1013
|
+
}
|
|
1014
|
+
},
|
|
1015
|
+
"parameters": [
|
|
1016
|
+
{
|
|
1017
|
+
"name": "event",
|
|
1018
|
+
"type": {
|
|
1019
|
+
"text": "KeyboardEvent"
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
]
|
|
1023
|
+
},
|
|
1024
|
+
{
|
|
1025
|
+
"kind": "method",
|
|
1026
|
+
"name": "_restoreFocus",
|
|
1027
|
+
"privacy": "private",
|
|
1028
|
+
"return": {
|
|
1029
|
+
"type": {
|
|
1030
|
+
"text": "void"
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
]
|
|
1035
|
+
}
|
|
1036
|
+
],
|
|
1037
|
+
"exports": [
|
|
1038
|
+
{
|
|
1039
|
+
"kind": "js",
|
|
1040
|
+
"name": "FocusTrapController",
|
|
1041
|
+
"declaration": {
|
|
1042
|
+
"name": "FocusTrapController",
|
|
1043
|
+
"module": "src/controllers/focus-trap-controller.ts"
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
]
|
|
1047
|
+
},
|
|
746
1048
|
{
|
|
747
1049
|
"kind": "javascript-module",
|
|
748
1050
|
"path": "src/controllers/roving-tabindex-controller.ts",
|
|
@@ -1902,26 +2204,6 @@
|
|
|
1902
2204
|
}
|
|
1903
2205
|
]
|
|
1904
2206
|
},
|
|
1905
|
-
{
|
|
1906
|
-
"kind": "javascript-module",
|
|
1907
|
-
"path": "src/stories/reusableUsageGuidelinesStories.ts",
|
|
1908
|
-
"declarations": [
|
|
1909
|
-
{
|
|
1910
|
-
"kind": "function",
|
|
1911
|
-
"name": "CollapsibleOrHiddenContentGuidelines"
|
|
1912
|
-
}
|
|
1913
|
-
],
|
|
1914
|
-
"exports": [
|
|
1915
|
-
{
|
|
1916
|
-
"kind": "js",
|
|
1917
|
-
"name": "CollapsibleOrHiddenContentGuidelines",
|
|
1918
|
-
"declaration": {
|
|
1919
|
-
"name": "CollapsibleOrHiddenContentGuidelines",
|
|
1920
|
-
"module": "src/stories/reusableUsageGuidelinesStories.ts"
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
]
|
|
1924
|
-
},
|
|
1925
2207
|
{
|
|
1926
2208
|
"kind": "javascript-module",
|
|
1927
2209
|
"path": "src/utils/cookies.ts",
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
export interface FocusTrapConfig {
|
|
3
|
+
/** Funzione che ritorna l'elemento contenitore del trap */
|
|
4
|
+
getContainer: () => HTMLElement | ShadowRoot | null;
|
|
5
|
+
/** Funzione che ritorna l'elemento trigger che ha attivato il focus trap */
|
|
6
|
+
getTrigger: () => HTMLElement | ShadowRoot | null;
|
|
7
|
+
/** Opzionale: funzione che ritorna l'elemento da mettere a fuoco all'apertura (può essere tabindex -1) */
|
|
8
|
+
initialFocus?: () => HTMLElement | null;
|
|
9
|
+
/** Callback quando viene premuto Escape */
|
|
10
|
+
onEscape?: () => void;
|
|
11
|
+
/** Se true, non chiude con Escape */
|
|
12
|
+
disableEscape?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Controller per gestire il focus trap all'interno di un elemento.
|
|
16
|
+
* Implementa le linee guida WAI-ARIA per i dialog modali.
|
|
17
|
+
*
|
|
18
|
+
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class FocusTrapController implements ReactiveController {
|
|
22
|
+
private host;
|
|
23
|
+
private config;
|
|
24
|
+
private observer;
|
|
25
|
+
private _isActive;
|
|
26
|
+
private _previousActiveElement;
|
|
27
|
+
private _focusableElements;
|
|
28
|
+
private _first;
|
|
29
|
+
private _last;
|
|
30
|
+
private static readonly FOCUSABLE_SELECTORS;
|
|
31
|
+
/**
|
|
32
|
+
* Verifica se un elemento è effettivamente focusabile e tabbabile.
|
|
33
|
+
* Elementi con tabindex="-1" sono focusabili programmaticamente ma non tabbabili.
|
|
34
|
+
*/
|
|
35
|
+
private static isFocusable;
|
|
36
|
+
constructor(host: ReactiveControllerHost & HTMLElement, config: FocusTrapConfig);
|
|
37
|
+
hostConnected(): void;
|
|
38
|
+
hostDisconnected(): void;
|
|
39
|
+
/** Indica se il focus trap è attivo */
|
|
40
|
+
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
|
+
activate(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Disattiva il focus trap.
|
|
49
|
+
* Ripristina il focus all'elemento precedentemente attivo.
|
|
50
|
+
*/
|
|
51
|
+
deactivate(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Aggiorna la lista degli elementi focusabili.
|
|
54
|
+
* Chiamare dopo modifiche al DOM.
|
|
55
|
+
*/
|
|
56
|
+
updateFocusableElements(): void;
|
|
57
|
+
/** Sposta il focus sul primo elemento focusabile */
|
|
58
|
+
focusFirst(): void;
|
|
59
|
+
/** Sposta il focus sull'ultimo elemento focusabile */
|
|
60
|
+
focusLast(): void;
|
|
61
|
+
/** Ritorna l'elemento attivo corrente, attraversando shadow DOM e slot */
|
|
62
|
+
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
|
+
private _handleKeyDown;
|
|
69
|
+
private _handleTab;
|
|
70
|
+
private _restoreFocus;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=focus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,uBAAuB,IAAI,IAAI;IA+C/B,oDAAoD;IACpD,UAAU,IAAI,IAAI;IAMlB,sDAAsD;IACtD,SAAS,IAAI,IAAI;IAMjB,0EAA0E;IAC1E,MAAM,CAAC,gBAAgB,IAAI,WAAW,GAAG,IAAI;IAQ7C;;;OAGG;IACH,YAAY,IAAI,IAAI;IAYpB,OAAO,CAAC,cAAc,CAgBpB;IAEF,OAAO,CAAC,UAAU;IAgDlB,OAAO,CAAC,aAAa;CAMtB"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Controller per gestire il focus trap all'interno di un elemento.
|
|
3
|
+
* Implementa le linee guida WAI-ARIA per i dialog modali.
|
|
4
|
+
*
|
|
5
|
+
|
|
6
|
+
* ```
|
|
7
|
+
*/
|
|
8
|
+
export class FocusTrapController {
|
|
9
|
+
/**
|
|
10
|
+
* Verifica se un elemento è effettivamente focusabile e tabbabile.
|
|
11
|
+
* Elementi con tabindex="-1" sono focusabili programmaticamente ma non tabbabili.
|
|
12
|
+
*/
|
|
13
|
+
static isFocusable(el) {
|
|
14
|
+
if (typeof el.focus !== 'function')
|
|
15
|
+
return false;
|
|
16
|
+
// Escludi elementi disabilitati
|
|
17
|
+
if (el.hasAttribute('disabled'))
|
|
18
|
+
return false;
|
|
19
|
+
// Escludi elementi con tabindex negativo (focusabili programmaticamente ma non tabbabili)
|
|
20
|
+
const tabindex = el.getAttribute('tabindex');
|
|
21
|
+
if (tabindex && parseInt(tabindex, 10) < 0) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
// Per custom elements (it-*), controlla anche il loro tabindex
|
|
25
|
+
if (el.tagName.toLowerCase().startsWith('it-')) {
|
|
26
|
+
// Se ha tabindex esplicito negativo, non è tabbabile
|
|
27
|
+
if (tabindex && parseInt(tabindex, 10) < 0) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
// Per elementi standard, controlliamo anche visibilità in modo robusto.
|
|
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.
|
|
36
|
+
try {
|
|
37
|
+
// Se non ci sono bounding rects, probabilmente non è visibile
|
|
38
|
+
if (el.getClientRects()?.length === 0)
|
|
39
|
+
return false;
|
|
40
|
+
const style = window.getComputedStyle(el);
|
|
41
|
+
if (!style)
|
|
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;
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
constructor(host, config) {
|
|
53
|
+
this.observer = null;
|
|
54
|
+
this._isActive = false;
|
|
55
|
+
this._previousActiveElement = null;
|
|
56
|
+
this._focusableElements = [];
|
|
57
|
+
this._handleKeyDown = (event) => {
|
|
58
|
+
if (!this._isActive)
|
|
59
|
+
return;
|
|
60
|
+
switch (event.key) {
|
|
61
|
+
case 'Escape':
|
|
62
|
+
if (!this.config.disableEscape && this.config.onEscape) {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
this.config.onEscape();
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
case 'Tab':
|
|
68
|
+
this._handleTab(event);
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
this.host = host;
|
|
75
|
+
this.config = config;
|
|
76
|
+
this.host.addController(this);
|
|
77
|
+
}
|
|
78
|
+
// eslint-disable-next-line class-methods-use-this
|
|
79
|
+
hostConnected() {
|
|
80
|
+
// Controller ready
|
|
81
|
+
// Set up our MutationObserver
|
|
82
|
+
const observerOptions = {
|
|
83
|
+
childList: true,
|
|
84
|
+
attributes: true,
|
|
85
|
+
subtree: true,
|
|
86
|
+
};
|
|
87
|
+
this.observer = new MutationObserver(this.updateFocusableElements.bind(this));
|
|
88
|
+
this.observer.observe(this.host, observerOptions);
|
|
89
|
+
}
|
|
90
|
+
hostDisconnected() {
|
|
91
|
+
this.deactivate();
|
|
92
|
+
if (this.observer) {
|
|
93
|
+
this.observer.disconnect();
|
|
94
|
+
this.observer = null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** Indica se il focus trap è attivo */
|
|
98
|
+
get isActive() {
|
|
99
|
+
return this._isActive;
|
|
100
|
+
}
|
|
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
|
+
activate() {
|
|
107
|
+
if (this._isActive)
|
|
108
|
+
return;
|
|
109
|
+
this._isActive = true;
|
|
110
|
+
this._previousActiveElement = FocusTrapController.getActiveElement();
|
|
111
|
+
this.host.addEventListener('keydown', this._handleKeyDown);
|
|
112
|
+
this.updateFocusableElements();
|
|
113
|
+
if (typeof this.focusInitial === 'function')
|
|
114
|
+
this.focusInitial();
|
|
115
|
+
else
|
|
116
|
+
this.focusFirst();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Disattiva il focus trap.
|
|
120
|
+
* Ripristina il focus all'elemento precedentemente attivo.
|
|
121
|
+
*/
|
|
122
|
+
deactivate() {
|
|
123
|
+
if (!this._isActive)
|
|
124
|
+
return;
|
|
125
|
+
this._isActive = false;
|
|
126
|
+
this.host.removeEventListener('keydown', this._handleKeyDown);
|
|
127
|
+
this._restoreFocus();
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Aggiorna la lista degli elementi focusabili.
|
|
131
|
+
* Chiamare dopo modifiche al DOM.
|
|
132
|
+
*/
|
|
133
|
+
updateFocusableElements() {
|
|
134
|
+
const container = this.config.getContainer();
|
|
135
|
+
const trigger = this.config.getTrigger();
|
|
136
|
+
if (!container) {
|
|
137
|
+
this._focusableElements = [];
|
|
138
|
+
this._first = undefined;
|
|
139
|
+
this._last = undefined;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const candidates = [];
|
|
143
|
+
// Tutti gli elementi focusable direttamente nel container
|
|
144
|
+
const direct = Array.from(container.querySelectorAll(FocusTrapController.FOCUSABLE_SELECTORS));
|
|
145
|
+
candidates.push(...direct);
|
|
146
|
+
// Tutti gli elementi slottati
|
|
147
|
+
const slots = Array.from(container.querySelectorAll('slot'));
|
|
148
|
+
slots.forEach((slot) => {
|
|
149
|
+
slot.assignedElements({ flatten: true }).forEach((el) => {
|
|
150
|
+
if (!(el instanceof HTMLElement))
|
|
151
|
+
return;
|
|
152
|
+
if (el === trigger) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// focusable diretto
|
|
156
|
+
if (el.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {
|
|
157
|
+
candidates.push(el);
|
|
158
|
+
}
|
|
159
|
+
// nested focusable dentro l'elemento assegnato
|
|
160
|
+
Array.from(el.querySelectorAll(FocusTrapController.FOCUSABLE_SELECTORS)).forEach((nested) => candidates.push(nested));
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
// Filtra solo elementi veramente focusabili e rimuovi duplicati
|
|
164
|
+
this._focusableElements = Array.from(new Set(candidates)).filter((el) => {
|
|
165
|
+
// Escludi esplicitamente il container/dialog stesso
|
|
166
|
+
if (el === this.config.getContainer())
|
|
167
|
+
return false;
|
|
168
|
+
return FocusTrapController.isFocusable(el);
|
|
169
|
+
});
|
|
170
|
+
// Aggiorna primo/ultimo
|
|
171
|
+
this._first = this._focusableElements?.[0];
|
|
172
|
+
this._last = this._focusableElements[this._focusableElements.length - 1];
|
|
173
|
+
}
|
|
174
|
+
/** Sposta il focus sul primo elemento focusabile */
|
|
175
|
+
focusFirst() {
|
|
176
|
+
if (this._first) {
|
|
177
|
+
this._first.focus();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/** Sposta il focus sull'ultimo elemento focusabile */
|
|
181
|
+
focusLast() {
|
|
182
|
+
if (this._last) {
|
|
183
|
+
this._last.focus();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/** Ritorna l'elemento attivo corrente, attraversando shadow DOM e slot */
|
|
187
|
+
static getActiveElement() {
|
|
188
|
+
let active = document.activeElement;
|
|
189
|
+
while (active && active.shadowRoot && active.shadowRoot.activeElement) {
|
|
190
|
+
active = active.shadowRoot.activeElement;
|
|
191
|
+
}
|
|
192
|
+
return active;
|
|
193
|
+
}
|
|
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
|
+
_handleTab(event) {
|
|
209
|
+
if (this._focusableElements.length === 0) {
|
|
210
|
+
event.preventDefault();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
// SEMPRE previeni il default - gestiamo noi la navigazione
|
|
214
|
+
event.preventDefault();
|
|
215
|
+
const firstElement = this._first;
|
|
216
|
+
const lastElement = this._last;
|
|
217
|
+
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
|
+
let currentIndex = this._focusableElements.indexOf(activeElement);
|
|
222
|
+
// Se non trovato, potrebbe essere un elemento interno ad un custom element
|
|
223
|
+
if (currentIndex === -1 && activeElement) {
|
|
224
|
+
// Risali attraverso gli shadow host
|
|
225
|
+
let parent = activeElement.getRootNode()?.host;
|
|
226
|
+
while (parent && currentIndex === -1) {
|
|
227
|
+
currentIndex = this._focusableElements.indexOf(parent);
|
|
228
|
+
if (currentIndex === -1) {
|
|
229
|
+
parent = parent.getRootNode()?.host;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (event.shiftKey) {
|
|
234
|
+
// Shift + Tab: vai al precedente
|
|
235
|
+
if (currentIndex <= 0) {
|
|
236
|
+
// Se sei sul primo o non sei nella lista, vai all'ultimo
|
|
237
|
+
lastElement?.focus();
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
// Vai al precedente
|
|
241
|
+
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
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
// Vai al successivo
|
|
250
|
+
this._focusableElements[currentIndex + 1]?.focus();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
_restoreFocus() {
|
|
254
|
+
if (this._previousActiveElement && typeof this._previousActiveElement.focus === 'function') {
|
|
255
|
+
this._previousActiveElement.focus();
|
|
256
|
+
}
|
|
257
|
+
this._previousActiveElement = null;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
FocusTrapController.FOCUSABLE_SELECTORS = [
|
|
261
|
+
'a[href]',
|
|
262
|
+
'button:not([disabled])',
|
|
263
|
+
'textarea:not([disabled])',
|
|
264
|
+
'input:not([disabled]):not([type="hidden"])',
|
|
265
|
+
'select:not([disabled])',
|
|
266
|
+
'[tabindex]',
|
|
267
|
+
// '[role="dialog"]',
|
|
268
|
+
// Custom elements focusabili
|
|
269
|
+
'it-button:not([disabled])',
|
|
270
|
+
].join(',');
|
|
271
|
+
//# sourceMappingURL=focus-trap-controller.js.map
|
|
@@ -0,0 +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;gB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W,EAAiB,EAAE,IAAI,CAAC;gBACtD,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,KAAK,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"]}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import TrackFocus from './utils/track-focus.js';
|
|
|
2
2
|
import setAttributes from './directives/setAttributes.js';
|
|
3
3
|
import AriaKeyboardListController from './controllers/aria-keyboard-list-controller.js';
|
|
4
4
|
import { StoryFormControlMethodAndProps } from './stories/formControlReusableStories.js';
|
|
5
|
-
import { CollapsibleOrHiddenContentGuidelines } from './stories/reusableUsageGuidelinesStories.js';
|
|
6
5
|
declare global {
|
|
7
6
|
interface Window {
|
|
8
7
|
_itAnalytics: {
|
|
@@ -17,10 +16,11 @@ export type { RovingTabindexConfig } from './controllers/roving-tabindex-control
|
|
|
17
16
|
export { BaseComponent, BaseComponentInterface, BaseComponentType, BaseLocalizedComponent, } from './base-component/base-component.js';
|
|
18
17
|
export { AriaKeyboardAccordionController, type AriaKeyboardAccordionConfig, } from './controllers/aria-keyboard-accordion-controller.js';
|
|
19
18
|
export { CollapseAnimationController } from './controllers/collapse-controller.js';
|
|
19
|
+
export { FocusTrapController, type FocusTrapConfig } from './controllers/focus-trap-controller.js';
|
|
20
20
|
export { FormControl } from './form/form-control.js';
|
|
21
21
|
export { formCollections, FormControlControllerOptions, FormControlController } from './form/form-controller.js';
|
|
22
22
|
export { cookies } from './utils/cookies.js';
|
|
23
23
|
export type Constructor<T = {}> = new (...args: any[]) => T;
|
|
24
24
|
export { WindowManager, type ScrollCallback, type ScrollState } from './window-manager.js';
|
|
25
|
-
export { StoryFormControlMethodAndProps
|
|
25
|
+
export { StoryFormControlMethodAndProps };
|
|
26
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","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;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings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ist/src/index.js
CHANGED
|
@@ -2,12 +2,11 @@ import TrackFocus from './utils/track-focus.js';
|
|
|
2
2
|
import setAttributes from './directives/setAttributes.js';
|
|
3
3
|
import AriaKeyboardListController from './controllers/aria-keyboard-list-controller.js';
|
|
4
4
|
import { StoryFormControlMethodAndProps } from './stories/formControlReusableStories.js';
|
|
5
|
-
import { CollapsibleOrHiddenContentGuidelines } from './stories/reusableUsageGuidelinesStories.js';
|
|
6
5
|
if (typeof window !== 'undefined') {
|
|
7
6
|
window._itAnalytics = window._itAnalytics || {};
|
|
8
7
|
window._itAnalytics = {
|
|
9
8
|
...window._itAnalytics,
|
|
10
|
-
version: '1.0.0-alpha.
|
|
9
|
+
version: '1.0.0-alpha.6',
|
|
11
10
|
};
|
|
12
11
|
}
|
|
13
12
|
export { TrackFocus, setAttributes, AriaKeyboardListController };
|
|
@@ -15,9 +14,10 @@ export { RovingTabindexController } from './controllers/roving-tabindex-controll
|
|
|
15
14
|
export { BaseComponent, BaseLocalizedComponent, } from './base-component/base-component.js';
|
|
16
15
|
export { AriaKeyboardAccordionController, } from './controllers/aria-keyboard-accordion-controller.js';
|
|
17
16
|
export { CollapseAnimationController } from './controllers/collapse-controller.js';
|
|
17
|
+
export { FocusTrapController } from './controllers/focus-trap-controller.js';
|
|
18
18
|
export { FormControl } from './form/form-control.js';
|
|
19
19
|
export { formCollections, FormControlController } from './form/form-controller.js';
|
|
20
20
|
export { cookies } from './utils/cookies.js';
|
|
21
21
|
export { WindowManager } from './window-manager.js';
|
|
22
|
-
export { StoryFormControlMethodAndProps
|
|
22
|
+
export { StoryFormControlMethodAndProps };
|
|
23
23
|
//# sourceMappingURL=index.js.map
|
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;
|
|
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.6',\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"]}
|
|
@@ -28,14 +28,14 @@ myInput.setCustomValidity("Messaggio di errore");
|
|
|
28
28
|
\`\`\`
|
|
29
29
|
|
|
30
30
|
<br/>
|
|
31
|
-
<
|
|
31
|
+
<h3>Proprietà accessibili dall'esterno</h3>
|
|
32
32
|
| Nome | Descrizione |
|
|
33
33
|
|------|-------------|
|
|
34
34
|
|\`validity\`| Ritorna l'oggetto di validazione effettuata dal browser.|
|
|
35
35
|
|\`validationMessage\`| Ritorna il messaggio di errore in caso di validazione fallita.|
|
|
36
36
|
${otherProps}
|
|
37
37
|
|
|
38
|
-
<
|
|
38
|
+
<h3>Metodi</h3>
|
|
39
39
|
| Nome | Descrizione | Argomenti |
|
|
40
40
|
|------|-------------|-----------|
|
|
41
41
|
|\`getForm()\`| Ritorna l'elemento del DOM corrispondente alla form di riferimento dell'input. | - |
|
|
@@ -45,7 +45,7 @@ ${otherProps}
|
|
|
45
45
|
${otherMethods}
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
<
|
|
48
|
+
<h3>Eventi</h3>
|
|
49
49
|
| Nome | Descrizione |
|
|
50
50
|
|------|-------------|
|
|
51
51
|
|\`it-input-ready\`| Quando il componente è montato e l'elemento input interno è pronto. |
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formControlReusableStories.js","sourceRoot":"","sources":["../../../src/stories/formControlReusableStories.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAE3B,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,EAC7C,UAAU,GAAG,EAAE,EACf,YAAY,GAAG,EAAE,EACjB,WAAW,GAAG,EAAE,EAChB,aAAa,GAAG,UAAU,GAC3B,EAAE,EAAE;IACH,OAAO;QACL,IAAI,EAAE,iDAAiD;QACvD,IAAI,EAAE,CAAC,MAAM,CAAC;QACd,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAA,kCAAkC;QACpD,UAAU,EAAE;YACV,QAAQ,EAAE,MAAM,EAAE,kDAAkD;YACpE,IAAI,EAAE;gBACJ,WAAW,EAAE;oBACX,KAAK,EAAE;;;;GAId,aAAa,uBAAuB,aAAa;;;;;;;;;;;;;;;;;;;;EAoBlD,UAAU;;;;;;;;;EASV,YAAY;;;;;;;;;;;;;EAaZ,WAAW,EAAE;iBACN;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable arrow-body-style */\nimport { html } from 'lit';\n\nexport const StoryFormControlMethodAndProps = ({\n otherProps = '',\n otherMethods = '',\n otherEvents = '',\n componentName = 'it-input',\n}) => {\n return {\n name: 'Proprietà, Metodi, ed Eventi accessibili via js',\n tags: ['!dev'],\n render: () => html`<div class=\"hide-preview\"></div>`,\n parameters: {\n viewMode: 'docs', // assicura che si apra la tab Docs anziché Canvas\n docs: {\n description: {\n story: `\nIl componente espone delle proprietà, metodi, ed eventi, utili per eventuali interazioni via js.\n\n\\`\\`\\`html\n<${componentName} ... id=\"myinput\"></${componentName}>\n\\`\\`\\`\n\n\\`\\`\\`js\nconst myInput = document.getElementById(\"myInput\");\nconst validity = myInput.validity;\nconst validationMessage = myInput.validationMessage;\n\nconst form = myInput.getForm();\nmyInput.checkValidity();\nmyInput.reportValidity();\nmyInput.setCustomValidity(\"Messaggio di errore\");\n\\`\\`\\`\n\n<br/>\n<
|
|
1
|
+
{"version":3,"file":"formControlReusableStories.js","sourceRoot":"","sources":["../../../src/stories/formControlReusableStories.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAE3B,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,EAC7C,UAAU,GAAG,EAAE,EACf,YAAY,GAAG,EAAE,EACjB,WAAW,GAAG,EAAE,EAChB,aAAa,GAAG,UAAU,GAC3B,EAAE,EAAE;IACH,OAAO;QACL,IAAI,EAAE,iDAAiD;QACvD,IAAI,EAAE,CAAC,MAAM,CAAC;QACd,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAA,kCAAkC;QACpD,UAAU,EAAE;YACV,QAAQ,EAAE,MAAM,EAAE,kDAAkD;YACpE,IAAI,EAAE;gBACJ,WAAW,EAAE;oBACX,KAAK,EAAE;;;;GAId,aAAa,uBAAuB,aAAa;;;;;;;;;;;;;;;;;;;;EAoBlD,UAAU;;;;;;;;;EASV,YAAY;;;;;;;;;;;;;EAaZ,WAAW,EAAE;iBACN;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable arrow-body-style */\nimport { html } from 'lit';\n\nexport const StoryFormControlMethodAndProps = ({\n otherProps = '',\n otherMethods = '',\n otherEvents = '',\n componentName = 'it-input',\n}) => {\n return {\n name: 'Proprietà, Metodi, ed Eventi accessibili via js',\n tags: ['!dev'],\n render: () => html`<div class=\"hide-preview\"></div>`,\n parameters: {\n viewMode: 'docs', // assicura che si apra la tab Docs anziché Canvas\n docs: {\n description: {\n story: `\nIl componente espone delle proprietà, metodi, ed eventi, utili per eventuali interazioni via js.\n\n\\`\\`\\`html\n<${componentName} ... id=\"myinput\"></${componentName}>\n\\`\\`\\`\n\n\\`\\`\\`js\nconst myInput = document.getElementById(\"myInput\");\nconst validity = myInput.validity;\nconst validationMessage = myInput.validationMessage;\n\nconst form = myInput.getForm();\nmyInput.checkValidity();\nmyInput.reportValidity();\nmyInput.setCustomValidity(\"Messaggio di errore\");\n\\`\\`\\`\n\n<br/>\n<h3>Proprietà accessibili dall'esterno</h3>\n| Nome | Descrizione |\n|------|-------------|\n|\\`validity\\`| Ritorna l'oggetto di validazione effettuata dal browser.|\n|\\`validationMessage\\`| Ritorna il messaggio di errore in caso di validazione fallita.|\n${otherProps}\n\n<h3>Metodi</h3>\n| Nome | Descrizione | Argomenti |\n|------|-------------|-----------|\n|\\`getForm()\\`| Ritorna l'elemento del DOM corrispondente alla form di riferimento dell'input. | - |\n|\\`checkValidity()\\`| Triggera la validazione nativa del browser sul campo, e restituisce true o false a seconda che l'input sia valido o meno. | - |\n|\\`reportValidity()\\`| Controlla se l'elemento è valido secondo le regole di validazione del browser. Se non è valido, mostra un messaggio di errore (tooltip nativo del browser) e restituisce \\`false\\`. Se è valido, restituisce \\`true\\`. | - |\n|\\`setCustomValidity('')\\`| Permette di impostare un messaggio di errore personalizzato passato come parametro. Se il messaggio non è vuoto, rende invalido l'elemento. Se invece il messaggio è vuoto (''), rende valido l'elemento. | message: String |\n${otherMethods}\n\n\n<h3>Eventi</h3>\n| Nome | Descrizione |\n|------|-------------|\n|\\`it-input-ready\\`| Quando il componente è montato e l'elemento input interno è pronto. |\n|\\`it-input\\`| Ogni volta che il valore di input cambia per interazione da parte dell'utente |\n|\\`it-blur\\`| Quando l'input perde il focus (blur) |\n|\\`it-focus\\`| Quando l'input riceve il focus (focus) |\n|\\`it-click\\`| Quando l'utente fa click sull'input |\n|\\`it-change\\`| Quando il valore dell’input viene modificato e il browser emette \\`change\\` |\n|\\`invalid\\`| Emesso dal browser quando la validazione fallisce.|\n${otherEvents}`,\n },\n },\n },\n };\n};\n"]}
|
|
@@ -11,10 +11,23 @@ export declare class WindowManager {
|
|
|
11
11
|
private static lastWidth;
|
|
12
12
|
private static lastHeight;
|
|
13
13
|
private static ticking;
|
|
14
|
+
private static scrollLockCount;
|
|
15
|
+
private static scrollbarWidth;
|
|
14
16
|
static init(): void;
|
|
15
17
|
private static requestTick;
|
|
16
18
|
private static tick;
|
|
17
19
|
static subscribe(cb: ScrollCallback): void;
|
|
18
20
|
static unsubscribe(cb: ScrollCallback): void;
|
|
21
|
+
/**
|
|
22
|
+
* Blocca lo scroll del body. Usa ref counting per gestire modal nested.
|
|
23
|
+
* Chiamare unlockBodyScroll() per ogni lockBodyScroll().
|
|
24
|
+
*/
|
|
25
|
+
static lockBodyScroll(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Sblocca lo scroll del body. Rimuove il lock solo quando tutti i consumer hanno chiamato unlock.
|
|
28
|
+
*/
|
|
29
|
+
static unlockBodyScroll(): void;
|
|
30
|
+
/** Ritorna la larghezza della scrollbar (utile per compensazioni) */
|
|
31
|
+
static getScrollbarWidth(): number;
|
|
19
32
|
}
|
|
20
33
|
//# sourceMappingURL=window-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"window-manager.d.ts","sourceRoot":"","sources":["../../src/window-manager.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAA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AAM,CAAC,WAAW,CAAC,EAAE,EAAE,cAAc;IAIrC;;;OAGG;IACH,MAAM,CAAC,cAAc,IAAI,IAAI;IAU7B;;OAEG;IACH,MAAM,CAAC,gBAAgB,IAAI,IAAI;IAS/B,qEAAqE;IACrE,MAAM,CAAC,iBAAiB,IAAI,MAAM;CAGnC"}
|
|
@@ -37,6 +37,34 @@ export class WindowManager {
|
|
|
37
37
|
static unsubscribe(cb) {
|
|
38
38
|
this.subscribers.delete(cb);
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Blocca lo scroll del body. Usa ref counting per gestire modal nested.
|
|
42
|
+
* Chiamare unlockBodyScroll() per ogni lockBodyScroll().
|
|
43
|
+
*/
|
|
44
|
+
static lockBodyScroll() {
|
|
45
|
+
this.scrollLockCount += 1;
|
|
46
|
+
if (this.scrollLockCount === 1) {
|
|
47
|
+
this.scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
|
|
48
|
+
document.body.classList.add('modal-open');
|
|
49
|
+
document.body.style.overflow = 'hidden';
|
|
50
|
+
document.body.style.paddingRight = `${this.scrollbarWidth}px`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Sblocca lo scroll del body. Rimuove il lock solo quando tutti i consumer hanno chiamato unlock.
|
|
55
|
+
*/
|
|
56
|
+
static unlockBodyScroll() {
|
|
57
|
+
this.scrollLockCount = Math.max(0, this.scrollLockCount - 1);
|
|
58
|
+
if (this.scrollLockCount === 0) {
|
|
59
|
+
document.body.classList.remove('modal-open');
|
|
60
|
+
document.body.style.overflow = '';
|
|
61
|
+
document.body.style.paddingRight = '';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** Ritorna la larghezza della scrollbar (utile per compensazioni) */
|
|
65
|
+
static getScrollbarWidth() {
|
|
66
|
+
return this.scrollbarWidth || window.innerWidth - document.documentElement.clientWidth;
|
|
67
|
+
}
|
|
40
68
|
}
|
|
41
69
|
WindowManager.initialized = false;
|
|
42
70
|
WindowManager.subscribers = new Set();
|
|
@@ -44,4 +72,7 @@ WindowManager.lastScrollY = 0;
|
|
|
44
72
|
WindowManager.lastWidth = 0;
|
|
45
73
|
WindowManager.lastHeight = 0;
|
|
46
74
|
WindowManager.ticking = false;
|
|
75
|
+
// Body scroll lock (ref counting per modal nested)
|
|
76
|
+
WindowManager.scrollLockCount = 0;
|
|
77
|
+
WindowManager.scrollbarWidth = 0;
|
|
47
78
|
//# sourceMappingURL=window-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"window-manager.js","sourceRoot":"","sources":["../../src/window-manager.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,aAAa;
|
|
1
|
+
{"version":3,"file":"window-manager.js","sourceRoot":"","sources":["../../src/window-manager.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,aAAa;IAkBxB,MAAM,CAAC,IAAI;QACT,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO;QAE7B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC;QAErC,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE;YACrC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC;YAClC,IAAI,CAAC,WAAW,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE;YACrC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC;YACnC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC;YACrC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,sBAAsB;QAChD,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;I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I,CAAC,KAAK,CAAC,YAAY,GAAG,GAAG,IAAI,CAAC,cAAc,IAAI,CAAC;QAChE,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,gBAAgB;QACrB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC;QAC7D,IAAI,IAAI,CAAC,eAAe,KAAK,CAAC,EAAE,CAAC;YAC/B,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YAC7C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC;YAClC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,EAAE,CAAC;QACxC,CAAC;IACH,CAAC;IAED,qEAAqE;IACrE,MAAM,CAAC,iBAAiB;QACtB,OAAO,IAAI,CAAC,cAAc,IAAI,MAAM,CAAC,UAAU,GAAG,QAAQ,CAAC,eAAe,CAAC,WAAW,CAAC;IACzF,CAAC;;AA5Fc,yBAAW,GAAG,KAAK,CAAC;AAEpB,yBAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;AAExC,yBAAW,GAAG,CAAC,CAAC;AAEhB,uBAAS,GAAG,CAAC,CAAC;AAEd,wBAAU,GAAG,CAAC,CAAC;AAEf,qBAAO,GAAG,KAAK,CAAC;AAE/B,mDAAmD;AACpC,6BAAe,GAAG,CAAC,CAAC;AAEpB,4BAAc,GAAG,CAAC,CAAC","sourcesContent":["export type ScrollState = { scrollY: number; width: number; height: number };\nexport type ScrollCallback = (state: ScrollState, forceRecalc?: boolean) => void;\n\nexport class WindowManager {\n private static initialized = false;\n\n private static subscribers = new Set<ScrollCallback>();\n\n private static lastScrollY = 0;\n\n private static lastWidth = 0;\n\n private static lastHeight = 0;\n\n private static ticking = false;\n\n // Body scroll lock (ref counting per modal nested)\n private static scrollLockCount = 0;\n\n private static scrollbarWidth = 0;\n\n static init() {\n if (this.initialized) return;\n\n this.lastScrollY = window.scrollY;\n this.lastWidth = window.innerWidth;\n this.lastHeight = window.innerHeight;\n\n window.addEventListener('scroll', () => {\n this.lastScrollY = window.scrollY;\n this.requestTick();\n });\n\n window.addEventListener('resize', () => {\n this.lastWidth = window.innerWidth;\n this.lastHeight = window.innerHeight;\n this.requestTick(true); // force recalculation\n });\n\n this.initialized = true;\n }\n\n private static requestTick(forceRecalc = false) {\n if (!this.ticking) {\n requestAnimationFrame(() => this.tick(forceRecalc));\n this.ticking = true;\n }\n }\n\n private static tick(forceRecalc: boolean) {\n this.ticking = false;\n const state: ScrollState = {\n scrollY: this.lastScrollY,\n width: this.lastWidth,\n height: this.lastHeight,\n };\n this.subscribers.forEach((cb) => cb(state, forceRecalc));\n }\n\n static subscribe(cb: ScrollCallback) {\n this.subscribers.add(cb);\n }\n\n static unsubscribe(cb: ScrollCallback) {\n this.subscribers.delete(cb);\n }\n\n /**\n * Blocca lo scroll del body. Usa ref counting per gestire modal nested.\n * Chiamare unlockBodyScroll() per ogni lockBodyScroll().\n */\n static lockBodyScroll(): void {\n this.scrollLockCount += 1;\n if (this.scrollLockCount === 1) {\n this.scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;\n document.body.classList.add('modal-open');\n document.body.style.overflow = 'hidden';\n document.body.style.paddingRight = `${this.scrollbarWidth}px`;\n }\n }\n\n /**\n * Sblocca lo scroll del body. Rimuove il lock solo quando tutti i consumer hanno chiamato unlock.\n */\n static unlockBodyScroll(): void {\n this.scrollLockCount = Math.max(0, this.scrollLockCount - 1);\n if (this.scrollLockCount === 0) {\n document.body.classList.remove('modal-open');\n document.body.style.overflow = '';\n document.body.style.paddingRight = '';\n }\n }\n\n /** Ritorna la larghezza della scrollbar (utile per compensazioni) */\n static getScrollbarWidth(): number {\n return this.scrollbarWidth || window.innerWidth - document.documentElement.clientWidth;\n }\n}\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.6",
|
|
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.6"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@custom-elements-manifest/analyzer": "^0.10.3",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const CollapsibleOrHiddenContentGuidelines: () => {
|
|
2
|
-
name: string;
|
|
3
|
-
tags: string[];
|
|
4
|
-
render: () => import("lit").TemplateResult<1>;
|
|
5
|
-
parameters: {
|
|
6
|
-
docs: {
|
|
7
|
-
description: {
|
|
8
|
-
story: string;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=reusableUsageGuidelinesStories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reusableUsageGuidelinesStories.d.ts","sourceRoot":"","sources":["../../../src/stories/reusableUsageGuidelinesStories.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oCAAoC;;;;;;;;;;;CAmChD,CAAC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-disable arrow-body-style */
|
|
2
|
-
import { html } from 'lit';
|
|
3
|
-
export const CollapsibleOrHiddenContentGuidelines = () => {
|
|
4
|
-
return {
|
|
5
|
-
name: 'Differenza tra Collapse, Accordion e Tabs',
|
|
6
|
-
tags: ['!dev', '!autodocs'],
|
|
7
|
-
render: () => html `<div class="hide-preview"></div>`,
|
|
8
|
-
parameters: {
|
|
9
|
-
// viewMode: 'docs', // assicura che si apra la tab Docs anziché Canvas
|
|
10
|
-
docs: {
|
|
11
|
-
description: {
|
|
12
|
-
story: `
|
|
13
|
-
#### Differenza tra Collapse, Accordion e Tabs
|
|
14
|
-
I componenti Accordion, Tabs e Collapse funzionano tutti nascondendo sezioni di contenuto che l'utente può scegliere di visualizzare. Evitare di usare questi componenti l'uno all'interno dell'altro.
|
|
15
|
-
|
|
16
|
-
Se decidi di usare uno di questi componenti, considera quanto segue:
|
|
17
|
-
|
|
18
|
-
- L'utente ha bisogno di visualizzare più di una sezione alla volta? L'accordion può mostrare più sezioni contemporaneamente, a differenza dei tabs.
|
|
19
|
-
|
|
20
|
-
- L'utente deve passare rapidamente tra le sezioni? I tabs permettono di cambiare contenuto senza spostare le altre sezioni nella pagina, a differenza dell'accordion.
|
|
21
|
-
|
|
22
|
-
- Ci sono molte sezioni di contenuto? L'accordion può contenere più sezioni perché sono disposte verticalmente, mentre i tabs sono disposti orizzontalmente.
|
|
23
|
-
|
|
24
|
-
- Ci sono solo uno o due contenuti brevi e meno importanti? Il componente Collapse è più adatto perché visivamente più piccolo e meno prominente rispetto a un accordion o ai tabs.
|
|
25
|
-
|
|
26
|
-
<br/>
|
|
27
|
-
|
|
28
|
-
| Componente | Contenuti multipli | Visibilità | Esclusività | Uso tipico | Esempi |
|
|
29
|
-
|----------|--------------------|-------------|--------------|-------------|---------|
|
|
30
|
-
| **Collapse** | No | Singolo contenuto mostrato o nascosto | N/A | Mostrare o nascondere dettagli secondari | "Mostra dettagli", "Visualizza termini" |
|
|
31
|
-
| **Accordion** | Sì | Più sezioni espandibili | Solo una aperta alla volta *(consigliato)* | Raggruppare contenuti correlati in blocchi espandibili | FAQ, elenchi informativi |
|
|
32
|
-
| **Tabs** | Sì | Una sezione visibile alla volta | Sempre esclusiva | Organizzare viste equivalenti o alternative | Schede di impostazioni, pannelli di dati |
|
|
33
|
-
`,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=reusableUsageGuidelinesStories.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reusableUsageGuidelinesStories.js","sourceRoot":"","sources":["../../../src/stories/reusableUsageGuidelinesStories.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAE3B,MAAM,CAAC,MAAM,oCAAoC,GAAG,GAAG,EAAE;IACvD,OAAO;QACL,IAAI,EAAE,2CAA2C;QACjD,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC;QAC3B,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAA,kCAAkC;QACpD,UAAU,EAAE;YACV,uEAAuE;YACvE,IAAI,EAAE;gBACJ,WAAW,EAAE;oBACX,KAAK,EAAE;;;;;;;;;;;;;;;;;;;;;CAqBhB;iBACQ;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable arrow-body-style */\nimport { html } from 'lit';\n\nexport const CollapsibleOrHiddenContentGuidelines = () => {\n return {\n name: 'Differenza tra Collapse, Accordion e Tabs',\n tags: ['!dev', '!autodocs'],\n render: () => html`<div class=\"hide-preview\"></div>`,\n parameters: {\n // viewMode: 'docs', // assicura che si apra la tab Docs anziché Canvas\n docs: {\n description: {\n story: `\n#### Differenza tra Collapse, Accordion e Tabs\nI componenti Accordion, Tabs e Collapse funzionano tutti nascondendo sezioni di contenuto che l'utente può scegliere di visualizzare. Evitare di usare questi componenti l'uno all'interno dell'altro.\n\nSe decidi di usare uno di questi componenti, considera quanto segue:\n\n- L'utente ha bisogno di visualizzare più di una sezione alla volta? L'accordion può mostrare più sezioni contemporaneamente, a differenza dei tabs.\n\n- L'utente deve passare rapidamente tra le sezioni? I tabs permettono di cambiare contenuto senza spostare le altre sezioni nella pagina, a differenza dell'accordion.\n\n- Ci sono molte sezioni di contenuto? L'accordion può contenere più sezioni perché sono disposte verticalmente, mentre i tabs sono disposti orizzontalmente.\n\n- Ci sono solo uno o due contenuti brevi e meno importanti? Il componente Collapse è più adatto perché visivamente più piccolo e meno prominente rispetto a un accordion o ai tabs.\n\n<br/>\n\n| Componente | Contenuti multipli | Visibilità | Esclusività | Uso tipico | Esempi |\n|----------|--------------------|-------------|--------------|-------------|---------|\n| **Collapse** | No | Singolo contenuto mostrato o nascosto | N/A | Mostrare o nascondere dettagli secondari | \"Mostra dettagli\", \"Visualizza termini\" |\n| **Accordion** | Sì | Più sezioni espandibili | Solo una aperta alla volta *(consigliato)* | Raggruppare contenuti correlati in blocchi espandibili | FAQ, elenchi informativi |\n| **Tabs** | Sì | Una sezione visibile alla volta | Sempre esclusiva | Organizzare viste equivalenti o alternative | Schede di impostazioni, pannelli di dati |\n`,\n },\n },\n },\n };\n};\n"]}
|