@italia/globals 0.1.0-alpha.2 → 1.0.0-alpha.11

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.
Files changed (36) hide show
  1. package/custom-elements.json +680 -166
  2. package/dist/src/base-component/base-component.d.ts +19 -7
  3. package/dist/src/base-component/base-component.d.ts.map +1 -1
  4. package/dist/src/controllers/focus-trap-controller.d.ts +92 -0
  5. package/dist/src/controllers/focus-trap-controller.d.ts.map +1 -0
  6. package/dist/src/controllers/focus-trap-controller.js +497 -0
  7. package/dist/src/controllers/focus-trap-controller.js.map +1 -0
  8. package/dist/src/controllers/roving-tabindex-controller.d.ts +9 -2
  9. package/dist/src/controllers/roving-tabindex-controller.d.ts.map +1 -1
  10. package/dist/src/controllers/roving-tabindex-controller.js +11 -5
  11. package/dist/src/controllers/roving-tabindex-controller.js.map +1 -1
  12. package/dist/src/form/form-control.d.ts +2 -1
  13. package/dist/src/form/form-control.d.ts.map +1 -1
  14. package/dist/src/form/form-control.js +15 -7
  15. package/dist/src/form/form-control.js.map +1 -1
  16. package/dist/src/form/form-controller.d.ts +2 -0
  17. package/dist/src/form/form-controller.d.ts.map +1 -1
  18. package/dist/src/form/form-controller.js +45 -1
  19. package/dist/src/form/form-controller.js.map +1 -1
  20. package/dist/src/form/locales/it.d.ts.map +1 -1
  21. package/dist/src/form/locales/it.js +1 -0
  22. package/dist/src/form/locales/it.js.map +1 -1
  23. package/dist/src/index.d.ts +8 -0
  24. package/dist/src/index.d.ts.map +1 -1
  25. package/dist/src/index.js +8 -0
  26. package/dist/src/index.js.map +1 -1
  27. package/dist/src/mixins/validity.d.ts +18 -6
  28. package/dist/src/mixins/validity.d.ts.map +1 -1
  29. package/dist/src/stories/formControlReusableStories.d.ts.map +1 -1
  30. package/dist/src/stories/formControlReusableStories.js +5 -4
  31. package/dist/src/stories/formControlReusableStories.js.map +1 -1
  32. package/dist/src/window-manager.d.ts +13 -0
  33. package/dist/src/window-manager.d.ts.map +1 -1
  34. package/dist/src/window-manager.js +31 -0
  35. package/dist/src/window-manager.js.map +1 -1
  36. package/package.json +2 -2
