@italia/globals 1.0.0-alpha.9 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -67
- package/custom-elements.json +319 -3
- package/dist/src/base-component/base-component.d.ts +2 -0
- package/dist/src/base-component/base-component.d.ts.map +1 -1
- package/dist/src/base-component/base-component.js +20 -0
- package/dist/src/base-component/base-component.js.map +1 -1
- package/dist/src/controllers/aria-keyboard-list-controller.d.ts +0 -0
- package/dist/src/controllers/aria-keyboard-list-controller.d.ts.map +0 -0
- package/dist/src/controllers/aria-keyboard-list-controller.js +0 -0
- package/dist/src/controllers/aria-keyboard-list-controller.js.map +0 -0
- package/dist/src/controllers/focus-trap-controller.d.ts +16 -2
- package/dist/src/controllers/focus-trap-controller.d.ts.map +1 -1
- package/dist/src/controllers/focus-trap-controller.js +265 -22
- package/dist/src/controllers/focus-trap-controller.js.map +1 -1
- package/dist/src/directives/setAttributes.d.ts +0 -0
- package/dist/src/directives/setAttributes.d.ts.map +1 -1
- package/dist/src/directives/setAttributes.js +69 -3
- package/dist/src/directives/setAttributes.js.map +1 -1
- package/dist/src/form/form-control.d.ts +0 -0
- package/dist/src/form/form-control.d.ts.map +0 -0
- package/dist/src/form/form-control.js +1 -1
- package/dist/src/form/form-control.js.map +1 -1
- package/dist/src/form/form-controller.d.ts +0 -0
- package/dist/src/form/form-controller.d.ts.map +0 -0
- package/dist/src/form/form-controller.js +0 -0
- package/dist/src/form/form-controller.js.map +0 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/stories/formControlReusableStories.d.ts +0 -0
- package/dist/src/stories/formControlReusableStories.d.ts.map +0 -0
- package/dist/src/stories/formControlReusableStories.js +0 -0
- package/dist/src/stories/formControlReusableStories.js.map +0 -0
- package/dist/src/stories/reusableUsageGuidelinesStories.d.ts +13 -0
- package/dist/src/stories/reusableUsageGuidelinesStories.d.ts.map +1 -0
- package/dist/src/stories/reusableUsageGuidelinesStories.js +39 -0
- package/dist/src/stories/reusableUsageGuidelinesStories.js.map +1 -0
- package/dist/src/utils/cookies.d.ts +0 -0
- package/dist/src/utils/cookies.d.ts.map +0 -0
- package/dist/src/utils/cookies.js +0 -0
- package/dist/src/utils/cookies.js.map +0 -0
- package/dist/src/utils/dispatch-cancelable.d.ts +31 -0
- package/dist/src/utils/dispatch-cancelable.d.ts.map +1 -0
- package/dist/src/utils/dispatch-cancelable.js +43 -0
- package/dist/src/utils/dispatch-cancelable.js.map +1 -0
- package/dist/src/utils/focus-fallback.d.ts +27 -0
- package/dist/src/utils/focus-fallback.d.ts.map +1 -0
- package/dist/src/utils/focus-fallback.js +63 -0
- package/dist/src/utils/focus-fallback.js.map +1 -0
- package/dist/src/utils/logger.d.ts +0 -0
- package/dist/src/utils/logger.d.ts.map +0 -0
- package/dist/src/utils/logger.js +0 -0
- package/dist/src/utils/logger.js.map +0 -0
- package/dist/src/utils/track-focus.d.ts +0 -0
- package/dist/src/utils/track-focus.d.ts.map +0 -0
- package/dist/src/utils/track-focus.js +0 -0
- package/dist/src/utils/track-focus.js.map +0 -0
- package/package.json +19 -19
|
@@ -22,6 +22,158 @@
|
|
|
22
22
|
* focus-trap npm package, and a11y-dialog.
|
|
23
23
|
*/
|
|
24
24
|
export class FocusTrapController {
|
|
25
|
+
static getManagedHostAncestor(element) {
|
|
26
|
+
let current = element;
|
|
27
|
+
while (current) {
|
|
28
|
+
const parentEl = current instanceof HTMLElement ? current.parentElement : null;
|
|
29
|
+
if (parentEl && parentEl.matches(FocusTrapController.MANAGED_HOST_SELECTORS))
|
|
30
|
+
return parentEl;
|
|
31
|
+
if (parentEl) {
|
|
32
|
+
current = parentEl;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const rootNode = current.getRootNode();
|
|
36
|
+
if (rootNode instanceof ShadowRoot) {
|
|
37
|
+
const hostElement = rootNode.host;
|
|
38
|
+
if (hostElement instanceof HTMLElement) {
|
|
39
|
+
if (hostElement.matches(FocusTrapController.MANAGED_HOST_SELECTORS))
|
|
40
|
+
return hostElement;
|
|
41
|
+
current = hostElement;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
static isInsideManagedHost(element) {
|
|
50
|
+
return FocusTrapController.getManagedHostAncestor(element) !== null;
|
|
51
|
+
}
|
|
52
|
+
static getManagedMenuHostAncestor(element) {
|
|
53
|
+
let current = element;
|
|
54
|
+
while (current) {
|
|
55
|
+
const parentEl = current instanceof HTMLElement ? current.parentElement : null;
|
|
56
|
+
if (parentEl && parentEl.matches(FocusTrapController.MANAGED_MENU_HOST_SELECTORS))
|
|
57
|
+
return parentEl;
|
|
58
|
+
if (parentEl) {
|
|
59
|
+
current = parentEl;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const rootNode = current.getRootNode();
|
|
63
|
+
if (rootNode instanceof ShadowRoot) {
|
|
64
|
+
const hostElement = rootNode.host;
|
|
65
|
+
if (hostElement instanceof HTMLElement) {
|
|
66
|
+
if (hostElement.matches(FocusTrapController.MANAGED_MENU_HOST_SELECTORS))
|
|
67
|
+
return hostElement;
|
|
68
|
+
current = hostElement;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
static collectFocusableCandidates(root, candidates, trigger, visited) {
|
|
77
|
+
const rootAsNode = root;
|
|
78
|
+
if (visited.has(rootAsNode))
|
|
79
|
+
return;
|
|
80
|
+
visited.add(rootAsNode);
|
|
81
|
+
const elements = Array.from(root.querySelectorAll('*'));
|
|
82
|
+
elements.forEach((el) => {
|
|
83
|
+
if (el === trigger)
|
|
84
|
+
return;
|
|
85
|
+
// Keep custom host components as single tab stops: their internal light/shadow
|
|
86
|
+
// descendants must not appear as separate trap candidates.
|
|
87
|
+
if (FocusTrapController.isInsideManagedHost(el))
|
|
88
|
+
return;
|
|
89
|
+
if (el.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {
|
|
90
|
+
candidates.push(el);
|
|
91
|
+
// Stop here: focusCandidate() handles delegation to the inner focusable.
|
|
92
|
+
// Prevent recursion into this element's shadow DOM so inner buttons/triggers
|
|
93
|
+
// are not added as separate tab stops.
|
|
94
|
+
if (el.shadowRoot)
|
|
95
|
+
visited.add(el.shadowRoot);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (el instanceof HTMLSlotElement) {
|
|
99
|
+
el.assignedElements({ flatten: true }).forEach((assigned) => {
|
|
100
|
+
if (!(assigned instanceof HTMLElement) || assigned === trigger)
|
|
101
|
+
return;
|
|
102
|
+
if (assigned.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {
|
|
103
|
+
candidates.push(assigned);
|
|
104
|
+
// Same rule: don't recurse into a focusable element.
|
|
105
|
+
if (assigned.shadowRoot)
|
|
106
|
+
visited.add(assigned.shadowRoot);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
FocusTrapController.collectFocusableCandidates(assigned, candidates, trigger, visited);
|
|
110
|
+
if (assigned.shadowRoot) {
|
|
111
|
+
FocusTrapController.collectFocusableCandidates(assigned.shadowRoot, candidates, trigger, visited);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (el.shadowRoot) {
|
|
117
|
+
FocusTrapController.collectFocusableCandidates(el.shadowRoot, candidates, trigger, visited);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
static getFirstFocusableInShadow(host) {
|
|
122
|
+
const visited = new Set();
|
|
123
|
+
const walk = (root) => {
|
|
124
|
+
const rootAsNode = root;
|
|
125
|
+
if (visited.has(rootAsNode))
|
|
126
|
+
return null;
|
|
127
|
+
visited.add(rootAsNode);
|
|
128
|
+
const direct = Array.from(root.querySelectorAll(FocusTrapController.NATIVE_FOCUSABLE_SELECTORS));
|
|
129
|
+
const firstDirect = direct.find((el) => FocusTrapController.isFocusable(el));
|
|
130
|
+
if (firstDirect)
|
|
131
|
+
return firstDirect;
|
|
132
|
+
const all = Array.from(root.querySelectorAll('*'));
|
|
133
|
+
for (const el of all) {
|
|
134
|
+
if (el instanceof HTMLSlotElement) {
|
|
135
|
+
const assigned = el.assignedElements({ flatten: true });
|
|
136
|
+
for (const assignedEl of assigned) {
|
|
137
|
+
if (!(assignedEl instanceof HTMLElement))
|
|
138
|
+
continue;
|
|
139
|
+
if (assignedEl.matches(FocusTrapController.NATIVE_FOCUSABLE_SELECTORS)) {
|
|
140
|
+
if (FocusTrapController.isFocusable(assignedEl))
|
|
141
|
+
return assignedEl;
|
|
142
|
+
}
|
|
143
|
+
const nestedAssigned = walk(assignedEl);
|
|
144
|
+
if (nestedAssigned)
|
|
145
|
+
return nestedAssigned;
|
|
146
|
+
if (assignedEl.shadowRoot) {
|
|
147
|
+
const nestedAssignedShadow = walk(assignedEl.shadowRoot);
|
|
148
|
+
if (nestedAssignedShadow)
|
|
149
|
+
return nestedAssignedShadow;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (el.shadowRoot) {
|
|
154
|
+
const nested = walk(el.shadowRoot);
|
|
155
|
+
if (nested)
|
|
156
|
+
return nested;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
};
|
|
161
|
+
if (!host.shadowRoot)
|
|
162
|
+
return null;
|
|
163
|
+
return walk(host.shadowRoot);
|
|
164
|
+
}
|
|
165
|
+
static focusCandidate(target) {
|
|
166
|
+
if (!target)
|
|
167
|
+
return;
|
|
168
|
+
if (target.tagName.toLowerCase().startsWith('it-')) {
|
|
169
|
+
const innerFocusable = FocusTrapController.getFirstFocusableInShadow(target);
|
|
170
|
+
if (innerFocusable) {
|
|
171
|
+
innerFocusable.focus({ preventScroll: true });
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
target.focus({ preventScroll: true });
|
|
176
|
+
}
|
|
25
177
|
/**
|
|
26
178
|
* Verifica se un elemento è effettivamente focusabile e tabbabile.
|
|
27
179
|
* Elementi con tabindex="-1" sono focusabili programmaticamente ma non tabbabili.
|
|
@@ -53,6 +205,10 @@ export class FocusTrapController {
|
|
|
53
205
|
this._isActive = false;
|
|
54
206
|
this._previousActiveElement = null;
|
|
55
207
|
this._focusableElements = [];
|
|
208
|
+
/** Last known index resolved from real focusin events inside the trap.
|
|
209
|
+
* Used as a fallback when assistive tech retargeting makes activeElement
|
|
210
|
+
* temporarily unmappable during Tab navigation. */
|
|
211
|
+
this._lastKnownFocusIndex = -1;
|
|
56
212
|
/** Timer ID for the focus call scheduled inside activate(). Cancelled by deactivate()
|
|
57
213
|
* to prevent focus firing after the trap has been torn down (fast open/close, unmount). */
|
|
58
214
|
this._pendingFocusTimer = null;
|
|
@@ -73,6 +229,32 @@ export class FocusTrapController {
|
|
|
73
229
|
break;
|
|
74
230
|
}
|
|
75
231
|
};
|
|
232
|
+
this._handleFocusIn = (event) => {
|
|
233
|
+
if (!this._isActive)
|
|
234
|
+
return;
|
|
235
|
+
if (this._focusableElements.length === 0) {
|
|
236
|
+
this.updateFocusableElements();
|
|
237
|
+
if (this._focusableElements.length === 0)
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const path = event.composedPath();
|
|
241
|
+
let index = this._focusableElements.findIndex((candidate) => path.includes(candidate));
|
|
242
|
+
if (index === -1) {
|
|
243
|
+
const target = path[0];
|
|
244
|
+
if (target instanceof HTMLElement) {
|
|
245
|
+
index = this._focusableElements.indexOf(target);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (index === -1) {
|
|
249
|
+
const active = FocusTrapController.getActiveElement();
|
|
250
|
+
if (active) {
|
|
251
|
+
index = this._focusableElements.findIndex((candidate) => candidate.contains(active));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (index !== -1) {
|
|
255
|
+
this._lastKnownFocusIndex = index;
|
|
256
|
+
}
|
|
257
|
+
};
|
|
76
258
|
this.host = host;
|
|
77
259
|
this.config = config;
|
|
78
260
|
this.host.addController(this);
|
|
@@ -103,7 +285,9 @@ export class FocusTrapController {
|
|
|
103
285
|
// Usa document capture: cattura Tab/Escape prima di qualsiasi handler,
|
|
104
286
|
// indipendentemente da shadow DOM, delegatesFocus e slot retargeting.
|
|
105
287
|
document.addEventListener('keydown', this._handleKeyDown, true);
|
|
288
|
+
document.addEventListener('focusin', this._handleFocusIn, true);
|
|
106
289
|
this.updateFocusableElements();
|
|
290
|
+
this._lastKnownFocusIndex = -1;
|
|
107
291
|
// FIX Safari: trick engine
|
|
108
292
|
// Diamo al browser un istante per processare il ricalcolo del layout
|
|
109
293
|
requestAnimationFrame(() => {
|
|
@@ -119,6 +303,7 @@ export class FocusTrapController {
|
|
|
119
303
|
}
|
|
120
304
|
}
|
|
121
305
|
else {
|
|
306
|
+
// eslint-disable-next-line no-console
|
|
122
307
|
console.warn("FocusTrap: missing 'initialFocus' callback, provide one");
|
|
123
308
|
}
|
|
124
309
|
});
|
|
@@ -134,6 +319,8 @@ export class FocusTrapController {
|
|
|
134
319
|
}
|
|
135
320
|
this._isActive = false;
|
|
136
321
|
document.removeEventListener('keydown', this._handleKeyDown, true);
|
|
322
|
+
document.removeEventListener('focusin', this._handleFocusIn, true);
|
|
323
|
+
this._lastKnownFocusIndex = -1;
|
|
137
324
|
if (!options?.skipFocusRestore) {
|
|
138
325
|
this._restoreFocus();
|
|
139
326
|
}
|
|
@@ -155,20 +342,21 @@ export class FocusTrapController {
|
|
|
155
342
|
return;
|
|
156
343
|
}
|
|
157
344
|
const candidates = [];
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
345
|
+
FocusTrapController.collectFocusableCandidates(container, candidates, trigger, new Set());
|
|
346
|
+
// Include anche i figli light DOM dell'host (es. contenuti slottati della modale)
|
|
347
|
+
Array.from(this.host.children).forEach((child) => {
|
|
348
|
+
if (!(child instanceof HTMLElement) || child === trigger)
|
|
349
|
+
return;
|
|
350
|
+
if (child.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {
|
|
351
|
+
candidates.push(child);
|
|
352
|
+
// Don't recurse: same stop-on-focusable rule.
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
const childVisited = new Set();
|
|
356
|
+
FocusTrapController.collectFocusableCandidates(child, candidates, trigger, childVisited);
|
|
357
|
+
if (child.shadowRoot) {
|
|
358
|
+
FocusTrapController.collectFocusableCandidates(child.shadowRoot, candidates, trigger, childVisited);
|
|
359
|
+
}
|
|
172
360
|
});
|
|
173
361
|
// Filtra solo elementi veramente focusabili e rimuovi duplicati
|
|
174
362
|
this._focusableElements = Array.from(new Set(candidates)).filter((el) => {
|
|
@@ -201,15 +389,24 @@ export class FocusTrapController {
|
|
|
201
389
|
return active;
|
|
202
390
|
}
|
|
203
391
|
_handleTab(event) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
392
|
+
const activeElement = FocusTrapController.getActiveElement();
|
|
393
|
+
// Let native Tab behavior handle navigation inside open dropdown/megamenu.
|
|
394
|
+
// This allows entering and traversing internal menu items correctly.
|
|
395
|
+
if (activeElement) {
|
|
396
|
+
const managedHost = FocusTrapController.getManagedMenuHostAncestor(activeElement);
|
|
397
|
+
if (managedHost && managedHost.getAttribute('data-it-aria-expanded') === 'true') {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
// Ricalcola sempre al Tab: gli elementi slottati possono completare il render
|
|
402
|
+
// del proprio shadow DOM dopo l'attivazione iniziale del trap.
|
|
403
|
+
this.updateFocusableElements();
|
|
207
404
|
if (this._focusableElements.length === 0)
|
|
208
405
|
return; // Se è ancora vuoto, non bloccare il Tab
|
|
209
406
|
event.preventDefault();
|
|
210
|
-
const activeElement = FocusTrapController.getActiveElement();
|
|
211
407
|
let currentIndex = this._focusableElements.indexOf(activeElement);
|
|
212
408
|
if (currentIndex === -1 && activeElement) {
|
|
409
|
+
// 1. Walk shadow host chain (covers delegatesFocus custom elements)
|
|
213
410
|
let parent = activeElement.getRootNode()?.host;
|
|
214
411
|
while (parent && currentIndex === -1) {
|
|
215
412
|
currentIndex = this._focusableElements.indexOf(parent);
|
|
@@ -217,16 +414,43 @@ export class FocusTrapController {
|
|
|
217
414
|
parent = parent.getRootNode()?.host;
|
|
218
415
|
}
|
|
219
416
|
}
|
|
417
|
+
if (currentIndex === -1) {
|
|
418
|
+
// 2. Composed path fallback: handles focus inside nested shadow/slotted
|
|
419
|
+
// content (e.g. anchors inside it-dropdown-item) by mapping the active
|
|
420
|
+
// target to the first focusable host found in the event path.
|
|
421
|
+
const composedPath = event.composedPath();
|
|
422
|
+
currentIndex = this._focusableElements.findIndex((candidate) => composedPath.includes(candidate));
|
|
423
|
+
}
|
|
424
|
+
if (currentIndex === -1 && activeElement) {
|
|
425
|
+
// 3. contains() fallback: handles focus inside an open dropdown/megamenu whose
|
|
426
|
+
// items live in light DOM (not shadow DOM), so the parent-walk above doesn't
|
|
427
|
+
// reach the host. Map to the host's index so Tab/Shift+Tab move to the
|
|
428
|
+
// correct adjacent element.
|
|
429
|
+
currentIndex = this._focusableElements.findIndex((candidate) => candidate.contains(activeElement));
|
|
430
|
+
}
|
|
431
|
+
if (currentIndex === -1) {
|
|
432
|
+
// 4. AT fallback: with some screen readers, document.activeElement and/or
|
|
433
|
+
// event target can be unreliable while navigating inside composite widgets.
|
|
434
|
+
// If a dropdown/megamenu is currently open, use its host index as anchor
|
|
435
|
+
// so forward/backward Tab continue from that position instead of wrapping.
|
|
436
|
+
currentIndex = this._focusableElements.findIndex((candidate) => candidate.matches('it-dropdown, it-megamenu') && candidate.getAttribute('data-it-aria-expanded') === 'true');
|
|
437
|
+
}
|
|
438
|
+
if (currentIndex === -1 && this._lastKnownFocusIndex >= 0) {
|
|
439
|
+
// 5. Last-known fallback: if assistive tech retargeting hides the active
|
|
440
|
+
// element for this key event, continue from the most recent resolved
|
|
441
|
+
// focus index captured via focusin.
|
|
442
|
+
currentIndex = Math.min(this._lastKnownFocusIndex, this._focusableElements.length - 1);
|
|
443
|
+
}
|
|
220
444
|
if (event.shiftKey) {
|
|
221
445
|
if (currentIndex <= 0)
|
|
222
|
-
this._last
|
|
446
|
+
FocusTrapController.focusCandidate(this._last);
|
|
223
447
|
else
|
|
224
|
-
this._focusableElements[currentIndex - 1]
|
|
448
|
+
FocusTrapController.focusCandidate(this._focusableElements[currentIndex - 1]);
|
|
225
449
|
}
|
|
226
450
|
else if (currentIndex === -1 || currentIndex >= this._focusableElements.length - 1)
|
|
227
|
-
this._first
|
|
451
|
+
FocusTrapController.focusCandidate(this._first);
|
|
228
452
|
else
|
|
229
|
-
this._focusableElements[currentIndex + 1]
|
|
453
|
+
FocusTrapController.focusCandidate(this._focusableElements[currentIndex + 1]);
|
|
230
454
|
}
|
|
231
455
|
_restoreFocus() {
|
|
232
456
|
const target = this._previousActiveElement;
|
|
@@ -251,5 +475,24 @@ FocusTrapController.FOCUSABLE_SELECTORS = [
|
|
|
251
475
|
'select:not([disabled])',
|
|
252
476
|
'[tabindex]',
|
|
253
477
|
'it-button:not([disabled])',
|
|
478
|
+
'it-dropdown:not([disabled])',
|
|
479
|
+
'it-megamenu:not([disabled])',
|
|
480
|
+
].join(',');
|
|
481
|
+
FocusTrapController.NATIVE_FOCUSABLE_SELECTORS = [
|
|
482
|
+
'a[href]',
|
|
483
|
+
'button:not([disabled])',
|
|
484
|
+
'textarea:not([disabled])',
|
|
485
|
+
'input:not([disabled]):not([type="hidden"])',
|
|
486
|
+
'select:not([disabled])',
|
|
487
|
+
'[tabindex]:not([tabindex="-1"])',
|
|
488
|
+
].join(',');
|
|
489
|
+
FocusTrapController.MANAGED_HOST_SELECTORS = [
|
|
490
|
+
'it-button:not([disabled])',
|
|
491
|
+
'it-dropdown:not([disabled])',
|
|
492
|
+
'it-megamenu:not([disabled])',
|
|
493
|
+
].join(',');
|
|
494
|
+
FocusTrapController.MANAGED_MENU_HOST_SELECTORS = [
|
|
495
|
+
'it-dropdown:not([disabled])',
|
|
496
|
+
'it-megamenu:not([disabled])',
|
|
254
497
|
].join(',');
|
|
255
498
|
//# 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;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,mBAAmB;IA+B9B;;;OAGG;IACK,MAAM,CAAC,WAAW,CAAC,EAAe;QACxC,IAAI,OAAO,EAAE,CAAC,KAAK,KAAK,UAAU;YAAE,OAAO,KAAK,CAAC;QACjD,IAAI,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC;YAAE,OAAO,KAAK,CAAC;QACzG,MAAM,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QAC7C,IAAI,QAAQ,IAAI,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QAEzD,IAAI,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/C,IAAI,QAAQ,IAAI,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC;gBAAE,OAAO,KAAK,CAAC;YACzD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,wFAA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AU,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"]}
|
|
1
|
+
{"version":3,"file":"focus-trap-controller.js","sourceRoot":"","sources":["../../../src/controllers/focus-trap-controller.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,mBAAmB;IA0DtB,MAAM,CAAC,sBAAsB,CAAC,OAAoB;QACxD,IAAI,OAAO,GAAgB,OAAO,CAAC;QAEnC,OAAO,OAAO,EAAE,CAAC;YACf,MAAM,QAAQ,GAAuB,OAAO,YAAY,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC;YACnG,IAAI,QAAQ,IAAI,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,sBAAsB,CAAC;gBAAE,OAAO,QAAQ,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CAAC,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC;IACrF,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;;AAvfuB,uCAAmB,GAAG;IAC5C,SAAS;IACT,wBAAwB;IACxB,0BAA0B;IAC1B,4CAA4C;IAC5C,wBAAwB;IACxB,YAAY;IACZ,2BAA2B;IAC3B,6BAA6B;IAC7B,6BAA6B;CAC9B,CAAC,IAAI,CAAC,GAAG,CAAC,AAVgC,CAU/B;AAEY,8CAA0B,GAAG;IACnD,SAAS;IACT,wBAAwB;IACxB,0BAA0B;IAC1B,4CAA4C;IAC5C,wBAAwB;IACxB,iCAAiC;CAClC,CAAC,IAAI,CAAC,GAAG,CAAC,AAPuC,CAOtC;AAEY,0CAAsB,GAAG;IAC/C,2BAA2B;IAC3B,6BAA6B;IAC7B,6BAA6B;CAC9B,CAAC,IAAI,CAAC,GAAG,CAAC,AAJmC,CAIlC;AAEY,+CAA2B,GAAG;IACpD,6BAA6B;IAC7B,6BAA6B;CAC9B,CAAC,IAAI,CAAC,GAAG,CAAC,AAHwC,CAGvC","sourcesContent":["/* eslint-disable no-continue */\nimport { 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: HTMLElement[] = [];\n\n private _first?: HTMLElement;\n\n private _last?: HTMLElement;\n\n /** Last known index resolved from real focusin events inside the trap.\n * Used as a fallback when assistive tech retargeting makes activeElement\n * temporarily unmappable during Tab navigation. */\n private _lastKnownFocusIndex = -1;\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 'it-dropdown:not([disabled])',\n 'it-megamenu:not([disabled])',\n ].join(',');\n\n private static readonly NATIVE_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]:not([tabindex=\"-1\"])',\n ].join(',');\n\n private static readonly MANAGED_HOST_SELECTORS = [\n 'it-button:not([disabled])',\n 'it-dropdown:not([disabled])',\n 'it-megamenu:not([disabled])',\n ].join(',');\n\n private static readonly MANAGED_MENU_HOST_SELECTORS = [\n 'it-dropdown:not([disabled])',\n 'it-megamenu:not([disabled])',\n ].join(',');\n\n private static getManagedHostAncestor(element: HTMLElement): HTMLElement | null {\n let current: Node | null = element;\n\n while (current) {\n const parentEl: HTMLElement | null = current instanceof HTMLElement ? current.parentElement : null;\n if (parentEl && parentEl.matches(FocusTrapController.MANAGED_HOST_SELECTORS)) return parentEl;\n\n if (parentEl) {\n current = parentEl;\n continue;\n }\n\n const rootNode: Node = current.getRootNode();\n if (rootNode instanceof ShadowRoot) {\n const hostElement: Element = rootNode.host;\n if (hostElement instanceof HTMLElement) {\n if (hostElement.matches(FocusTrapController.MANAGED_HOST_SELECTORS)) return hostElement;\n current = hostElement;\n continue;\n }\n }\n\n break;\n }\n\n return null;\n }\n\n private static isInsideManagedHost(element: HTMLElement): boolean {\n return FocusTrapController.getManagedHostAncestor(element) !== null;\n }\n\n private static getManagedMenuHostAncestor(element: HTMLElement): HTMLElement | null {\n let current: Node | null = element;\n\n while (current) {\n const parentEl: HTMLElement | null = current instanceof HTMLElement ? current.parentElement : null;\n if (parentEl && parentEl.matches(FocusTrapController.MANAGED_MENU_HOST_SELECTORS)) return parentEl;\n\n if (parentEl) {\n current = parentEl;\n continue;\n }\n\n const rootNode: Node = current.getRootNode();\n if (rootNode instanceof ShadowRoot) {\n const hostElement: Element = rootNode.host;\n if (hostElement instanceof HTMLElement) {\n if (hostElement.matches(FocusTrapController.MANAGED_MENU_HOST_SELECTORS)) return hostElement;\n current = hostElement;\n continue;\n }\n }\n\n break;\n }\n\n return null;\n }\n\n private static collectFocusableCandidates(\n root: ParentNode,\n candidates: HTMLElement[],\n trigger: HTMLElement | ShadowRoot | null,\n visited: Set<Node>,\n ): void {\n const rootAsNode = root as Node;\n if (visited.has(rootAsNode)) return;\n visited.add(rootAsNode);\n\n const elements = Array.from(root.querySelectorAll<HTMLElement>('*'));\n elements.forEach((el) => {\n if (el === trigger) return;\n\n // Keep custom host components as single tab stops: their internal light/shadow\n // descendants must not appear as separate trap candidates.\n if (FocusTrapController.isInsideManagedHost(el)) return;\n\n if (el.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {\n candidates.push(el);\n // Stop here: focusCandidate() handles delegation to the inner focusable.\n // Prevent recursion into this element's shadow DOM so inner buttons/triggers\n // are not added as separate tab stops.\n if (el.shadowRoot) visited.add(el.shadowRoot);\n return;\n }\n\n if (el instanceof HTMLSlotElement) {\n el.assignedElements({ flatten: true }).forEach((assigned) => {\n if (!(assigned instanceof HTMLElement) || assigned === trigger) return;\n\n if (assigned.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {\n candidates.push(assigned);\n // Same rule: don't recurse into a focusable element.\n if (assigned.shadowRoot) visited.add(assigned.shadowRoot);\n return;\n }\n\n FocusTrapController.collectFocusableCandidates(assigned, candidates, trigger, visited);\n\n if (assigned.shadowRoot) {\n FocusTrapController.collectFocusableCandidates(assigned.shadowRoot, candidates, trigger, visited);\n }\n });\n return;\n }\n\n if (el.shadowRoot) {\n FocusTrapController.collectFocusableCandidates(el.shadowRoot, candidates, trigger, visited);\n }\n });\n }\n\n private static getFirstFocusableInShadow(host: HTMLElement): HTMLElement | null {\n const visited = new Set<Node>();\n\n const walk = (root: ParentNode): HTMLElement | null => {\n const rootAsNode = root as Node;\n if (visited.has(rootAsNode)) return null;\n visited.add(rootAsNode);\n\n const direct = Array.from(root.querySelectorAll<HTMLElement>(FocusTrapController.NATIVE_FOCUSABLE_SELECTORS));\n const firstDirect = direct.find((el) => FocusTrapController.isFocusable(el));\n if (firstDirect) return firstDirect;\n\n const all = Array.from(root.querySelectorAll<HTMLElement>('*'));\n for (const el of all) {\n if (el instanceof HTMLSlotElement) {\n const assigned = el.assignedElements({ flatten: true });\n for (const assignedEl of assigned) {\n if (!(assignedEl instanceof HTMLElement)) continue;\n if (assignedEl.matches(FocusTrapController.NATIVE_FOCUSABLE_SELECTORS)) {\n if (FocusTrapController.isFocusable(assignedEl)) return assignedEl;\n }\n const nestedAssigned = walk(assignedEl);\n if (nestedAssigned) return nestedAssigned;\n if (assignedEl.shadowRoot) {\n const nestedAssignedShadow = walk(assignedEl.shadowRoot);\n if (nestedAssignedShadow) return nestedAssignedShadow;\n }\n }\n }\n\n if (el.shadowRoot) {\n const nested = walk(el.shadowRoot);\n if (nested) return nested;\n }\n }\n\n return null;\n };\n\n if (!host.shadowRoot) return null;\n return walk(host.shadowRoot);\n }\n\n private static focusCandidate(target: HTMLElement | undefined): void {\n if (!target) return;\n\n if (target.tagName.toLowerCase().startsWith('it-')) {\n const innerFocusable = FocusTrapController.getFirstFocusableInShadow(target);\n if (innerFocusable) {\n innerFocusable.focus({ preventScroll: true });\n return;\n }\n }\n\n target.focus({ preventScroll: true });\n }\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 document.addEventListener('focusin', this._handleFocusIn, true);\n this.updateFocusableElements();\n this._lastKnownFocusIndex = -1;\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 // eslint-disable-next-line no-console\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 document.removeEventListener('focusin', this._handleFocusIn, true);\n this._lastKnownFocusIndex = -1;\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 FocusTrapController.collectFocusableCandidates(container, candidates, trigger, new Set<Node>());\n\n // Include anche i figli light DOM dell'host (es. contenuti slottati della modale)\n Array.from(this.host.children).forEach((child) => {\n if (!(child instanceof HTMLElement) || child === trigger) return;\n\n if (child.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {\n candidates.push(child);\n // Don't recurse: same stop-on-focusable rule.\n return;\n }\n\n const childVisited = new Set<Node>();\n FocusTrapController.collectFocusableCandidates(child, candidates, trigger, childVisited);\n\n if (child.shadowRoot) {\n FocusTrapController.collectFocusableCandidates(child.shadowRoot, candidates, trigger, childVisited);\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 _handleFocusIn = (event: FocusEvent): void => {\n if (!this._isActive) return;\n\n if (this._focusableElements.length === 0) {\n this.updateFocusableElements();\n if (this._focusableElements.length === 0) return;\n }\n\n const path = event.composedPath();\n let index = this._focusableElements.findIndex((candidate) => path.includes(candidate));\n\n if (index === -1) {\n const target = path[0];\n if (target instanceof HTMLElement) {\n index = this._focusableElements.indexOf(target);\n }\n }\n\n if (index === -1) {\n const active = FocusTrapController.getActiveElement();\n if (active) {\n index = this._focusableElements.findIndex((candidate) => candidate.contains(active));\n }\n }\n\n if (index !== -1) {\n this._lastKnownFocusIndex = index;\n }\n };\n\n private _handleTab(event: KeyboardEvent): void {\n const activeElement = FocusTrapController.getActiveElement();\n\n // Let native Tab behavior handle navigation inside open dropdown/megamenu.\n // This allows entering and traversing internal menu items correctly.\n if (activeElement) {\n const managedHost = FocusTrapController.getManagedMenuHostAncestor(activeElement);\n if (managedHost && managedHost.getAttribute('data-it-aria-expanded') === 'true') {\n return;\n }\n }\n\n // Ricalcola sempre al Tab: gli elementi slottati possono completare il render\n // del proprio shadow DOM dopo l'attivazione iniziale del trap.\n this.updateFocusableElements();\n if (this._focusableElements.length === 0) return; // Se è ancora vuoto, non bloccare il Tab\n\n event.preventDefault();\n let currentIndex = this._focusableElements.indexOf(activeElement as HTMLElement);\n\n if (currentIndex === -1 && activeElement) {\n // 1. Walk shadow host chain (covers delegatesFocus custom elements)\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 (currentIndex === -1) {\n // 2. Composed path fallback: handles focus inside nested shadow/slotted\n // content (e.g. anchors inside it-dropdown-item) by mapping the active\n // target to the first focusable host found in the event path.\n const composedPath = event.composedPath();\n currentIndex = this._focusableElements.findIndex((candidate) => composedPath.includes(candidate));\n }\n\n if (currentIndex === -1 && activeElement) {\n // 3. contains() fallback: handles focus inside an open dropdown/megamenu whose\n // items live in light DOM (not shadow DOM), so the parent-walk above doesn't\n // reach the host. Map to the host's index so Tab/Shift+Tab move to the\n // correct adjacent element.\n currentIndex = this._focusableElements.findIndex((candidate) => candidate.contains(activeElement));\n }\n\n if (currentIndex === -1) {\n // 4. AT fallback: with some screen readers, document.activeElement and/or\n // event target can be unreliable while navigating inside composite widgets.\n // If a dropdown/megamenu is currently open, use its host index as anchor\n // so forward/backward Tab continue from that position instead of wrapping.\n currentIndex = this._focusableElements.findIndex(\n (candidate) =>\n candidate.matches('it-dropdown, it-megamenu') && candidate.getAttribute('data-it-aria-expanded') === 'true',\n );\n }\n\n if (currentIndex === -1 && this._lastKnownFocusIndex >= 0) {\n // 5. Last-known fallback: if assistive tech retargeting hides the active\n // element for this key event, continue from the most recent resolved\n // focus index captured via focusin.\n currentIndex = Math.min(this._lastKnownFocusIndex, this._focusableElements.length - 1);\n }\n\n if (event.shiftKey) {\n if (currentIndex <= 0) FocusTrapController.focusCandidate(this._last);\n else FocusTrapController.focusCandidate(this._focusableElements[currentIndex - 1]);\n } else if (currentIndex === -1 || currentIndex >= this._focusableElements.length - 1)\n FocusTrapController.focusCandidate(this._first);\n else FocusTrapController.focusCandidate(this._focusableElements[currentIndex + 1]);\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"]}
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setAttributes.d.ts","sourceRoot":"","sources":["../../../src/directives/setAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"setAttributes.d.ts","sourceRoot":"","sources":["../../../src/directives/setAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAmD5F,cAAM,sBAAuB,SAAQ,SAAS;IAC5C,MAAM,CAAC,IAAI,EAAE,aAAa,EAAE,CAAC,UAAU,CAAC,EAAE,mBAAmB,CAAC,IAAI,CAAC;IAgCnE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAG3C;AAMD,QAAA,MAAM,aAAa,oHAAoC,CAAC;AAExD,eAAe,aAAa,CAAC"}
|
|
@@ -1,12 +1,78 @@
|
|
|
1
1
|
import { directive, Directive } from 'lit/directive.js';
|
|
2
|
+
const ARIA_IDREF_ATTRIBUTES = new Map([
|
|
3
|
+
['aria-activedescendant', 'ariaActivedescendantElement'],
|
|
4
|
+
['aria-controls', 'ariaControlsElements'],
|
|
5
|
+
['aria-describedby', 'ariaDescribedByElements'],
|
|
6
|
+
['aria-details', 'ariaDetailsElements'],
|
|
7
|
+
['aria-errormessage', 'ariaErrormessageElements'],
|
|
8
|
+
['aria-flowto', 'ariaFlowtoElements'],
|
|
9
|
+
['aria-labelledby', 'ariaLabelledByElements'],
|
|
10
|
+
['aria-owns', 'ariaOwnsElements'],
|
|
11
|
+
]);
|
|
12
|
+
function resolveAriaIdRefs(element, value) {
|
|
13
|
+
const ids = value
|
|
14
|
+
.trim()
|
|
15
|
+
.split(/\s+/)
|
|
16
|
+
.filter((id) => id.length > 0);
|
|
17
|
+
if (ids.length === 0)
|
|
18
|
+
return null;
|
|
19
|
+
const root = element.getRootNode();
|
|
20
|
+
let resolvedElements = [];
|
|
21
|
+
if (root instanceof ShadowRoot) {
|
|
22
|
+
resolvedElements = ids.map((id) => root.getElementById(id));
|
|
23
|
+
}
|
|
24
|
+
else if (root instanceof Document) {
|
|
25
|
+
resolvedElements = ids.map((id) => root.getElementById(id));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
resolvedElements = ids.map((id) => document.getElementById(id));
|
|
29
|
+
}
|
|
30
|
+
if (resolvedElements.filter((el) => el !== null).length === 0) {
|
|
31
|
+
resolvedElements = ids.map((id) => document.getElementById(id));
|
|
32
|
+
}
|
|
33
|
+
const validElements = resolvedElements.filter((el) => el !== null);
|
|
34
|
+
return validElements.length === ids.length ? validElements : null;
|
|
35
|
+
}
|
|
36
|
+
function setInternalsProperty(el, name, resolvedElements) {
|
|
37
|
+
if (name === 'aria-activedescendant') {
|
|
38
|
+
const [firstElement] = resolvedElements;
|
|
39
|
+
// eslint-disable-next-line no-param-reassign
|
|
40
|
+
el[name] = firstElement;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// eslint-disable-next-line no-param-reassign
|
|
44
|
+
el[name] = resolvedElements;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
2
47
|
class SetAttributesDirective extends Directive {
|
|
3
48
|
update(part, [attributes]) {
|
|
4
49
|
const el = part.element;
|
|
50
|
+
const internals = el.internals ?? null;
|
|
5
51
|
for (const [name, value] of Object.entries(attributes)) {
|
|
6
|
-
if (value
|
|
7
|
-
el.setAttribute(name, value);
|
|
8
|
-
else
|
|
52
|
+
if (value == null) {
|
|
9
53
|
el.removeAttribute(name);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const internalsPropertyName = ARIA_IDREF_ATTRIBUTES.get(name);
|
|
57
|
+
if (internalsPropertyName) {
|
|
58
|
+
const resolvedElements = resolveAriaIdRefs(el, String(value));
|
|
59
|
+
if (resolvedElements) {
|
|
60
|
+
if (internals) {
|
|
61
|
+
// Set on ElementInternals
|
|
62
|
+
setInternalsProperty(internals, internalsPropertyName, resolvedElements);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// Set internals property on shadowdom item
|
|
66
|
+
el.setAttribute(name, String(value));
|
|
67
|
+
setInternalsProperty(el, internalsPropertyName, resolvedElements);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// Non-ARIA IDREF attributes: set normally
|
|
73
|
+
el.setAttribute(name, String(value));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
10
76
|
}
|
|
11
77
|
return null;
|
|
12
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setAttributes.js","sourceRoot":"","sources":["../../../src/directives/setAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAsC,MAAM,kBAAkB,CAAC;AAE5F,MAAM,sBAAuB,SAAQ,SAAS;IAC5C,MAAM,CAAC,IAAmB,EAAE,CAAC,UAAU,CAA4B;QACjE,MAAM,EAAE,GAAI,IAAY,CAAC,OAAO,CAAC;QACjC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YACvD,IAAI,KAAK,I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CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YACvD,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;gBAClB,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC;iBAAM,CAAC;gBACN,MAAM,qBAAqB,GAAG,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC9D,IAAI,qBAAqB,EAAE,CAAC;oBAC1B,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;oBAE9D,IAAI,gBAAgB,EAAE,CAAC;wBACrB,IAAI,SAAS,EAAE,CAAC;4BACd,0BAA0B;4BAC1B,oBAAoB,CAAC,SAAS,EAAE,qBAAqB,EAAE,gBAAgB,CAAC,CAAC;wBAC3E,CAAC;6BAAM,CAAC;4BACN,2CAA2C;4BAC3C,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;4BACrC,oBAAoB,CAAC,EAAE,EAAE,qBAAqB,EAAE,gBAAgB,CAAC,CAAC;wBACpE,CAAC;oBACH,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,0CAA0C;oBAC1C,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;gBACvC,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,6DAA6D;IAC7D,MAAM,CAAC,WAAmC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED;;;EAGE;AACF,MAAM,aAAa,GAAG,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAExD,eAAe,aAAa,CAAC","sourcesContent":["import { directive, Directive, AttributePart, DirectiveParameters } from 'lit/directive.js';\n\nconst ARIA_IDREF_ATTRIBUTES = new Map([\n ['aria-activedescendant', 'ariaActivedescendantElement'],\n ['aria-controls', 'ariaControlsElements'],\n ['aria-describedby', 'ariaDescribedByElements'],\n ['aria-details', 'ariaDetailsElements'],\n ['aria-errormessage', 'ariaErrormessageElements'],\n ['aria-flowto', 'ariaFlowtoElements'],\n ['aria-labelledby', 'ariaLabelledByElements'],\n ['aria-owns', 'ariaOwnsElements'],\n]);\n\nfunction resolveAriaIdRefs(element: Element, value: string): HTMLElement[] | null {\n const ids = value\n .trim()\n .split(/\\s+/)\n .filter((id) => id.length > 0);\n\n if (ids.length === 0) return null;\n\n const root = element.getRootNode();\n let resolvedElements: (HTMLElement | null)[] = [];\n\n if (root instanceof ShadowRoot) {\n resolvedElements = ids.map((id) => root.getElementById(id) as HTMLElement | null);\n } else if (root instanceof Document) {\n resolvedElements = ids.map((id) => root.getElementById(id) as HTMLElement | null);\n } else {\n resolvedElements = ids.map((id) => document.getElementById(id) as HTMLElement | null);\n }\n\n if (resolvedElements.filter((el) => el !== null).length === 0) {\n resolvedElements = ids.map((id) => document.getElementById(id) as HTMLElement | null);\n }\n\n const validElements = resolvedElements.filter((el) => el !== null) as HTMLElement[];\n\n return validElements.length === ids.length ? validElements : null;\n}\n\nfunction setInternalsProperty(el: any, name: string, resolvedElements: HTMLElement[]) {\n if (name === 'aria-activedescendant') {\n const [firstElement] = resolvedElements;\n // eslint-disable-next-line no-param-reassign\n el[name] = firstElement;\n } else {\n // eslint-disable-next-line no-param-reassign\n el[name] = resolvedElements;\n }\n}\nclass SetAttributesDirective extends Directive {\n update(part: AttributePart, [attributes]: DirectiveParameters<this>) {\n const el = (part as any).element;\n const internals = el.internals ?? null;\n\n for (const [name, value] of Object.entries(attributes)) {\n if (value == null) {\n el.removeAttribute(name);\n } else {\n const internalsPropertyName = ARIA_IDREF_ATTRIBUTES.get(name);\n if (internalsPropertyName) {\n const resolvedElements = resolveAriaIdRefs(el, String(value));\n\n if (resolvedElements) {\n if (internals) {\n // Set on ElementInternals\n setInternalsProperty(internals, internalsPropertyName, resolvedElements);\n } else {\n // Set internals property on shadowdom item\n el.setAttribute(name, String(value));\n setInternalsProperty(el, internalsPropertyName, resolvedElements);\n }\n }\n } else {\n // Non-ARIA IDREF attributes: set normally\n el.setAttribute(name, String(value));\n }\n }\n }\n return null;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n render(_attributes: Record<string, string>) {\n return null;\n }\n}\n\n/* How to use:\n\n<textarea ${setAttributes(this._ariaAttributes)} ... />\n*/\nconst setAttributes = directive(SetAttributesDirective);\n\nexport default setAttributes;\n"]}
|
|
File without changes
|
|
File without changes
|
|
@@ -13,7 +13,7 @@ export class FormControl extends BaseLocalizedComponent {
|
|
|
13
13
|
});
|
|
14
14
|
// TODO: verificare se serve davvero con il fatto che usiamo form-controller
|
|
15
15
|
// static formAssociated = true;
|
|
16
|
-
//
|
|
16
|
+
// @property()
|
|
17
17
|
// internals = this.attachInternals();
|
|
18
18
|
this._touched = false;
|
|
19
19
|
/** The name of the input, submitted as a name/value pair with form data. */
|