@@ -0,0 +1,497 @@
1
+ /**
2
+ * Safari/VoiceOver iOS workarounds catalogue — why timers exist here:
3
+ *
4
+ * 1. `activate()` rAF + setTimeout(50): Safari does not reliably update the VoiceOver
5
+ * accessibility tree synchronously. rAF ensures the element is painted before we
6
+ * attempt to focus it. setTimeout(50) yields 50ms so VoiceOver can settle its
7
+ * accessibility tree before announcing the newly focused element.
8
+ * Empirically, VoiceOver iOS needs 100–300ms; the animated path in it-modal already
9
+ * provides ~316ms naturally via animation.finished, so the 50ms here only truly
10
+ * matters for the no-animation / prefers-reduced-motion path.
11
+ *
12
+ * 2. `_restoreFocus()` setTimeout(0): Same settle reason on close. The caller
13
+ * (it-modal finishHide) adds a belt-and-suspenders 20ms setTimeout; _restoreFocus
14
+ * is skipped via { skipFocusRestore: true } in that case to avoid double-focus.
15
+ *
16
+ * 3. `activate()` iOS body-focus fallback: On iOS Safari, tapping a button does not
17
+ * reliably move document.activeElement away from body. We fall back to getTrigger()
18
+ * so _previousActiveElement is always a real DOM element to restore focus to on close.
19
+ *
20
+ * There is no WebKit/Safari API to detect when VoiceOver has settled its accessibility
21
+ * tree. setTimeout-based workarounds are the same pattern used by Bootstrap 5, the
22
+ * focus-trap npm package, and a11y-dialog.
23
+ */
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
+ }
177
+ /**
178
+ * Verifica se un elemento è effettivamente focusabile e tabbabile.
179
+ * Elementi con tabindex="-1" sono focusabili programmaticamente ma non tabbabili.
180
+ */
181
+ static isFocusable(el) {
182
+ if (typeof el.focus !== 'function')
183
+ return false;
184
+ if (el.hasAttribute('disabled') || el.hasAttribute('inert') || el.hasAttribute('it-inert'))
185
+ return false;
186
+ const tabindex = el.getAttribute('tabindex');
187
+ if (tabindex && parseInt(tabindex, 10) < 0)
188
+ return false;
189
+ if (el.tagName.toLowerCase().startsWith('it-')) {
190
+ if (tabindex && parseInt(tabindex, 10) < 0)
191
+ return false;
192
+ return true;
193
+ }
194
+ // Fix Race Condition Safari: durante l'apertura non fidarti di getClientRects o opacità
195
+ try {
196
+ const style = window.getComputedStyle(el);
197
+ return style && style.display !== 'none' && style.visibility !== 'hidden';
198
+ }
199
+ catch {
200
+ return false;
201
+ }
202
+ }
203
+ constructor(host, config) {
204
+ this.observer = null;
205
+ this._isActive = false;
206
+ this._previousActiveElement = null;
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;
212
+ /** Timer ID for the focus call scheduled inside activate(). Cancelled by deactivate()
213
+ * to prevent focus firing after the trap has been torn down (fast open/close, unmount). */
214
+ this._pendingFocusTimer = null;
215
+ this._handleKeyDown = (event) => {
216
+ if (!this._isActive)
217
+ return;
218
+ switch (event.key) {
219
+ case 'Escape':
220
+ if (!this.config.disableEscape && this.config.onEscape) {
221
+ event.preventDefault();
222
+ this.config.onEscape();
223
+ }
224
+ break;
225
+ case 'Tab':
226
+ this._handleTab(event);
227
+ break;
228
+ default:
229
+ break;
230
+ }
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
+ };
258
+ this.host = host;
259
+ this.config = config;
260
+ this.host.addController(this);
261
+ }
262
+ hostConnected() {
263
+ const observerOptions = { childList: true, attributes: true, subtree: true };
264
+ this.observer = new MutationObserver(this.updateFocusableElements.bind(this));
265
+ this.observer.observe(this.host, observerOptions);
266
+ }
267
+ hostDisconnected() {
268
+ this.deactivate();
269
+ if (this.observer) {
270
+ this.observer.disconnect();
271
+ this.observer = null;
272
+ }
273
+ }
274
+ get isActive() {
275
+ return this._isActive;
276
+ }
277
+ activate() {
278
+ if (this._isActive)
279
+ return;
280
+ this._isActive = true;
281
+ // FIX iOS: Safari non dà focus al tap. Se activeElement è body, salviamo il trigger della config.
282
+ const currentActive = FocusTrapController.getActiveElement();
283
+ this._previousActiveElement =
284
+ !currentActive || currentActive === document.body ? this.config.getTrigger() : currentActive;
285
+ // Usa document capture: cattura Tab/Escape prima di qualsiasi handler,
286
+ // indipendentemente da shadow DOM, delegatesFocus e slot retargeting.
287
+ document.addEventListener('keydown', this._handleKeyDown, true);
288
+ document.addEventListener('focusin', this._handleFocusIn, true);
289
+ this.updateFocusableElements();
290
+ this._lastKnownFocusIndex = -1;
291
+ // FIX Safari: trick engine
292
+ // Diamo al browser un istante per processare il ricalcolo del layout
293
+ requestAnimationFrame(() => {
294
+ if (this.config.initialFocus) {
295
+ const el = this.config.initialFocus();
296
+ if (el) {
297
+ // 50ms gives VoiceOver iOS time to settle its accessibility tree before
298
+ // announcing the focused element. See class-level comment for details.
299
+ this._pendingFocusTimer = setTimeout(() => {
300
+ this._pendingFocusTimer = null;
301
+ el.focus({ preventScroll: true });
302
+ }, 50);
303
+ }
304
+ }
305
+ else {
306
+ console.warn("FocusTrap: missing 'initialFocus' callback, provide one");
307
+ }
308
+ });
309
+ }
310
+ deactivate(options) {
311
+ if (!this._isActive)
312
+ return;
313
+ // Cancel any in-flight focus timer so it cannot fire after the trap is torn down
314
+ // (e.g. fast open/close cycle, component unmounted while opening).
315
+ if (this._pendingFocusTimer !== null) {
316
+ clearTimeout(this._pendingFocusTimer);
317
+ this._pendingFocusTimer = null;
318
+ }
319
+ this._isActive = false;
320
+ document.removeEventListener('keydown', this._handleKeyDown, true);
321
+ document.removeEventListener('focusin', this._handleFocusIn, true);
322
+ this._lastKnownFocusIndex = -1;
323
+ if (!options?.skipFocusRestore) {
324
+ this._restoreFocus();
325
+ }
326
+ else {
327
+ this._previousActiveElement = null;
328
+ }
329
+ }
330
+ /**
331
+ * Aggiorna la lista degli elementi focusabili.
332
+ * Chiamare dopo modifiche al DOM.
333
+ */
334
+ updateFocusableElements() {
335
+ const container = this.config.getContainer();
336
+ const trigger = this.config.getTrigger();
337
+ if (!container) {
338
+ this._focusableElements = [];
339
+ this._first = undefined;
340
+ this._last = undefined;
341
+ return;
342
+ }
343
+ const candidates = [];
344
+ FocusTrapController.collectFocusableCandidates(container, candidates, trigger, new Set());
345
+ // Include anche i figli light DOM dell'host (es. contenuti slottati della modale)
346
+ Array.from(this.host.children).forEach((child) => {
347
+ if (!(child instanceof HTMLElement) || child === trigger)
348
+ return;
349
+ if (child.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {
350
+ candidates.push(child);
351
+ // Don't recurse: same stop-on-focusable rule.
352
+ return;
353
+ }
354
+ const childVisited = new Set();
355
+ FocusTrapController.collectFocusableCandidates(child, candidates, trigger, childVisited);
356
+ if (child.shadowRoot) {
357
+ FocusTrapController.collectFocusableCandidates(child.shadowRoot, candidates, trigger, childVisited);
358
+ }
359
+ });
360
+ // Filtra solo elementi veramente focusabili e rimuovi duplicati
361
+ this._focusableElements = Array.from(new Set(candidates)).filter((el) => {
362
+ // Escludi esplicitamente il container/dialog stesso
363
+ if (el === this.config.getContainer())
364
+ return false;
365
+ return FocusTrapController.isFocusable(el);
366
+ });
367
+ // Aggiorna primo/ultimo
368
+ this._first = this._focusableElements?.[0];
369
+ this._last = this._focusableElements[this._focusableElements.length - 1];
370
+ }
371
+ /** Sposta il focus sul primo elemento focusabile */
372
+ focusFirst() {
373
+ if (this._first)
374
+ this._first.focus();
375
+ }
376
+ /** Sposta il focus sull'ultimo elemento focusabile */
377
+ focusLast() {
378
+ if (this._last) {
379
+ this._last.focus();
380
+ }
381
+ }
382
+ /** Ritorna l'elemento attivo corrente, attraversando shadow DOM e slot */
383
+ static getActiveElement() {
384
+ let active = document.activeElement;
385
+ while (active && active.shadowRoot && active.shadowRoot.activeElement) {
386
+ active = active.shadowRoot.activeElement;
387
+ }
388
+ return active;
389
+ }
390
+ _handleTab(event) {
391
+ const activeElement = FocusTrapController.getActiveElement();
392
+ // Let native Tab behavior handle navigation inside open dropdown/megamenu.
393
+ // This allows entering and traversing internal menu items correctly.
394
+ if (activeElement) {
395
+ const managedHost = FocusTrapController.getManagedMenuHostAncestor(activeElement);
396
+ if (managedHost && managedHost.getAttribute('data-it-aria-expanded') === 'true') {
397
+ return;
398
+ }
399
+ }
400
+ // Ricalcola sempre al Tab: gli elementi slottati possono completare il render
401
+ // del proprio shadow DOM dopo l'attivazione iniziale del trap.
402
+ this.updateFocusableElements();
403
+ if (this._focusableElements.length === 0)
404
+ return; // Se è ancora vuoto, non bloccare il Tab
405
+ event.preventDefault();
406
+ let currentIndex = this._focusableElements.indexOf(activeElement);
407
+ if (currentIndex === -1 && activeElement) {
408
+ // 1. Walk shadow host chain (covers delegatesFocus custom elements)
409
+ let parent = activeElement.getRootNode()?.host;
410
+ while (parent && currentIndex === -1) {
411
+ currentIndex = this._focusableElements.indexOf(parent);
412
+ if (currentIndex === -1)
413
+ parent = parent.getRootNode()?.host;
414
+ }
415
+ }
416
+ if (currentIndex === -1) {
417
+ // 2. Composed path fallback: handles focus inside nested shadow/slotted
418
+ // content (e.g. anchors inside it-dropdown-item) by mapping the active
419
+ // target to the first focusable host found in the event path.
420
+ const composedPath = event.composedPath();
421
+ currentIndex = this._focusableElements.findIndex((candidate) => composedPath.includes(candidate));
422
+ }
423
+ if (currentIndex === -1 && activeElement) {
424
+ // 3. contains() fallback: handles focus inside an open dropdown/megamenu whose
425
+ // items live in light DOM (not shadow DOM), so the parent-walk above doesn't
426
+ // reach the host. Map to the host's index so Tab/Shift+Tab move to the
427
+ // correct adjacent element.
428
+ currentIndex = this._focusableElements.findIndex((candidate) => candidate.contains(activeElement));
429
+ }
430
+ if (currentIndex === -1) {
431
+ // 4. AT fallback: with some screen readers, document.activeElement and/or
432
+ // event target can be unreliable while navigating inside composite widgets.
433
+ // If a dropdown/megamenu is currently open, use its host index as anchor
434
+ // so forward/backward Tab continue from that position instead of wrapping.
435
+ currentIndex = this._focusableElements.findIndex((candidate) => candidate.matches('it-dropdown, it-megamenu') && candidate.getAttribute('data-it-aria-expanded') === 'true');
436
+ }
437
+ if (currentIndex === -1 && this._lastKnownFocusIndex >= 0) {
438
+ // 5. Last-known fallback: if assistive tech retargeting hides the active
439
+ // element for this key event, continue from the most recent resolved
440
+ // focus index captured via focusin.
441
+ currentIndex = Math.min(this._lastKnownFocusIndex, this._focusableElements.length - 1);
442
+ }
443
+ if (event.shiftKey) {
444
+ if (currentIndex <= 0)
445
+ FocusTrapController.focusCandidate(this._last);
446
+ else
447
+ FocusTrapController.focusCandidate(this._focusableElements[currentIndex - 1]);
448
+ }
449
+ else if (currentIndex === -1 || currentIndex >= this._focusableElements.length - 1)
450
+ FocusTrapController.focusCandidate(this._first);
451
+ else
452
+ FocusTrapController.focusCandidate(this._focusableElements[currentIndex + 1]);
453
+ }
454
+ _restoreFocus() {
455
+ const target = this._previousActiveElement;
456
+ this._previousActiveElement = null;
457
+ if (target && typeof target.focus === 'function' && document.contains(target)) {
458
+ // FIX Safari: blur the current element first so VoiceOver doesn't stay on the
459
+ // modal element while the accessibility tree processes the focus change.
460
+ FocusTrapController.getActiveElement()?.blur();
461
+ // FIX Safari/VoiceOver iOS: defer to the next macrotask so the accessibility
462
+ // tree has time to process the DOM mutation before announcing the restored element.
463
+ setTimeout(() => {
464
+ target.focus({ preventScroll: true });
465
+ }, 0);
466
+ }
467
+ }
468
+ }
469
+ FocusTrapController.FOCUSABLE_SELECTORS = [
470
+ 'a[href]',
471
+ 'button:not([disabled])',
472
+ 'textarea:not([disabled])',
473
+ 'input:not([disabled]):not([type="hidden"])',
474
+ 'select:not([disabled])',
475
+ '[tabindex]',
476
+ 'it-button:not([disabled])',
477
+ 'it-dropdown:not([disabled])',
478
+ 'it-megamenu:not([disabled])',
479
+ ].join(',');
480
+ FocusTrapController.NATIVE_FOCUSABLE_SELECTORS = [
481
+ 'a[href]',
482
+ 'button:not([disabled])',
483
+ 'textarea:not([disabled])',
484
+ 'input:not([disabled]):not([type="hidden"])',
485
+ 'select:not([disabled])',
486
+ '[tabindex]:not([tabindex="-1"])',
487
+ ].join(',');
488
+ FocusTrapController.MANAGED_HOST_SELECTORS = [
489
+ 'it-button:not([disabled])',
490
+ 'it-dropdown:not([disabled])',
491
+ 'it-megamenu:not([disabled])',
492
+ ].join(',');
493
+ FocusTrapController.MANAGED_MENU_HOST_SELECTORS = [
494
+ 'it-dropdown:not([disabled])',
495
+ 'it-megamenu:not([disabled])',
496
+ ].join(',');
497
+ //# 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":"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,CAAC;YAE9F,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO,GAAG,QAAQ,CAAC;gBACnB,SAAS;YACX,CAAC;YAED,MAAM,QAAQ,GAAS,OAAO,CAAC,WAAW,EAAE,CAAC;YAC7C,IAAI,QAAQ,YAAY,UAAU,EAAE,CAAC;gBACnC,MAAM,WAAW,GAAY,QAAQ,CAAC,IAAI,CAAC;gBAC3C,IAAI,WAAW,YAAY,WAAW,EAAE,CAAC;oBACvC,IAAI,WAAW,CAAC,OAAO,CAAC,mBAAmB,CAAC,sBAAsB,CAAC;wBAAE,OAAO,WAAW,CAAC;oBACxF,OAAO,GAAG,WAAW,CAAC;oBACtB,SAAS;gBACX,CAAC;YACH,CAAC;YAED,MAAM;QACR,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,MAAM,CAAC,mBAAmB,CAAC,OAAoB;QACrD,OAAO,mBAAmB,CAAC,sBAAsB,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;IACtE,CAAC;IAEO,MAAM,CAAC,0BAA0B,CAAC,OAAoB;QAC5D,IAAI,OAAO,GAAgB,OAAO,CAAC;QAEnC,OAAO,OAAO,EA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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 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"]}
@@ -14,15 +14,22 @@ export interface RovingTabindexConfig<T extends HTMLElement> {
14
14
  */
15
15
  wrap?: boolean;
16
16
  /**
17
- * Direction of navigation
17
+ * Direction of navigation. Può essere una stringa statica o una funzione
18
+ * che restituisce la direzione dinamicamente (utile quando la direzione
19
+ * dipende dallo stato del componente, es. orientamento verticale/orizzontale).
18
20
  * @default 'both'
19
21
  */
20
- direction?: 'horizontal' | 'vertical' | 'both';
22
+ direction?: 'horizontal' | 'vertical' | 'both' | (() => 'horizontal' | 'vertical' | 'both');
21
23
  /**
22
24
  * Whether to select items on focus (vs just focusing)
23
25
  * @default false
24
26
  */
25
27
  selectOnFocus?: boolean;
28
+ /**
29
+ * Whether Home/End should *activate* (select) the item in addition to focusing it.
30
+ * Default false to avoid changing downstream components; opt-in when needed.
31
+ */
32
+ selectOnHomeEnd?: boolean;
26
33
  /**
27
34
  * Custom logic to determine if an item should be skipped
28
35
  * @default (item) => item.hasAttribute('disabled')
@@ -1 +1 @@
1
- {"version":3,"file":"roving-tabindex-controller.d.ts","sourceRoot":"","sources":["../../../src/controllers/roving-tabindex-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,KAAK,CAAC;AAEjE,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,WAAW;IACzD;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC;IAEpB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,aAAa,GAAG,YAAY,GAAG,UAAU,KAAK,IAAI,CAAC;IAE/E;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;;OAGG;IACH,SAAS,CAAC,EAAE,YAAY,GAAG,UAAU,GAAG,MAAM,CAAC;IAE/C;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC;CACjC;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,wBAAwB,CAAC,CAAC,SAAS,WAAW,CAAE,YAAW,kBAAkB;IACxF,OAAO,CAAC,IAAI,CAAyB;IAErC,OAAO,CAAC,MAAM,CAKZ;gBAEU,IAAI,EAAE,sBAAsB,EAAE,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAazE,aAAa,IAAI,IAAI;IAKrB,gBAAgB,IAAI,IAAI;IAIxB;;;OAGG;IACH,gBAAgB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IA8B5C;;;;;OAKG;IACH,aAAa,CAAC,WAAW,EAAE,CAAC,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO;IAyE5D;;OAEG;IACH,OAAO,CAAC,YAAY;IAmBpB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAkB1B;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAUxB;;OAEG;IACH,UAAU,IAAI,IAAI;IASlB;;OAEG;IACH,SAAS,IAAI,IAAI;CAQlB"}
1
+ {"version":3,"file":"roving-tabindex-controller.d.ts","sourceRoot":"","sources":["../../../src/controllers/roving-tabindex-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,KAAK,CAAC;AAEjE,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,WAAW;IACzD;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC;IAEpB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,aAAa,GAAG,YAAY,GAAG,UAAU,KAAK,IAAI,CAAC;IAE/E;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;;;;OAKG;IACH,SAAS,CAAC,EAAE,YAAY,GAAG,UAAU,GAAG,MAAM,GAAG,CAAC,MAAM,YAAY,GAAG,UAAU,GAAG,MAAM,CAAC,CAAC;IAE5F;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC;CACjC;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,wBAAwB,CAAC,CAAC,SAAS,WAAW,CAAE,YAAW,kBAAkB;IACxF,OAAO,CAAC,IAAI,CAAyB;IAErC,OAAO,CAAC,MAAM,CAMZ;gBAEU,IAAI,EAAE,sBAAsB,EAAE,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAczE,aAAa,IAAI,IAAI;IAKrB,gBAAgB,IAAI,IAAI;IAIxB;;;OAGG;IACH,gBAAgB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IA8B5C;;;;;OAKG;IACH,aAAa,CAAC,WAAW,EAAE,CAAC,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO;IA+E5D;;OAEG;IACH,OAAO,CAAC,YAAY;IAmBpB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAkB1B;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAUxB;;OAEG;IACH,UAAU,IAAI,IAAI;IASlB;;OAEG;IACH,SAAS,IAAI,IAAI;CAQlB"}
@@ -19,6 +19,7 @@ export class RovingTabindexController {
19
19
  wrap: true,
20
20
  direction: 'both',
21
21
  selectOnFocus: false,
22
+ selectOnHomeEnd: false,
22
23
  skipItem: (item) => item.hasAttribute('disabled') || item.disabled === true,
23
24
  ...config,
24
25
  };
@@ -70,7 +71,7 @@ export class RovingTabindexController {
70
71
  * @returns true if the event was handled, false otherwise
71
72
  */
72
73
  handleKeydown(currentItem, event) {
73
- const { direction } = this.config;
74
+ const direction = typeof this.config.direction === 'function' ? this.config.direction() : this.config.direction;
74
75
  const { key } = event;
75
76
  // Determine if this key should be handled based on direction
76
77
  const isVertical = key === 'ArrowUp' || key === 'ArrowDown';
@@ -111,16 +112,21 @@ export class RovingTabindexController {
111
112
  nextIndex = this.getNextIndex(items, currentIndex, -1);
112
113
  }
113
114
  }
114
- // Skip disabled items
115
- nextIndex = this.findNextValidIndex(items, nextIndex, nextIndex > currentIndex ? 1 : -1);
115
+ // Skip disabled items — Home always searches forward, End always searches backward
116
+ // eslint-disable-next-line no-nested-ternary
117
+ const searchDirection = isHome ? 1 : isEnd ? -1 : nextIndex > currentIndex ? 1 : -1;
118
+ nextIndex = this.findNextValidIndex(items, nextIndex, searchDirection);
116
119
  if (nextIndex !== -1 && nextIndex !== currentIndex) {
117
120
  const nextItem = items[nextIndex];
118
121
  // Update tabindices
119
122
  this.updateTabindices(nextIndex);
120
123
  // Focus the next item
121
124
  nextItem.focus();
122
- // Optionally select/activate the item
123
- if (this.config.selectOnFocus && this.config.onSelect) {
125
+ // Optionally select/activate the item.
126
+ // Select when `selectOnFocus` is enabled, or when Home/End keys
127
+ // were used and the consumer explicitly opted in via `selectOnHomeEnd`.
128
+ const shouldSelect = this.config.selectOnFocus === true || ((isHome || isEnd) && this.config.selectOnHomeEnd === true);
129
+ if (shouldSelect && this.config.onSelect) {
124
130
  this.config.onSelect(nextItem, event);
125
131
  }
126
132
  return true;