@italia/modal 1.0.0-alpha.8 → 1.0.0-beta.0

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.
@@ -37,14 +37,80 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
37
37
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
38
38
  };
39
39
 
40
+ const ARIA_IDREF_ATTRIBUTES = new Map([
41
+ ['aria-activedescendant', 'ariaActivedescendantElement'],
42
+ ['aria-controls', 'ariaControlsElements'],
43
+ ['aria-describedby', 'ariaDescribedByElements'],
44
+ ['aria-details', 'ariaDetailsElements'],
45
+ ['aria-errormessage', 'ariaErrormessageElements'],
46
+ ['aria-flowto', 'ariaFlowtoElements'],
47
+ ['aria-labelledby', 'ariaLabelledByElements'],
48
+ ['aria-owns', 'ariaOwnsElements'],
49
+ ]);
50
+ function resolveAriaIdRefs(element, value) {
51
+ const ids = value
52
+ .trim()
53
+ .split(/\s+/)
54
+ .filter((id) => id.length > 0);
55
+ if (ids.length === 0)
56
+ return null;
57
+ const root = element.getRootNode();
58
+ let resolvedElements = [];
59
+ if (root instanceof ShadowRoot) {
60
+ resolvedElements = ids.map((id) => root.getElementById(id));
61
+ }
62
+ else if (root instanceof Document) {
63
+ resolvedElements = ids.map((id) => root.getElementById(id));
64
+ }
65
+ else {
66
+ resolvedElements = ids.map((id) => document.getElementById(id));
67
+ }
68
+ if (resolvedElements.filter((el) => el !== null).length === 0) {
69
+ resolvedElements = ids.map((id) => document.getElementById(id));
70
+ }
71
+ const validElements = resolvedElements.filter((el) => el !== null);
72
+ return validElements.length === ids.length ? validElements : null;
73
+ }
74
+ function setInternalsProperty(el, name, resolvedElements) {
75
+ if (name === 'aria-activedescendant') {
76
+ const [firstElement] = resolvedElements;
77
+ // eslint-disable-next-line no-param-reassign
78
+ el[name] = firstElement;
79
+ }
80
+ else {
81
+ // eslint-disable-next-line no-param-reassign
82
+ el[name] = resolvedElements;
83
+ }
84
+ }
40
85
  class SetAttributesDirective extends Directive {
41
86
  update(part, [attributes]) {
42
87
  const el = part.element;
88
+ const internals = el.internals ?? null;
43
89
  for (const [name, value] of Object.entries(attributes)) {
44
- if (value != null)
45
- el.setAttribute(name, value);
46
- else
90
+ if (value == null) {
47
91
  el.removeAttribute(name);
92
+ }
93
+ else {
94
+ const internalsPropertyName = ARIA_IDREF_ATTRIBUTES.get(name);
95
+ if (internalsPropertyName) {
96
+ const resolvedElements = resolveAriaIdRefs(el, String(value));
97
+ if (resolvedElements) {
98
+ if (internals) {
99
+ // Set on ElementInternals
100
+ setInternalsProperty(internals, internalsPropertyName, resolvedElements);
101
+ }
102
+ else {
103
+ // Set internals property on shadowdom item
104
+ el.setAttribute(name, String(value));
105
+ setInternalsProperty(el, internalsPropertyName, resolvedElements);
106
+ }
107
+ }
108
+ }
109
+ else {
110
+ // Non-ARIA IDREF attributes: set normally
111
+ el.setAttribute(name, String(value));
112
+ }
113
+ }
48
114
  }
49
115
  return null;
50
116
  }
@@ -115,7 +181,9 @@ function registerTranslation(...translation) {
115
181
  });
116
182
  update();
117
183
  }
118
- window.registerTranslation = registerTranslation;
184
+ if (typeof window !== 'undefined') {
185
+ window.registerTranslation = registerTranslation;
186
+ }
119
187
  /**
120
188
  * Localize Reactive Controller for components built with Lit
121
189
  *
@@ -410,18 +478,206 @@ class BaseComponent extends LitElement {
410
478
  // generate internal _id
411
479
  const prefix = this.id?.length > 0 ? this.id : this.tagName.toLowerCase();
412
480
  this._id = this.generateId(prefix);
481
+ this.ariaAttributesObserver = new MutationObserver((mutations) => {
482
+ const shouldUpdate = mutations.some((mutation) => {
483
+ if (mutation.type !== 'attributes' || !mutation.attributeName) {
484
+ return false;
485
+ }
486
+ return mutation.attributeName === 'it-role' || mutation.attributeName.startsWith('it-aria-');
487
+ });
488
+ if (shouldUpdate) {
489
+ this.requestUpdate();
490
+ }
491
+ });
492
+ this.ariaAttributesObserver.observe(this, {
493
+ attributes: true,
494
+ attributeOldValue: true,
495
+ });
496
+ }
497
+ disconnectedCallback() {
498
+ this.ariaAttributesObserver?.disconnect();
499
+ this.ariaAttributesObserver = undefined;
500
+ super.disconnectedCallback();
413
501
  }
414
502
  }
415
503
  const BaseLocalizedComponent = LocalizeMixin(BaseComponent);
416
504
 
417
505
  /**
418
- * Controller per gestire il focus trap all'interno di un elemento.
419
- * Implementa le linee guida WAI-ARIA per i dialog modali.
506
+ * Safari/VoiceOver iOS workarounds catalogue — why timers exist here:
420
507
  *
421
-
422
- * ```
508
+ * 1. `activate()` rAF + setTimeout(50): Safari does not reliably update the VoiceOver
509
+ * accessibility tree synchronously. rAF ensures the element is painted before we
510
+ * attempt to focus it. setTimeout(50) yields 50ms so VoiceOver can settle its
511
+ * accessibility tree before announcing the newly focused element.
512
+ * Empirically, VoiceOver iOS needs 100–300ms; the animated path in it-modal already
513
+ * provides ~316ms naturally via animation.finished, so the 50ms here only truly
514
+ * matters for the no-animation / prefers-reduced-motion path.
515
+ *
516
+ * 2. `_restoreFocus()` setTimeout(0): Same settle reason on close. The caller
517
+ * (it-modal finishHide) adds a belt-and-suspenders 20ms setTimeout; _restoreFocus
518
+ * is skipped via { skipFocusRestore: true } in that case to avoid double-focus.
519
+ *
520
+ * 3. `activate()` iOS body-focus fallback: On iOS Safari, tapping a button does not
521
+ * reliably move document.activeElement away from body. We fall back to getTrigger()
522
+ * so _previousActiveElement is always a real DOM element to restore focus to on close.
523
+ *
524
+ * There is no WebKit/Safari API to detect when VoiceOver has settled its accessibility
525
+ * tree. setTimeout-based workarounds are the same pattern used by Bootstrap 5, the
526
+ * focus-trap npm package, and a11y-dialog.
423
527
  */
424
528
  class FocusTrapController {
529
+ static getManagedHostAncestor(element) {
530
+ let current = element;
531
+ while (current) {
532
+ const parentEl = current instanceof HTMLElement ? current.parentElement : null;
533
+ if (parentEl && parentEl.matches(FocusTrapController.MANAGED_HOST_SELECTORS))
534
+ return parentEl;
535
+ if (parentEl) {
536
+ current = parentEl;
537
+ continue;
538
+ }
539
+ const rootNode = current.getRootNode();
540
+ if (rootNode instanceof ShadowRoot) {
541
+ const hostElement = rootNode.host;
542
+ if (hostElement instanceof HTMLElement) {
543
+ if (hostElement.matches(FocusTrapController.MANAGED_HOST_SELECTORS))
544
+ return hostElement;
545
+ current = hostElement;
546
+ continue;
547
+ }
548
+ }
549
+ break;
550
+ }
551
+ return null;
552
+ }
553
+ static isInsideManagedHost(element) {
554
+ return FocusTrapController.getManagedHostAncestor(element) !== null;
555
+ }
556
+ static getManagedMenuHostAncestor(element) {
557
+ let current = element;
558
+ while (current) {
559
+ const parentEl = current instanceof HTMLElement ? current.parentElement : null;
560
+ if (parentEl && parentEl.matches(FocusTrapController.MANAGED_MENU_HOST_SELECTORS))
561
+ return parentEl;
562
+ if (parentEl) {
563
+ current = parentEl;
564
+ continue;
565
+ }
566
+ const rootNode = current.getRootNode();
567
+ if (rootNode instanceof ShadowRoot) {
568
+ const hostElement = rootNode.host;
569
+ if (hostElement instanceof HTMLElement) {
570
+ if (hostElement.matches(FocusTrapController.MANAGED_MENU_HOST_SELECTORS))
571
+ return hostElement;
572
+ current = hostElement;
573
+ continue;
574
+ }
575
+ }
576
+ break;
577
+ }
578
+ return null;
579
+ }
580
+ static collectFocusableCandidates(root, candidates, trigger, visited) {
581
+ const rootAsNode = root;
582
+ if (visited.has(rootAsNode))
583
+ return;
584
+ visited.add(rootAsNode);
585
+ const elements = Array.from(root.querySelectorAll('*'));
586
+ elements.forEach((el) => {
587
+ if (el === trigger)
588
+ return;
589
+ // Keep custom host components as single tab stops: their internal light/shadow
590
+ // descendants must not appear as separate trap candidates.
591
+ if (FocusTrapController.isInsideManagedHost(el))
592
+ return;
593
+ if (el.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {
594
+ candidates.push(el);
595
+ // Stop here: focusCandidate() handles delegation to the inner focusable.
596
+ // Prevent recursion into this element's shadow DOM so inner buttons/triggers
597
+ // are not added as separate tab stops.
598
+ if (el.shadowRoot)
599
+ visited.add(el.shadowRoot);
600
+ return;
601
+ }
602
+ if (el instanceof HTMLSlotElement) {
603
+ el.assignedElements({ flatten: true }).forEach((assigned) => {
604
+ if (!(assigned instanceof HTMLElement) || assigned === trigger)
605
+ return;
606
+ if (assigned.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {
607
+ candidates.push(assigned);
608
+ // Same rule: don't recurse into a focusable element.
609
+ if (assigned.shadowRoot)
610
+ visited.add(assigned.shadowRoot);
611
+ return;
612
+ }
613
+ FocusTrapController.collectFocusableCandidates(assigned, candidates, trigger, visited);
614
+ if (assigned.shadowRoot) {
615
+ FocusTrapController.collectFocusableCandidates(assigned.shadowRoot, candidates, trigger, visited);
616
+ }
617
+ });
618
+ return;
619
+ }
620
+ if (el.shadowRoot) {
621
+ FocusTrapController.collectFocusableCandidates(el.shadowRoot, candidates, trigger, visited);
622
+ }
623
+ });
624
+ }
625
+ static getFirstFocusableInShadow(host) {
626
+ const visited = new Set();
627
+ const walk = (root) => {
628
+ const rootAsNode = root;
629
+ if (visited.has(rootAsNode))
630
+ return null;
631
+ visited.add(rootAsNode);
632
+ const direct = Array.from(root.querySelectorAll(FocusTrapController.NATIVE_FOCUSABLE_SELECTORS));
633
+ const firstDirect = direct.find((el) => FocusTrapController.isFocusable(el));
634
+ if (firstDirect)
635
+ return firstDirect;
636
+ const all = Array.from(root.querySelectorAll('*'));
637
+ for (const el of all) {
638
+ if (el instanceof HTMLSlotElement) {
639
+ const assigned = el.assignedElements({ flatten: true });
640
+ for (const assignedEl of assigned) {
641
+ if (!(assignedEl instanceof HTMLElement))
642
+ continue;
643
+ if (assignedEl.matches(FocusTrapController.NATIVE_FOCUSABLE_SELECTORS)) {
644
+ if (FocusTrapController.isFocusable(assignedEl))
645
+ return assignedEl;
646
+ }
647
+ const nestedAssigned = walk(assignedEl);
648
+ if (nestedAssigned)
649
+ return nestedAssigned;
650
+ if (assignedEl.shadowRoot) {
651
+ const nestedAssignedShadow = walk(assignedEl.shadowRoot);
652
+ if (nestedAssignedShadow)
653
+ return nestedAssignedShadow;
654
+ }
655
+ }
656
+ }
657
+ if (el.shadowRoot) {
658
+ const nested = walk(el.shadowRoot);
659
+ if (nested)
660
+ return nested;
661
+ }
662
+ }
663
+ return null;
664
+ };
665
+ if (!host.shadowRoot)
666
+ return null;
667
+ return walk(host.shadowRoot);
668
+ }
669
+ static focusCandidate(target) {
670
+ if (!target)
671
+ return;
672
+ if (target.tagName.toLowerCase().startsWith('it-')) {
673
+ const innerFocusable = FocusTrapController.getFirstFocusableInShadow(target);
674
+ if (innerFocusable) {
675
+ innerFocusable.focus({ preventScroll: true });
676
+ return;
677
+ }
678
+ }
679
+ target.focus({ preventScroll: true });
680
+ }
425
681
  /**
426
682
  * Verifica se un elemento è effettivamente focusabile e tabbabile.
427
683
  * Elementi con tabindex="-1" sono focusabili programmaticamente ma non tabbabili.
@@ -429,39 +685,22 @@ class FocusTrapController {
429
685
  static isFocusable(el) {
430
686
  if (typeof el.focus !== 'function')
431
687
  return false;
432
- // Escludi elementi disabilitati
433
- if (el.hasAttribute('disabled'))
688
+ if (el.hasAttribute('disabled') || el.hasAttribute('inert') || el.hasAttribute('it-inert'))
434
689
  return false;
435
- // Escludi elementi con tabindex negativo (focusabili programmaticamente ma non tabbabili)
436
690
  const tabindex = el.getAttribute('tabindex');
437
- if (tabindex && parseInt(tabindex, 10) < 0) {
691
+ if (tabindex && parseInt(tabindex, 10) < 0)
438
692
  return false;
439
- }
440
- // Per custom elements (it-*), controlla anche il loro tabindex
441
693
  if (el.tagName.toLowerCase().startsWith('it-')) {
442
- // Se ha tabindex esplicito negativo, non è tabbabile
443
- if (tabindex && parseInt(tabindex, 10) < 0) {
694
+ if (tabindex && parseInt(tabindex, 10) < 0)
444
695
  return false;
445
- }
446
696
  return true;
447
697
  }
448
- // Per elementi standard, controlliamo anche visibilità in modo robusto.
449
- // Alcuni elementi (es. inline anchors, elementi dentro container positionati) possono
450
- // avere offsetParent === null pur essendo visibili/focusabili. Usiamo quindi getClientRects
451
- // e computedStyle come controllo più affidabile.
698
+ // Fix Race Condition Safari: durante l'apertura non fidarti di getClientRects o opacità
452
699
  try {
453
- // Se non ci sono bounding rects, probabilmente non è visibile
454
- if (el.getClientRects()?.length === 0)
455
- return false;
456
700
  const style = window.getComputedStyle(el);
457
- if (!style)
458
- return false;
459
- if (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0')
460
- return false;
461
- // Altrimenti consideriamo l'elemento focusabile
462
- return true;
701
+ return style && style.display !== 'none' && style.visibility !== 'hidden';
463
702
  }
464
- catch (e) {
703
+ catch {
465
704
  return false;
466
705
  }
467
706
  }
@@ -470,6 +709,13 @@ class FocusTrapController {
470
709
  this._isActive = false;
471
710
  this._previousActiveElement = null;
472
711
  this._focusableElements = [];
712
+ /** Last known index resolved from real focusin events inside the trap.
713
+ * Used as a fallback when assistive tech retargeting makes activeElement
714
+ * temporarily unmappable during Tab navigation. */
715
+ this._lastKnownFocusIndex = -1;
716
+ /** Timer ID for the focus call scheduled inside activate(). Cancelled by deactivate()
717
+ * to prevent focus firing after the trap has been torn down (fast open/close, unmount). */
718
+ this._pendingFocusTimer = null;
473
719
  this._handleKeyDown = (event) => {
474
720
  if (!this._isActive)
475
721
  return;
@@ -485,19 +731,38 @@ class FocusTrapController {
485
731
  break;
486
732
  }
487
733
  };
734
+ this._handleFocusIn = (event) => {
735
+ if (!this._isActive)
736
+ return;
737
+ if (this._focusableElements.length === 0) {
738
+ this.updateFocusableElements();
739
+ if (this._focusableElements.length === 0)
740
+ return;
741
+ }
742
+ const path = event.composedPath();
743
+ let index = this._focusableElements.findIndex((candidate) => path.includes(candidate));
744
+ if (index === -1) {
745
+ const target = path[0];
746
+ if (target instanceof HTMLElement) {
747
+ index = this._focusableElements.indexOf(target);
748
+ }
749
+ }
750
+ if (index === -1) {
751
+ const active = FocusTrapController.getActiveElement();
752
+ if (active) {
753
+ index = this._focusableElements.findIndex((candidate) => candidate.contains(active));
754
+ }
755
+ }
756
+ if (index !== -1) {
757
+ this._lastKnownFocusIndex = index;
758
+ }
759
+ };
488
760
  this.host = host;
489
761
  this.config = config;
490
762
  this.host.addController(this);
491
763
  }
492
- // eslint-disable-next-line class-methods-use-this
493
764
  hostConnected() {
494
- // Controller ready
495
- // Set up our MutationObserver
496
- const observerOptions = {
497
- childList: true,
498
- attributes: true,
499
- subtree: true,
500
- };
765
+ const observerOptions = { childList: true, attributes: true, subtree: true };
501
766
  this.observer = new MutationObserver(this.updateFocusableElements.bind(this));
502
767
  this.observer.observe(this.host, observerOptions);
503
768
  }
@@ -508,37 +773,62 @@ class FocusTrapController {
508
773
  this.observer = null;
509
774
  }
510
775
  }
511
- /** Indica se il focus trap è attivo */
512
776
  get isActive() {
513
777
  return this._isActive;
514
778
  }
515
- /**
516
- * Attiva il focus trap.
517
- * Salva l'elemento attivo corrente e attiva i listener.
518
- * NOTA: chiamare updateFocusableElements() e focusFirst() separatamente quando necessario.
519
- */
520
779
  activate() {
521
780
  if (this._isActive)
522
781
  return;
523
782
  this._isActive = true;
524
- this._previousActiveElement = FocusTrapController.getActiveElement();
525
- this.host.addEventListener('keydown', this._handleKeyDown);
783
+ // FIX iOS: Safari non dà focus al tap. Se activeElement è body, salviamo il trigger della config.
784
+ const currentActive = FocusTrapController.getActiveElement();
785
+ this._previousActiveElement =
786
+ !currentActive || currentActive === document.body ? this.config.getTrigger() : currentActive;
787
+ // Usa document capture: cattura Tab/Escape prima di qualsiasi handler,
788
+ // indipendentemente da shadow DOM, delegatesFocus e slot retargeting.
789
+ document.addEventListener('keydown', this._handleKeyDown, true);
790
+ document.addEventListener('focusin', this._handleFocusIn, true);
526
791
  this.updateFocusableElements();
527
- if (typeof this.focusInitial === 'function')
528
- this.focusInitial();
529
- else
530
- this.focusFirst();
792
+ this._lastKnownFocusIndex = -1;
793
+ // FIX Safari: trick engine
794
+ // Diamo al browser un istante per processare il ricalcolo del layout
795
+ requestAnimationFrame(() => {
796
+ if (this.config.initialFocus) {
797
+ const el = this.config.initialFocus();
798
+ if (el) {
799
+ // 50ms gives VoiceOver iOS time to settle its accessibility tree before
800
+ // announcing the focused element. See class-level comment for details.
801
+ this._pendingFocusTimer = setTimeout(() => {
802
+ this._pendingFocusTimer = null;
803
+ el.focus({ preventScroll: true });
804
+ }, 50);
805
+ }
806
+ }
807
+ else {
808
+ // eslint-disable-next-line no-console
809
+ console.warn("FocusTrap: missing 'initialFocus' callback, provide one");
810
+ }
811
+ });
531
812
  }
532
- /**
533
- * Disattiva il focus trap.
534
- * Ripristina il focus all'elemento precedentemente attivo.
535
- */
536
- deactivate() {
813
+ deactivate(options) {
537
814
  if (!this._isActive)
538
815
  return;
816
+ // Cancel any in-flight focus timer so it cannot fire after the trap is torn down
817
+ // (e.g. fast open/close cycle, component unmounted while opening).
818
+ if (this._pendingFocusTimer !== null) {
819
+ clearTimeout(this._pendingFocusTimer);
820
+ this._pendingFocusTimer = null;
821
+ }
539
822
  this._isActive = false;
540
- this.host.removeEventListener('keydown', this._handleKeyDown);
541
- this._restoreFocus();
823
+ document.removeEventListener('keydown', this._handleKeyDown, true);
824
+ document.removeEventListener('focusin', this._handleFocusIn, true);
825
+ this._lastKnownFocusIndex = -1;
826
+ if (!options?.skipFocusRestore) {
827
+ this._restoreFocus();
828
+ }
829
+ else {
830
+ this._previousActiveElement = null;
831
+ }
542
832
  }
543
833
  /**
544
834
  * Aggiorna la lista degli elementi focusabili.
@@ -554,25 +844,21 @@ class FocusTrapController {
554
844
  return;
555
845
  }
556
846
  const candidates = [];
557
- // Tutti gli elementi focusable direttamente nel container
558
- const direct = Array.from(container.querySelectorAll(FocusTrapController.FOCUSABLE_SELECTORS));
559
- candidates.push(...direct);
560
- // Tutti gli elementi slottati
561
- const slots = Array.from(container.querySelectorAll('slot'));
562
- slots.forEach((slot) => {
563
- slot.assignedElements({ flatten: true }).forEach((el) => {
564
- if (!(el instanceof HTMLElement))
565
- return;
566
- if (el === trigger) {
567
- return;
568
- }
569
- // focusable diretto
570
- if (el.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {
571
- candidates.push(el);
572
- }
573
- // nested focusable dentro l'elemento assegnato
574
- Array.from(el.querySelectorAll(FocusTrapController.FOCUSABLE_SELECTORS)).forEach((nested) => candidates.push(nested));
575
- });
847
+ FocusTrapController.collectFocusableCandidates(container, candidates, trigger, new Set());
848
+ // Include anche i figli light DOM dell'host (es. contenuti slottati della modale)
849
+ Array.from(this.host.children).forEach((child) => {
850
+ if (!(child instanceof HTMLElement) || child === trigger)
851
+ return;
852
+ if (child.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {
853
+ candidates.push(child);
854
+ // Don't recurse: same stop-on-focusable rule.
855
+ return;
856
+ }
857
+ const childVisited = new Set();
858
+ FocusTrapController.collectFocusableCandidates(child, candidates, trigger, childVisited);
859
+ if (child.shadowRoot) {
860
+ FocusTrapController.collectFocusableCandidates(child.shadowRoot, candidates, trigger, childVisited);
861
+ }
576
862
  });
577
863
  // Filtra solo elementi veramente focusabili e rimuovi duplicati
578
864
  this._focusableElements = Array.from(new Set(candidates)).filter((el) => {
@@ -587,9 +873,8 @@ class FocusTrapController {
587
873
  }
588
874
  /** Sposta il focus sul primo elemento focusabile */
589
875
  focusFirst() {
590
- if (this._first) {
876
+ if (this._first)
591
877
  this._first.focus();
592
- }
593
878
  }
594
879
  /** Sposta il focus sull'ultimo elemento focusabile */
595
880
  focusLast() {
@@ -605,70 +890,83 @@ class FocusTrapController {
605
890
  }
606
891
  return active;
607
892
  }
608
- /**
609
- * Metti a fuoco l'elemento iniziale specificato nella config, se presente.
610
- * Se non è fornito, fallback sul primo elemento tabbabile.
611
- */
612
- focusInitial() {
613
- if (this.config.initialFocus) {
614
- const el = this.config.initialFocus();
615
- if (el && typeof el.focus === 'function') {
616
- el.focus();
893
+ _handleTab(event) {
894
+ const activeElement = FocusTrapController.getActiveElement();
895
+ // Let native Tab behavior handle navigation inside open dropdown/megamenu.
896
+ // This allows entering and traversing internal menu items correctly.
897
+ if (activeElement) {
898
+ const managedHost = FocusTrapController.getManagedMenuHostAncestor(activeElement);
899
+ if (managedHost && managedHost.getAttribute('data-it-aria-expanded') === 'true') {
617
900
  return;
618
901
  }
619
902
  }
620
- this.focusFirst();
621
- }
622
- _handleTab(event) {
623
- if (this._focusableElements.length === 0) {
624
- event.preventDefault();
625
- return;
626
- }
627
- // SEMPRE previeni il default - gestiamo noi la navigazione
903
+ // Ricalcola sempre al Tab: gli elementi slottati possono completare il render
904
+ // del proprio shadow DOM dopo l'attivazione iniziale del trap.
905
+ this.updateFocusableElements();
906
+ if (this._focusableElements.length === 0)
907
+ return; // Se è ancora vuoto, non bloccare il Tab
628
908
  event.preventDefault();
629
- const firstElement = this._first;
630
- const lastElement = this._last;
631
- const activeElement = FocusTrapController.getActiveElement();
632
- // Trova l'indice dell'elemento attivo
633
- // Se activeElement è dentro uno shadow DOM di un custom element,
634
- // cerca il custom element host nella lista
635
909
  let currentIndex = this._focusableElements.indexOf(activeElement);
636
- // Se non trovato, potrebbe essere un elemento interno ad un custom element
637
910
  if (currentIndex === -1 && activeElement) {
638
- // Risali attraverso gli shadow host
911
+ // 1. Walk shadow host chain (covers delegatesFocus custom elements)
639
912
  let parent = activeElement.getRootNode()?.host;
640
913
  while (parent && currentIndex === -1) {
641
914
  currentIndex = this._focusableElements.indexOf(parent);
642
- if (currentIndex === -1) {
915
+ if (currentIndex === -1)
643
916
  parent = parent.getRootNode()?.host;
644
- }
645
917
  }
646
918
  }
647
- if (event.shiftKey) {
648
- // Shift + Tab: vai al precedente
649
- if (currentIndex <= 0) {
650
- // Se sei sul primo o non sei nella lista, vai all'ultimo
651
- lastElement?.focus();
652
- }
653
- else {
654
- // Vai al precedente
655
- this._focusableElements[currentIndex - 1]?.focus();
656
- }
919
+ if (currentIndex === -1) {
920
+ // 2. Composed path fallback: handles focus inside nested shadow/slotted
921
+ // content (e.g. anchors inside it-dropdown-item) by mapping the active
922
+ // target to the first focusable host found in the event path.
923
+ const composedPath = event.composedPath();
924
+ currentIndex = this._focusableElements.findIndex((candidate) => composedPath.includes(candidate));
657
925
  }
658
- else if (currentIndex === -1 || currentIndex >= this._focusableElements.length - 1) {
659
- // Tab: se non sei nella lista o sei sull'ultimo, vai al primo
660
- firstElement?.focus();
926
+ if (currentIndex === -1 && activeElement) {
927
+ // 3. contains() fallback: handles focus inside an open dropdown/megamenu whose
928
+ // items live in light DOM (not shadow DOM), so the parent-walk above doesn't
929
+ // reach the host. Map to the host's index so Tab/Shift+Tab move to the
930
+ // correct adjacent element.
931
+ currentIndex = this._focusableElements.findIndex((candidate) => candidate.contains(activeElement));
661
932
  }
662
- else {
663
- // Vai al successivo
664
- this._focusableElements[currentIndex + 1]?.focus();
933
+ if (currentIndex === -1) {
934
+ // 4. AT fallback: with some screen readers, document.activeElement and/or
935
+ // event target can be unreliable while navigating inside composite widgets.
936
+ // If a dropdown/megamenu is currently open, use its host index as anchor
937
+ // so forward/backward Tab continue from that position instead of wrapping.
938
+ currentIndex = this._focusableElements.findIndex((candidate) => candidate.matches('it-dropdown, it-megamenu') && candidate.getAttribute('data-it-aria-expanded') === 'true');
665
939
  }
940
+ if (currentIndex === -1 && this._lastKnownFocusIndex >= 0) {
941
+ // 5. Last-known fallback: if assistive tech retargeting hides the active
942
+ // element for this key event, continue from the most recent resolved
943
+ // focus index captured via focusin.
944
+ currentIndex = Math.min(this._lastKnownFocusIndex, this._focusableElements.length - 1);
945
+ }
946
+ if (event.shiftKey) {
947
+ if (currentIndex <= 0)
948
+ FocusTrapController.focusCandidate(this._last);
949
+ else
950
+ FocusTrapController.focusCandidate(this._focusableElements[currentIndex - 1]);
951
+ }
952
+ else if (currentIndex === -1 || currentIndex >= this._focusableElements.length - 1)
953
+ FocusTrapController.focusCandidate(this._first);
954
+ else
955
+ FocusTrapController.focusCandidate(this._focusableElements[currentIndex + 1]);
666
956
  }
667
957
  _restoreFocus() {
668
- if (this._previousActiveElement && typeof this._previousActiveElement.focus === 'function') {
669
- this._previousActiveElement.focus();
670
- }
958
+ const target = this._previousActiveElement;
671
959
  this._previousActiveElement = null;
960
+ if (target && typeof target.focus === 'function' && document.contains(target)) {
961
+ // FIX Safari: blur the current element first so VoiceOver doesn't stay on the
962
+ // modal element while the accessibility tree processes the focus change.
963
+ FocusTrapController.getActiveElement()?.blur();
964
+ // FIX Safari/VoiceOver iOS: defer to the next macrotask so the accessibility
965
+ // tree has time to process the DOM mutation before announcing the restored element.
966
+ setTimeout(() => {
967
+ target.focus({ preventScroll: true });
968
+ }, 0);
969
+ }
672
970
  }
673
971
  }
674
972
  FocusTrapController.FOCUSABLE_SELECTORS = [
@@ -678,9 +976,26 @@ FocusTrapController.FOCUSABLE_SELECTORS = [
678
976
  'input:not([disabled]):not([type="hidden"])',
679
977
  'select:not([disabled])',
680
978
  '[tabindex]',
681
- // '[role="dialog"]',
682
- // Custom elements focusabili
683
979
  'it-button:not([disabled])',
980
+ 'it-dropdown:not([disabled])',
981
+ 'it-megamenu:not([disabled])',
982
+ ].join(',');
983
+ FocusTrapController.NATIVE_FOCUSABLE_SELECTORS = [
984
+ 'a[href]',
985
+ 'button:not([disabled])',
986
+ 'textarea:not([disabled])',
987
+ 'input:not([disabled]):not([type="hidden"])',
988
+ 'select:not([disabled])',
989
+ '[tabindex]:not([tabindex="-1"])',
990
+ ].join(',');
991
+ FocusTrapController.MANAGED_HOST_SELECTORS = [
992
+ 'it-button:not([disabled])',
993
+ 'it-dropdown:not([disabled])',
994
+ 'it-megamenu:not([disabled])',
995
+ ].join(',');
996
+ FocusTrapController.MANAGED_MENU_HOST_SELECTORS = [
997
+ 'it-dropdown:not([disabled])',
998
+ 'it-megamenu:not([disabled])',
684
999
  ].join(',');
685
1000
 
686
1001
  //
@@ -742,6 +1057,14 @@ class FormControlController {
742
1057
  case 'it-toggle-group':
743
1058
  // non settare valori in formData, perchè ogni singola checkbox setta il suo valore
744
1059
  break;
1060
+ case 'it-upload':
1061
+ // value is File[] — append each File object directly (not as string)
1062
+ if (Array.isArray(value)) {
1063
+ value.forEach((file) => {
1064
+ event.formData.append(name, file);
1065
+ });
1066
+ }
1067
+ break;
745
1068
  default:
746
1069
  if (Array.isArray(value)) {
747
1070
  value.forEach((val) => {
@@ -1103,7 +1426,7 @@ class FormControl extends BaseLocalizedComponent {
1103
1426
  });
1104
1427
  // TODO: verificare se serve davvero con il fatto che usiamo form-controller
1105
1428
  // static formAssociated = true;
1106
- // @property()
1429
+ // @property()
1107
1430
  // internals = this.attachInternals();
1108
1431
  this._touched = false;
1109
1432
  /** The name of the input, submitted as a name/value pair with form data. */
@@ -1347,6 +1670,49 @@ __decorate([
1347
1670
  __metadata("design:type", Object)
1348
1671
  ], FormControl.prototype, "validationMessage", void 0);
1349
1672
 
1673
+ /**
1674
+ * Dispatches a cancelable custom event and runs the provided default action
1675
+ * only if the consumer did not call `event.preventDefault()`.
1676
+ *
1677
+ * This is the shared convention used across components (Tabs, Modal, Chip, Alert,
1678
+ * Forward, Back) to provide a sensible default JavaScript behavior out of the box
1679
+ * while letting consumers intercept and override it. Notification deliberately does
1680
+ * NOT use this: its show/close are always caller-initiated (no default markup-driven
1681
+ * trigger to override), so there was no real use case for blocking them — see
1682
+ * it-notification.ts for the plain (non-cancelable) events it fires instead.
1683
+ *
1684
+ * ```js
1685
+ * el.addEventListener('it-alert-close', (e) => {
1686
+ * e.preventDefault(); // block the default removal
1687
+ * fetchConfirmation().then((ok) => { // async logic runs after prevention
1688
+ * if (ok) e.target.close();
1689
+ * });
1690
+ * });
1691
+ * ```
1692
+ *
1693
+ * Note: `preventDefault()` must be called synchronously inside the listener.
1694
+ * Async code can run afterward; call the component's public method when ready.
1695
+ *
1696
+ * @param host the element dispatching the event
1697
+ * @param name the event name (kebab-case, `it-` prefixed)
1698
+ * @param detail the event `detail` payload
1699
+ * @param defaultAction the behavior executed when the event is not prevented
1700
+ * @returns the dispatched event (inspect `defaultPrevented` if needed)
1701
+ */
1702
+ function dispatchCancelable(host, name, detail, defaultAction) {
1703
+ const event = new CustomEvent(name, {
1704
+ bubbles: true,
1705
+ composed: true,
1706
+ cancelable: true,
1707
+ detail,
1708
+ });
1709
+ host.dispatchEvent(event);
1710
+ if (!event.defaultPrevented) {
1711
+ defaultAction();
1712
+ }
1713
+ return event;
1714
+ }
1715
+
1350
1716
  class WindowManager {
1351
1717
  static init() {
1352
1718
  if (this.initialized)
@@ -1429,110 +1795,11 @@ if (typeof window !== 'undefined') {
1429
1795
  window._itAnalytics = window._itAnalytics || {};
1430
1796
  window._itAnalytics = {
1431
1797
  ...window._itAnalytics,
1432
- version: '1.0.0-alpha.8',
1798
+ version: '1.0.0-beta.0',
1433
1799
  };
1434
1800
  }
1435
1801
 
1436
1802
  var styles = css`@charset "UTF-8";
1437
- /***************************** 1 ****************************************/
1438
- /***************************** 2 ****************************************/
1439
- /***************************** 1 ****************************************/
1440
- /***************************** 2 ****************************************/
1441
- /***************************** 1 ****************************************/
1442
- /***************************** 2 ****************************************/
1443
- /***************************** 3 ****************************************/
1444
- /***************************** 1 ****************************************/
1445
- /***************************** 2 ****************************************/
1446
- /***************************** 3 ****************************************/
1447
- /***************************** NEUTRAL 1 ****************************************/
1448
- /***************************** NEUTRAL 2 ****************************************/
1449
- /***************************** NEUTRAL 2 / 3 ****************************************/
1450
- .d-none {
1451
- display: none !important;
1452
- }
1453
-
1454
- .d-block {
1455
- display: block !important;
1456
- }
1457
-
1458
- .d-flex {
1459
- display: flex !important;
1460
- }
1461
-
1462
- .overflow-auto {
1463
- overflow: auto !important;
1464
- }
1465
-
1466
- .overflow-hidden {
1467
- overflow: hidden !important;
1468
- }
1469
-
1470
- @media (min-width: 576px) {
1471
- .d-sm-none {
1472
- display: none !important;
1473
- }
1474
- .d-sm-block {
1475
- display: block !important;
1476
- }
1477
- .d-sm-flex {
1478
- display: flex !important;
1479
- }
1480
- }
1481
- @media (min-width: 768px) {
1482
- .d-md-none {
1483
- display: none !important;
1484
- }
1485
- .d-md-block {
1486
- display: block !important;
1487
- }
1488
- .d-md-flex {
1489
- display: flex !important;
1490
- }
1491
- }
1492
- @media (min-width: 992px) {
1493
- .d-lg-none {
1494
- display: none !important;
1495
- }
1496
- .d-lg-block {
1497
- display: block !important;
1498
- }
1499
- .d-lg-flex {
1500
- display: flex !important;
1501
- }
1502
- }
1503
- @media (min-width: 1200px) {
1504
- .d-xl-none {
1505
- display: none !important;
1506
- }
1507
- .d-xl-block {
1508
- display: block !important;
1509
- }
1510
- .d-xl-flex {
1511
- display: flex !important;
1512
- }
1513
- }
1514
- @media (min-width: 1400px) {
1515
- .d-xxl-none {
1516
- display: none !important;
1517
- }
1518
- .d-xxl-block {
1519
- display: block !important;
1520
- }
1521
- .d-xxl-flex {
1522
- display: flex !important;
1523
- }
1524
- }
1525
- @media print {
1526
- .d-print-none {
1527
- display: none !important;
1528
- }
1529
- .d-print-block {
1530
- display: block !important;
1531
- }
1532
- .d-print-flex {
1533
- display: flex !important;
1534
- }
1535
- }
1536
1803
  .modal {
1537
1804
  --bsi-modal-bg: var(--bsi-color-background-inverse);
1538
1805
  --bsi-modal-border-color: transparent;
@@ -1931,11 +2198,304 @@ var styles = css`@charset "UTF-8";
1931
2198
  height: calc(100vh - 128px);
1932
2199
  }
1933
2200
  }
1934
- body {
1935
- font-family: var(--bsi-font-sans);
2201
+ *,
2202
+ *::before,
2203
+ *::after {
2204
+ box-sizing: border-box;
1936
2205
  }
1937
2206
 
1938
- p,
2207
+ @media (prefers-reduced-motion: no-preference) {
2208
+ :root {
2209
+ scroll-behavior: smooth;
2210
+ }
2211
+ }
2212
+
2213
+ body {
2214
+ margin: 0;
2215
+ -webkit-text-size-adjust: 100%;
2216
+ -webkit-tap-highlight-color: hsla(0, 0%, 0%, 0);
2217
+ }
2218
+
2219
+ hr {
2220
+ margin: 1rem 0;
2221
+ color: inherit;
2222
+ border: 0;
2223
+ border-top: 1px solid;
2224
+ opacity: 0.25;
2225
+ }
2226
+
2227
+ p {
2228
+ margin-top: 0;
2229
+ margin-bottom: var(--bsi-paragraph-spacing);
2230
+ }
2231
+
2232
+ abbr[title] {
2233
+ text-decoration: underline dotted;
2234
+ cursor: help;
2235
+ text-decoration-skip-ink: none;
2236
+ }
2237
+
2238
+ address {
2239
+ margin-bottom: var(--bsi-spacing-s);
2240
+ font-style: normal;
2241
+ line-height: inherit;
2242
+ }
2243
+
2244
+ ol,
2245
+ ul {
2246
+ padding-left: var(--bsi-spacing-l);
2247
+ }
2248
+
2249
+ ol,
2250
+ ul,
2251
+ dl {
2252
+ margin-top: 0;
2253
+ margin-bottom: var(--bsi-spacing-s);
2254
+ }
2255
+
2256
+ ol ol,
2257
+ ul ul,
2258
+ ol ul,
2259
+ ul ol {
2260
+ margin-bottom: 0;
2261
+ }
2262
+
2263
+ dt {
2264
+ font-weight: var(--bsi-font-weight-strong);
2265
+ }
2266
+
2267
+ dd {
2268
+ margin-bottom: var(--bsi-spacing-xxs);
2269
+ margin-left: 0;
2270
+ }
2271
+
2272
+ blockquote {
2273
+ margin: 0 0 var(--bsi-spacing-s);
2274
+ }
2275
+
2276
+ sub,
2277
+ sup {
2278
+ position: relative;
2279
+ font-size: var(--bsi-font-size-1);
2280
+ line-height: 0;
2281
+ vertical-align: baseline;
2282
+ }
2283
+
2284
+ sub {
2285
+ bottom: -0.25em;
2286
+ }
2287
+
2288
+ sup {
2289
+ top: -0.5em;
2290
+ }
2291
+
2292
+ a {
2293
+ color: var(--bsi-color-link);
2294
+ text-decoration: underline;
2295
+ text-decoration-skip-ink: auto;
2296
+ text-underline-offset: 2px;
2297
+ }
2298
+ a:hover {
2299
+ color: var(--bsi-color-link-hover);
2300
+ cursor: pointer;
2301
+ }
2302
+
2303
+ pre,
2304
+ code,
2305
+ kbd,
2306
+ samp {
2307
+ font-size: 1em;
2308
+ }
2309
+
2310
+ pre {
2311
+ display: block;
2312
+ margin-top: 0;
2313
+ margin-bottom: var(--bsi-paragraph-spacing);
2314
+ overflow: auto;
2315
+ }
2316
+ pre code {
2317
+ word-break: normal;
2318
+ }
2319
+
2320
+ a > code {
2321
+ color: inherit;
2322
+ }
2323
+
2324
+ figure {
2325
+ margin: 0 0 1rem;
2326
+ }
2327
+
2328
+ img,
2329
+ svg {
2330
+ vertical-align: middle;
2331
+ }
2332
+
2333
+ table {
2334
+ caption-side: bottom;
2335
+ border-collapse: collapse;
2336
+ }
2337
+
2338
+ caption {
2339
+ padding-top: 0.5rem;
2340
+ padding-bottom: 0.5rem;
2341
+ color: hsl(210, 17%, 44%);
2342
+ text-align: left;
2343
+ }
2344
+
2345
+ th {
2346
+ text-align: inherit;
2347
+ text-align: -webkit-match-parent;
2348
+ }
2349
+
2350
+ thead,
2351
+ tbody,
2352
+ tfoot,
2353
+ tr,
2354
+ td,
2355
+ th {
2356
+ border-color: inherit;
2357
+ border-style: solid;
2358
+ border-width: 0;
2359
+ }
2360
+
2361
+ label {
2362
+ display: inline-block;
2363
+ }
2364
+
2365
+ button {
2366
+ border-radius: 0;
2367
+ }
2368
+
2369
+ button:focus:not(:focus-visible) {
2370
+ outline: 0;
2371
+ }
2372
+
2373
+ input,
2374
+ button,
2375
+ select,
2376
+ optgroup,
2377
+ textarea {
2378
+ margin: 0;
2379
+ font-family: inherit;
2380
+ font-size: inherit;
2381
+ line-height: inherit;
2382
+ }
2383
+
2384
+ button,
2385
+ select {
2386
+ text-transform: none;
2387
+ }
2388
+
2389
+ [role=button] {
2390
+ cursor: pointer;
2391
+ }
2392
+
2393
+ select {
2394
+ word-wrap: normal;
2395
+ }
2396
+ select:disabled {
2397
+ opacity: 1;
2398
+ }
2399
+
2400
+ [list]:not([type=date]):not([type=datetime-local]):not([type=month]):not([type=week]):not([type=time])::-webkit-calendar-picker-indicator {
2401
+ display: none !important;
2402
+ }
2403
+
2404
+ button,
2405
+ [type=button],
2406
+ [type=reset],
2407
+ [type=submit] {
2408
+ -webkit-appearance: button;
2409
+ }
2410
+ button:not(:disabled),
2411
+ [type=button]:not(:disabled),
2412
+ [type=reset]:not(:disabled),
2413
+ [type=submit]:not(:disabled) {
2414
+ cursor: pointer;
2415
+ }
2416
+
2417
+ ::-moz-focus-inner {
2418
+ padding: 0;
2419
+ border-style: none;
2420
+ }
2421
+
2422
+ textarea {
2423
+ resize: vertical;
2424
+ }
2425
+
2426
+ fieldset {
2427
+ min-width: 0;
2428
+ padding: 0;
2429
+ margin: 0;
2430
+ border: 0;
2431
+ }
2432
+
2433
+ ::-webkit-datetime-edit-fields-wrapper,
2434
+ ::-webkit-datetime-edit-text,
2435
+ ::-webkit-datetime-edit-minute,
2436
+ ::-webkit-datetime-edit-hour-field,
2437
+ ::-webkit-datetime-edit-day-field,
2438
+ ::-webkit-datetime-edit-month-field,
2439
+ ::-webkit-datetime-edit-year-field {
2440
+ padding: 0;
2441
+ }
2442
+
2443
+ ::-webkit-inner-spin-button {
2444
+ height: auto;
2445
+ }
2446
+
2447
+ [type=search] {
2448
+ outline-offset: -2px;
2449
+ -webkit-appearance: textfield;
2450
+ }
2451
+
2452
+ /* rtl:raw:
2453
+ [type="tel"],
2454
+ [type="url"],
2455
+ [type="email"],
2456
+ [type="number"] {
2457
+ direction: ltr;
2458
+ }
2459
+ */
2460
+ ::-webkit-search-decoration {
2461
+ -webkit-appearance: none;
2462
+ }
2463
+
2464
+ ::-webkit-color-swatch-wrapper {
2465
+ padding: 0;
2466
+ }
2467
+
2468
+ ::file-selector-button {
2469
+ font: inherit;
2470
+ -webkit-appearance: button;
2471
+ }
2472
+
2473
+ output {
2474
+ display: inline-block;
2475
+ }
2476
+
2477
+ iframe {
2478
+ border: 0;
2479
+ }
2480
+
2481
+ summary {
2482
+ display: list-item;
2483
+ cursor: pointer;
2484
+ }
2485
+
2486
+ progress {
2487
+ vertical-align: baseline;
2488
+ }
2489
+
2490
+ [hidden] {
2491
+ display: none !important;
2492
+ }
2493
+
2494
+ body {
2495
+ font-family: var(--bsi-font-sans);
2496
+ }
2497
+
2498
+ p,
1939
2499
  ul,
1940
2500
  ol,
1941
2501
  dl {
@@ -2073,7 +2633,7 @@ h6,
2073
2633
  .h6 {
2074
2634
  margin-top: 0;
2075
2635
  margin-bottom: var(--bsi-heading-spacing);
2076
- line-height: var(--bsi-heading-line-height);
2636
+ line-height: var(--bsi-heading-leading);
2077
2637
  }
2078
2638
  :is(h1, .h1, h2, .h2, h3, .h3, h4, .h4, h5, .h5, h6, .h6) + h1, p + h1,
2079
2639
  :is(h1, .h1, h2, .h2, h3, .h3, h4, .h4, h5, .h5, h6, .h6) + .h1,
@@ -2140,13 +2700,13 @@ h1,
2140
2700
  .display-1 {
2141
2701
  font-size: var(--bsi-display-font-size);
2142
2702
  font-weight: var(--bsi-heading-font-weight);
2143
- line-height: var(--bsi-heading-line-height);
2703
+ line-height: var(--bsi-heading-leading);
2144
2704
  }
2145
2705
 
2146
2706
  .lead {
2147
2707
  font-size: var(--bsi-lead-font-size);
2148
2708
  font-weight: var(--bsi-lead-font-weight);
2149
- line-height: var(--bsi-lead-line-height);
2709
+ line-height: var(--bsi-lead-leading);
2150
2710
  }
2151
2711
 
2152
2712
  blockquote,
@@ -2241,8 +2801,112 @@ blockquote.blockquote-card.dark .blockquote-footer,
2241
2801
  border: 0 !important;
2242
2802
  }
2243
2803
 
2804
+ .d-none {
2805
+ display: none !important;
2806
+ }
2807
+
2808
+ .d-block {
2809
+ display: block !important;
2810
+ }
2811
+
2812
+ .d-flex {
2813
+ display: flex !important;
2814
+ }
2815
+
2816
+ .overflow-auto {
2817
+ overflow: auto !important;
2818
+ }
2819
+
2820
+ .overflow-hidden {
2821
+ overflow: hidden !important;
2822
+ }
2823
+
2824
+ @media (min-width: 576px) {
2825
+ .d-sm-none {
2826
+ display: none !important;
2827
+ }
2828
+ .d-sm-block {
2829
+ display: block !important;
2830
+ }
2831
+ .d-sm-flex {
2832
+ display: flex !important;
2833
+ }
2834
+ }
2835
+ @media (min-width: 768px) {
2836
+ .d-md-none {
2837
+ display: none !important;
2838
+ }
2839
+ .d-md-block {
2840
+ display: block !important;
2841
+ }
2842
+ .d-md-flex {
2843
+ display: flex !important;
2844
+ }
2845
+ }
2846
+ @media (min-width: 992px) {
2847
+ .d-lg-none {
2848
+ display: none !important;
2849
+ }
2850
+ .d-lg-block {
2851
+ display: block !important;
2852
+ }
2853
+ .d-lg-flex {
2854
+ display: flex !important;
2855
+ }
2856
+ }
2857
+ @media (min-width: 1200px) {
2858
+ .d-xl-none {
2859
+ display: none !important;
2860
+ }
2861
+ .d-xl-block {
2862
+ display: block !important;
2863
+ }
2864
+ .d-xl-flex {
2865
+ display: flex !important;
2866
+ }
2867
+ }
2868
+ @media (min-width: 1400px) {
2869
+ .d-xxl-none {
2870
+ display: none !important;
2871
+ }
2872
+ .d-xxl-block {
2873
+ display: block !important;
2874
+ }
2875
+ .d-xxl-flex {
2876
+ display: flex !important;
2877
+ }
2878
+ }
2879
+ @media print {
2880
+ .d-print-none {
2881
+ display: none !important;
2882
+ }
2883
+ .d-print-block {
2884
+ display: block !important;
2885
+ }
2886
+ .d-print-flex {
2887
+ display: flex !important;
2888
+ }
2889
+ }
2244
2890
  :host {
2245
2891
  display: block;
2892
+ --it-focus-ring-safari-fix: none;
2893
+ }
2894
+
2895
+ /* Rimuovi il flash visivo solo durante l'apertura programmata */
2896
+ [part=modal]:focus {
2897
+ box-shadow: var(--it-focus-ring-safari-fix) !important;
2898
+ outline: var(--it-focus-ring-safari-fix) !important;
2899
+ }
2900
+
2901
+ [role=dialog]:focus,
2902
+ [role=dialog]:focus-visible,
2903
+ .btn-close:focus:not(:focus-visible) {
2904
+ box-shadow: none !important;
2905
+ outline: 0 !important;
2906
+ }
2907
+
2908
+ .btn-close:focus-visible {
2909
+ outline: 2px solid var(--it-focus-color) !important;
2246
2910
  }
2247
2911
 
2248
2912
  :host(:not([open])) .modal,
@@ -2273,6 +2937,13 @@ blockquote.blockquote-card.dark .blockquote-footer,
2273
2937
  overflow-y: auto;
2274
2938
  }
2275
2939
 
2940
+ :host([close-button-placement=backdrop]) .btn-close[part~=close-button] {
2941
+ --bsi-icon-default: white;
2942
+ position: absolute;
2943
+ top: 1rem;
2944
+ right: -2.5rem;
2945
+ }
2946
+
2276
2947
  .it-dialog-scrollable {
2277
2948
  overflow-y: hidden;
2278
2949
  }
@@ -2321,30 +2992,28 @@ blockquote.blockquote-card.dark .blockquote-footer,
2321
2992
  * @slot header-icon - Icona opzionale nell'header
2322
2993
  * @slot footer - Azioni del footer (pulsanti)
2323
2994
  *
2324
- * @fires it-modal-open - Quando la modale si apre
2325
- * @fires it-modal-close - Quando la modale si chiude
2995
+ * @fires it-modal-open - Quando la modale si apre (cancelable: `preventDefault()` impedisce l'apertura)
2996
+ * @fires it-modal-close - Quando la modale si chiude (cancelable: `preventDefault()` impedisce la chiusura)
2997
+ *
2998
+ * @prop {string} close-button-placement - Posizione del pulsante di chiusura: `header` (default) o `backdrop` (sopra lo sfondo scuro, utile per menu offcanvas)
2326
2999
  */
3000
+ const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
2327
3001
  let ItModal = class ItModal extends BaseComponent {
2328
3002
  get _triggerElement() {
2329
- if (!this._triggerSlot) {
2330
- this.logger.error('No trigger provided');
2331
- return null;
2332
- }
2333
- const elements = this._triggerSlot.assignedElements({ flatten: true });
2334
- if (elements.length === 0) {
2335
- return null;
2336
- }
2337
- return elements[0];
3003
+ const elements = this._triggerSlot?.assignedElements({ flatten: true });
3004
+ return elements?.[0] || null;
2338
3005
  }
2339
3006
  constructor() {
2340
3007
  super();
2341
- this.open = false;
3008
+ this.open = undefined;
2342
3009
  this.modalTitle = '';
2343
3010
  this.modalDescription = '';
3011
+ this.customHeader = false;
2344
3012
  this.size = '';
2345
3013
  this.scrollable = false;
2346
3014
  this.staticBackdrop = false;
2347
3015
  this.hideCloseButton = false;
3016
+ this.closeButtonPlacement = 'header';
2348
3017
  this.itAriaLabel = '';
2349
3018
  this.closeLabel = '';
2350
3019
  this.disableAnimation = false;
@@ -2353,53 +3022,74 @@ let ItModal = class ItModal extends BaseComponent {
2353
3022
  this._triggerId = '';
2354
3023
  this._descriptionId = '';
2355
3024
  this.isAnimating = false;
2356
- this._dialogAnimationDuration = 300; // ms - matches Bootstrap Italia modal-transition
2357
- this._backdropAnimationDuration = 150; // ms - standard fade
2358
- this._focusTrap = new FocusTrapController(this, {
2359
- getContainer: () => this._modalElement,
2360
- initialFocus: () => this._modalElement,
2361
- getTrigger: () => this._triggerElement,
2362
- onEscape: () => {
3025
+ this._isSelfClosing = false;
3026
+ this._originalTrigger = null;
3027
+ this._safariMouseInteraction = false;
3028
+ this._dialogAnimationDuration = 300;
3029
+ this._backdropAnimationDuration = 150;
3030
+ this._inertElements = [];
3031
+ this._triggerPointerBefore = null;
3032
+ /** Timer ID for the focus-restore call in finishHide. Cancelled on reconnect/unmount
3033
+ * to prevent a stale focus from a previous close cycle firing during a new open. */
3034
+ this._restoreFocusTimer = null;
3035
+ // eslint-disable-next-line class-methods-use-this
3036
+ this._handleDialogClick = (event) => {
3037
+ const path = event.composedPath();
3038
+ // Check that is not footer or react synthetic events break on buttons
3039
+ const isInFooter = path.some((el) => el instanceof HTMLElement && el.slot === 'footer');
3040
+ if (!isInFooter) {
3041
+ event.stopPropagation(); // solo per backdrop
3042
+ }
3043
+ };
3044
+ this._handleBackdropClick = () => {
3045
+ if (!this.staticBackdrop) {
2363
3046
  this.hide();
2364
- },
2365
- disableEscape: false,
2366
- });
3047
+ }
3048
+ };
2367
3049
  this._onTriggerSlotChange = () => {
2368
3050
  this._setupTriggerListeners();
2369
3051
  };
2370
3052
  this._onHeaderSlotChange = () => {
2371
3053
  this.requestUpdate();
2372
3054
  };
2373
- this._onTriggerClick = (event) => {
3055
+ this._onTriggerClick = async (event) => {
2374
3056
  event.stopPropagation();
3057
+ const trigger = this._triggerElement;
3058
+ if (!trigger)
3059
+ return;
3060
+ if (isSafari) {
3061
+ this._safariMouseInteraction = true;
3062
+ }
3063
+ await this.updateComplete; // Assicurati che l'update sia completo prima di applicare il focus workaround
2375
3064
  this.show();
2376
3065
  };
2377
- this._onTriggerKeydown = (event) => {
3066
+ this._onTriggerKeydown = async (event) => {
2378
3067
  if (event.key === 'Enter' || event.key === ' ') {
2379
3068
  event.preventDefault();
2380
3069
  this.show();
2381
3070
  }
2382
- };
2383
- this._handleCloseClick = () => {
2384
- this.hide();
2385
- };
2386
- this._handleBackdropClick = () => {
2387
- if (!this.staticBackdrop) {
2388
- this.hide();
2389
- }
2390
- };
2391
- // eslint-disable-next-line class-methods-use-this
2392
- this._handleDialogClick = (event) => {
2393
- const path = event.composedPath();
2394
- // Check that is not footer or react synthetic events break on buttons
2395
- const isInFooter = path.some((el) => el instanceof HTMLElement && el.slot === 'footer');
2396
- if (!isInFooter) {
2397
- event.stopPropagation(); // solo per backdrop
3071
+ else {
3072
+ const trigger = this._triggerElement;
3073
+ if (!trigger)
3074
+ return;
3075
+ if (isSafari) {
3076
+ this._safariMouseInteraction = false;
3077
+ }
3078
+ await this.updateComplete; // Assicurati che l'update sia completo prima di applicare il focus workaround
2398
3079
  }
2399
3080
  };
2400
3081
  this._triggerId = this.generateId('modal-trigger');
2401
3082
  this._titleId = this.generateId('modal-title');
2402
3083
  this._descriptionId = this.generateId('modal-description');
3084
+ this._focusTrap = new FocusTrapController(this, {
3085
+ getContainer: () => this._modalElement,
3086
+ initialFocus: () => this._modalElement,
3087
+ getTrigger: () => this._triggerElement,
3088
+ onEscape: () => {
3089
+ this._safariMouseInteraction = false;
3090
+ this.hide();
3091
+ },
3092
+ });
2403
3093
  }
2404
3094
  connectedCallback() {
2405
3095
  super.connectedCallback?.();
@@ -2408,59 +3098,129 @@ let ItModal = class ItModal extends BaseComponent {
2408
3098
  super.disconnectedCallback?.();
2409
3099
  this._removeTriggerListeners();
2410
3100
  this._cleanupAnimations();
3101
+ this._removeInert();
3102
+ if (this._restoreFocusTimer !== null) {
3103
+ clearTimeout(this._restoreFocusTimer);
3104
+ this._restoreFocusTimer = null;
3105
+ }
2411
3106
  WindowManager.unlockBodyScroll();
2412
3107
  }
3108
+ show() {
3109
+ if (this.open || this.isAnimating)
3110
+ return;
3111
+ // `it-modal-open` is cancelable: calling `preventDefault()` stops the modal
3112
+ // from opening (the consumer can open it later by calling `show()` again).
3113
+ dispatchCancelable(this, 'it-modal-open', { modal: this }, () => {
3114
+ this._originalTrigger = this._triggerElement;
3115
+ this.open = true;
3116
+ });
3117
+ }
3118
+ hide() {
3119
+ if (!this.open || this.isAnimating)
3120
+ return;
3121
+ // `it-modal-close` is cancelable: calling `preventDefault()` keeps the modal
3122
+ // open (the consumer can close it later by calling `hide()`).
3123
+ dispatchCancelable(this, 'it-modal-close', { modal: this }, () => {
3124
+ this._hideModal();
3125
+ });
3126
+ }
3127
+ toggle() {
3128
+ if (this.open) {
3129
+ this.hide();
3130
+ }
3131
+ else {
3132
+ this.show();
3133
+ }
3134
+ }
2413
3135
  updated(changedProperties) {
2414
3136
  if (changedProperties.has('open')) {
2415
- // Cancel any ongoing animations before starting new ones
3137
+ if (this._isSelfClosing) {
3138
+ this._isSelfClosing = false;
3139
+ return;
3140
+ }
2416
3141
  this._cleanupAnimations();
2417
- if (this.open) {
2418
- this._showModal();
3142
+ if (this.open !== undefined) {
3143
+ if (this.open)
3144
+ this._showModal();
3145
+ else
3146
+ this._hideModal();
3147
+ }
3148
+ }
3149
+ if (changedProperties.has('_safariMouseInteraction')) {
3150
+ let realButton = this._triggerElement;
3151
+ if (realButton?.tagName.toLowerCase() === 'it-button') {
3152
+ realButton = this._triggerElement?.shadowRoot?.querySelector('button');
3153
+ }
3154
+ if (!realButton)
3155
+ return;
3156
+ // Fix Safari: se l'interazione è da mouse, rimuovi outline e box-shadow forzati per evitare il doppio focus ring
3157
+ if (this._safariMouseInteraction) {
3158
+ realButton.style.setProperty('outline', '0', 'important');
3159
+ realButton.style.setProperty('box-shadow', 'none', 'important');
2419
3160
  }
2420
3161
  else {
2421
- this._hideModal();
3162
+ realButton.style.removeProperty('outline');
3163
+ realButton.style.removeProperty('box-shadow');
2422
3164
  }
2423
3165
  }
2424
3166
  }
2425
- _setupTriggerListeners() {
2426
- const trigger = this._triggerElement;
2427
- if (!trigger)
2428
- return;
2429
- trigger.setAttribute('id', this._triggerId);
2430
- // Rimuovi eventuali listener precedenti
2431
- trigger.removeEventListener('click', this._onTriggerClick);
2432
- trigger.removeEventListener('keydown', this._onTriggerKeydown);
2433
- // Aggiungi nuovi listener
2434
- trigger.addEventListener('click', this._onTriggerClick);
2435
- trigger.addEventListener('keydown', this._onTriggerKeydown);
2436
- }
2437
- _removeTriggerListeners() {
3167
+ _applyInert() {
3168
+ this._removeInert();
2438
3169
  const trigger = this._triggerElement;
2439
- if (!trigger)
2440
- return;
2441
- trigger.removeEventListener('click', this._onTriggerClick);
2442
- trigger.removeEventListener('keydown', this._onTriggerKeydown);
2443
- }
2444
- show() {
2445
- if (this.open || this.isAnimating)
2446
- return;
2447
- this.open = true;
2448
- }
2449
- hide() {
2450
- if (!this.open || this.isAnimating)
2451
- return;
2452
- this._hideModal();
3170
+ if (trigger) {
3171
+ this._triggerPointerBefore = trigger.style.pointerEvents;
3172
+ trigger.style.pointerEvents = 'none';
3173
+ trigger.setAttribute('inert', '');
3174
+ if (trigger.tagName.toLowerCase().startsWith('it-')) {
3175
+ trigger.setAttribute('it-inert', '');
3176
+ }
3177
+ }
3178
+ const ignored = new Set(['SCRIPT', 'STYLE', 'TEMPLATE', 'LINK']);
3179
+ for (let cur = this; cur && cur !== document.body; cur = cur.parentElement) {
3180
+ const parent = cur.parentElement;
3181
+ if (!parent)
3182
+ break;
3183
+ Array.from(parent.children).forEach((node) => {
3184
+ if (node !== cur && !ignored.has(node.tagName) && node instanceof HTMLElement) {
3185
+ node.setAttribute('inert', '');
3186
+ // // FIX FOR SAFARI/VOICEOVER:
3187
+ // // If it's a web component with a shadow root, VoiceOver might still
3188
+ // // find the inner button.
3189
+ if (node.shadowRoot && isSafari) {
3190
+ node.setAttribute('inert', '');
3191
+ node.setAttribute('it-inert', '');
3192
+ }
3193
+ this._inertElements.push(node);
3194
+ }
3195
+ });
3196
+ }
2453
3197
  }
2454
- toggle() {
2455
- this.open = !this.open;
3198
+ _removeInert() {
3199
+ this._inertElements.forEach((el) => {
3200
+ el.removeAttribute('inert');
3201
+ el.removeAttribute('it-inert');
3202
+ });
3203
+ if (this._triggerElement && this._triggerPointerBefore !== null) {
3204
+ this._triggerElement.style.pointerEvents = this._triggerPointerBefore;
3205
+ this._triggerElement.removeAttribute('inert');
3206
+ this._triggerElement.removeAttribute('it-inert');
3207
+ }
3208
+ this._inertElements = [];
3209
+ this._triggerPointerBefore = null;
2456
3210
  }
2457
- _showModal() {
3211
+ async _showModal() {
2458
3212
  if (this.isAnimating)
2459
3213
  return;
3214
+ // Cancel any stale close-focus-restore timer so it doesn't fire during the new open.
3215
+ if (this._restoreFocusTimer !== null) {
3216
+ clearTimeout(this._restoreFocusTimer);
3217
+ this._restoreFocusTimer = null;
3218
+ }
2460
3219
  this.isAnimating = true;
2461
- // Deactivate focus trap first if it was active
2462
- this._focusTrap.deactivate();
3220
+ this._applyInert();
2463
3221
  WindowManager.lockBodyScroll();
3222
+ // ASPETTA LIT o race conditions solo per Safari
3223
+ await this.updateComplete;
2464
3224
  requestAnimationFrame(() => {
2465
3225
  // Determine transform based on position
2466
3226
  let dialogStartTransform = 'translate(0, 0)'; // default: no transform
@@ -2492,48 +3252,27 @@ let ItModal = class ItModal extends BaseComponent {
2492
3252
  });
2493
3253
  this._dialogAnimation.finished
2494
3254
  .then(() => {
2495
- // Only activate focus trap if modal is still open
2496
3255
  if (this.open) {
2497
- try {
2498
- this._focusTrap.activate();
2499
- }
2500
- catch {
2501
- // Swallow errors if focus trap fails
2502
- }
3256
+ this._focusTrap.activate();
2503
3257
  }
2504
- })
2505
- .catch(() => {
2506
- // Animation cancelled or failed
2507
3258
  })
2508
3259
  .finally(() => {
2509
3260
  this.isAnimating = false;
2510
3261
  });
2511
3262
  }
2512
3263
  else {
2513
- // No dialog element or no animation, just finish
2514
- if (this.open) {
2515
- try {
2516
- this._focusTrap.activate();
2517
- }
2518
- catch {
2519
- // Swallow errors if focus trap fails
2520
- }
2521
- }
3264
+ // No animation: activate immediately. The 50ms inside activate()'s setTimeout
3265
+ // gives VoiceOver iOS enough time to settle its accessibility tree.
3266
+ // See FocusTrapController class comment for full rationale.
3267
+ this._focusTrap.activate();
2522
3268
  this.isAnimating = false;
2523
3269
  }
2524
3270
  });
2525
- this.dispatchEvent(new CustomEvent('it-modal-open', {
2526
- detail: { modal: this },
2527
- bubbles: true,
2528
- composed: true,
2529
- }));
2530
3271
  }
2531
3272
  _hideModal() {
2532
3273
  if (this.isAnimating)
2533
3274
  return;
2534
3275
  this.isAnimating = true;
2535
- // Deactivate focus trap immediately to prevent focus issues
2536
- this._focusTrap.deactivate();
2537
3276
  // Determine end transform based on position
2538
3277
  let dialogEndTransform = 'translate(0, 0)'; // default: no transform
2539
3278
  let dialogCloseDuration = this._dialogAnimationDuration / 1.33;
@@ -2551,12 +3290,27 @@ let ItModal = class ItModal extends BaseComponent {
2551
3290
  const dialogDuration = !this.disableAnimation && !this.prefersReducedMotion ? dialogCloseDuration : 0;
2552
3291
  const backdropDuration = !this.disableAnimation && !this.prefersReducedMotion ? this._backdropAnimationDuration / 1.33 : 0;
2553
3292
  const finishHide = () => {
2554
- // Ensure focus trap is deactivated
2555
- this._focusTrap.deactivate();
3293
+ const target = this._originalTrigger ?? this._triggerElement;
3294
+ this._removeInert();
2556
3295
  this._cleanupAnimations();
3296
+ // skipFocusRestore: we manage focus restore ourselves with the timer below.
3297
+ // Without this, _restoreFocus() fires at 0ms and the timer fires at 20ms,
3298
+ // causing VoiceOver to announce the restored element twice.
3299
+ this._focusTrap.deactivate({ skipFocusRestore: true });
2557
3300
  WindowManager.unlockBodyScroll();
2558
- // Set open to false after animation completes
3301
+ this._isSelfClosing = true;
3302
+ this.isAnimating = false;
2559
3303
  this.open = false;
3304
+ if (target) {
3305
+ this._restoreFocusTimer = setTimeout(() => {
3306
+ this._restoreFocusTimer = null;
3307
+ if (!this.open)
3308
+ target.focus({ preventScroll: true });
3309
+ }, 20);
3310
+ }
3311
+ this._originalTrigger = null;
3312
+ if (isSafari)
3313
+ this._safariMouseInteraction = false;
2560
3314
  };
2561
3315
  // Animate dialog and backdrop in parallel for smoother close
2562
3316
  const animations = [];
@@ -2593,39 +3347,38 @@ let ItModal = class ItModal extends BaseComponent {
2593
3347
  else {
2594
3348
  // No animation, finish immediately
2595
3349
  finishHide();
2596
- this.isAnimating = false;
2597
3350
  }
2598
- this.dispatchEvent(new CustomEvent('it-modal-close', {
2599
- detail: { modal: this },
2600
- bubbles: true,
2601
- composed: true,
2602
- }));
2603
3351
  }
2604
3352
  _cleanupAnimations() {
2605
- if (this._dialogAnimation) {
2606
- try {
2607
- this._dialogAnimation.cancel();
2608
- }
2609
- catch {
2610
- /* ignore */
2611
- }
2612
- this._dialogAnimation = undefined;
2613
- }
2614
- if (this._backdropAnimation) {
2615
- try {
2616
- this._backdropAnimation.cancel();
2617
- }
2618
- catch {
2619
- /* ignore */
2620
- }
2621
- this._backdropAnimation = undefined;
2622
- }
3353
+ this._dialogAnimation?.cancel();
3354
+ this._backdropAnimation?.cancel();
3355
+ this._dialogAnimation = undefined;
3356
+ this._backdropAnimation = undefined;
3357
+ }
3358
+ _setupTriggerListeners() {
3359
+ const trigger = this._triggerElement;
3360
+ if (!trigger)
3361
+ return;
3362
+ trigger.setAttribute('id', this._triggerId);
3363
+ // Rimuovi eventuali listener precedenti
3364
+ trigger.removeEventListener('click', this._onTriggerClick);
3365
+ trigger.removeEventListener('keydown', this._onTriggerKeydown);
3366
+ // Aggiungi nuovi listener
3367
+ trigger.addEventListener('click', this._onTriggerClick);
3368
+ trigger.addEventListener('keydown', this._onTriggerKeydown);
3369
+ }
3370
+ _removeTriggerListeners() {
3371
+ const trigger = this._triggerElement;
3372
+ if (!trigger)
3373
+ return;
3374
+ trigger.removeEventListener('click', this._onTriggerClick);
3375
+ trigger.removeEventListener('keydown', this._onTriggerKeydown);
2623
3376
  }
2624
3377
  get _modalClasses() {
2625
3378
  return {
2626
3379
  modal: true,
2627
3380
  fade: !this.disableAnimation,
2628
- show: this.open && !this.disableAnimation,
3381
+ show: Boolean(this.open) && !this.disableAnimation,
2629
3382
  'alert-modal': this.variant === 'alert',
2630
3383
  'popconfirm-modal': this.variant === 'popconfirm',
2631
3384
  'it-dialog-link-list': this.variant === 'link-list',
@@ -2644,58 +3397,73 @@ let ItModal = class ItModal extends BaseComponent {
2644
3397
  'modal-xl': this.size === 'xl',
2645
3398
  };
2646
3399
  }
3400
+ _renderCloseButton() {
3401
+ if (this.hideCloseButton || this.variant === 'popconfirm') {
3402
+ return '';
3403
+ }
3404
+ return html `<it-button
3405
+ class="btn-close"
3406
+ variant="link"
3407
+ size="lg"
3408
+ part="close-button"
3409
+ exportparts="focusable, button, button:close-button-button"
3410
+ @click="${() => this.hide()}"
3411
+ >
3412
+ <it-icon name="it-close" size="lg"></it-icon>
3413
+ <span class="visually-hidden">${this.closeLabel}</span>
3414
+ </it-button>`;
3415
+ }
2647
3416
  render() {
2648
- const hasHeader = this.modalTitle || this._headerSlot?.assignedElements({ flatten: true }).length > 0;
2649
- const ariaLabelledBy = hasHeader ? this._titleId : undefined;
2650
- const ariaLabel = !hasHeader ? this.itAriaLabel : undefined;
2651
- const headerClass = hasHeader || (this.variant !== 'popconfirm' && !this.hideCloseButton) ? 'modal-header' : '';
2652
- const hasDescription = this.modalDescription || this._descriptionSlot?.assignedElements({ flatten: true }).length > 0;
2653
- const ariaDescribedBy = hasDescription ? this._descriptionId : undefined;
3417
+ const hasHeader = (this.modalTitle || this._headerSlot?.assignedElements({ flatten: true }).length > 0) && !this.customHeader;
2654
3418
  const enableFocusContent = this.scrollable || this.position === 'left' || this.position === 'right';
3419
+ let ariaLabelledBy = hasHeader ? this._titleId : undefined;
3420
+ if (this.itAriaLabel) {
3421
+ ariaLabelledBy = undefined;
3422
+ }
2655
3423
  return html `
2656
3424
  <slot name="trigger" @slotchange=${this._onTriggerSlotChange}></slot>
2657
-
2658
3425
  <div
2659
3426
  class="${classMap(this._modalClasses)}"
2660
3427
  role="dialog"
2661
3428
  aria-modal="true"
2662
3429
  aria-labelledby="${ifDefined(ariaLabelledBy)}"
2663
- aria-describedby="${ifDefined(ariaDescribedBy)}"
2664
- aria-label="${ifDefined(ariaLabel)}"
3430
+ aria-describedby="${ifDefined(this._descriptionId)}"
3431
+ aria-label="${ifDefined(this.itAriaLabel || undefined)}"
2665
3432
  aria-hidden="${!this.open}"
2666
3433
  tabindex="-1"
2667
3434
  @click="${this._handleBackdropClick}"
2668
3435
  part="modal"
2669
3436
  >
3437
+ <!-- TRICK SAFARI ENGINE -->
3438
+ <div
3439
+ id="safari-focus-anchor"
3440
+ tabindex="-1"
3441
+ aria-hidden="true"
3442
+ style="position: absolute; width: 0; height: 0; outline: none;"
3443
+ ></div>
2670
3444
  <div
2671
3445
  class="${classMap(this._modalBodyClasses)}"
2672
3446
  role="document"
2673
3447
  @click="${this._handleDialogClick}"
2674
3448
  part="modal-content-wrapper"
2675
3449
  >
3450
+ ${this.closeButtonPlacement === 'backdrop' ? this._renderCloseButton() : ''}
2676
3451
  <div class="visually-hidden" id="${this._descriptionId}">
2677
3452
  <slot name="description" @slotchange="${this._onHeaderSlotChange}">${this.modalDescription}</slot>
2678
3453
  </div>
2679
3454
  <div class="modal-content" part="modal-content">
2680
- <div class="${headerClass}" part="modal-header">
3455
+ <div
3456
+ class="${hasHeader || (this.variant !== 'popconfirm' && !this.hideCloseButton) ? 'modal-header' : ''}"
3457
+ part="modal-header"
3458
+ >
2681
3459
  <slot name="header-icon"></slot>
2682
- <h2 id="${this._titleId}" class="modal-title">
2683
- <slot name="header" @slotchange="${this._onHeaderSlotChange}">${this.modalTitle}</slot>
2684
- </h2>
2685
- ${!this.hideCloseButton && this.variant !== 'popconfirm'
2686
- ? html `<it-button
2687
- class="btn-close"
2688
- variant="link"
2689
- size="lg"
2690
- exportparts="focusable, button"
2691
- @click="${this._handleCloseClick}"
2692
- >
2693
- <it-icon name="it-close" size="lg"></it-icon>
2694
- <span class="visually-hidden">${this.closeLabel}</span>
2695
- </it-button>`
2696
- : ''}
3460
+ ${hasHeader
3461
+ ? html `<h2 id="${this._titleId}" class="modal-title">
3462
+ <slot name="header" @slotchange="${this._onHeaderSlotChange}">${this.modalTitle}</slot>
3463
+ </h2>`
3464
+ : html `<div><slot name="header" @slotchange="${this._onHeaderSlotChange}"></slot></div>`}
3465
+ ${this.closeButtonPlacement === 'header' ? this._renderCloseButton() : ''}
2697
3466
  </div>
2698
-
2699
3467
  <div class="modal-body" tabindex="${enableFocusContent ? '0' : '-1'}" part="focusable modal-body">
2700
3468
  <slot name="content"></slot>
2701
3469
  </div>
@@ -2705,21 +3473,17 @@ let ItModal = class ItModal extends BaseComponent {
2705
3473
  </div>
2706
3474
  </div>
2707
3475
  </div>
2708
-
2709
3476
  <div
2710
3477
  class="modal-backdrop ${this.disableAnimation ? 'fade' : ''} ${this.open ? 'show' : ''}"
2711
3478
  aria-hidden="true"
2712
- @click="${this._handleBackdropClick}"
3479
+ @click="${() => !this.staticBackdrop && this.hide()}"
2713
3480
  part="modal-backdrop"
2714
3481
  ></div>
2715
3482
  `;
2716
3483
  }
2717
3484
  };
2718
3485
  ItModal.styles = styles;
2719
- ItModal.shadowRootOptions = {
2720
- ...BaseComponent.shadowRootOptions,
2721
- delegatesFocus: true,
2722
- };
3486
+ ItModal.shadowRootOptions = { ...BaseComponent.shadowRootOptions, delegatesFocus: true };
2723
3487
  __decorate([
2724
3488
  property({ type: Boolean, reflect: true }),
2725
3489
  __metadata("design:type", Object)
@@ -2732,13 +3496,17 @@ __decorate([
2732
3496
  property({ type: String, attribute: 'modal-description', reflect: true }),
2733
3497
  __metadata("design:type", Object)
2734
3498
  ], ItModal.prototype, "modalDescription", void 0);
3499
+ __decorate([
3500
+ property({ type: Boolean, attribute: 'custom-header', reflect: true }),
3501
+ __metadata("design:type", Object)
3502
+ ], ItModal.prototype, "customHeader", void 0);
2735
3503
  __decorate([
2736
3504
  property({ type: String, reflect: true }),
2737
3505
  __metadata("design:type", String)
2738
3506
  ], ItModal.prototype, "size", void 0);
2739
3507
  __decorate([
2740
3508
  property({ type: String, reflect: true }),
2741
- __metadata("design:type", Object)
3509
+ __metadata("design:type", String)
2742
3510
  ], ItModal.prototype, "position", void 0);
2743
3511
  __decorate([
2744
3512
  property({ type: Boolean, reflect: true }),
@@ -2752,13 +3520,17 @@ __decorate([
2752
3520
  property({ type: Boolean, attribute: 'hide-close-button', reflect: true }),
2753
3521
  __metadata("design:type", Object)
2754
3522
  ], ItModal.prototype, "hideCloseButton", void 0);
3523
+ __decorate([
3524
+ property({ type: String, attribute: 'close-button-placement', reflect: true }),
3525
+ __metadata("design:type", String)
3526
+ ], ItModal.prototype, "closeButtonPlacement", void 0);
2755
3527
  __decorate([
2756
3528
  property({ type: String, reflect: true }),
2757
- __metadata("design:type", Object)
3529
+ __metadata("design:type", String)
2758
3530
  ], ItModal.prototype, "variant", void 0);
2759
3531
  __decorate([
2760
3532
  property({ type: String, attribute: 'it-aria-label' }),
2761
- __metadata("design:type", String)
3533
+ __metadata("design:type", Object)
2762
3534
  ], ItModal.prototype, "itAriaLabel", void 0);
2763
3535
  __decorate([
2764
3536
  property({ type: String, attribute: 'close-label', reflect: true }),
@@ -2796,6 +3568,10 @@ __decorate([
2796
3568
  query('.modal-dialog'),
2797
3569
  __metadata("design:type", HTMLElement)
2798
3570
  ], ItModal.prototype, "_dialogElement", void 0);
3571
+ __decorate([
3572
+ state(),
3573
+ __metadata("design:type", Object)
3574
+ ], ItModal.prototype, "_safariMouseInteraction", void 0);
2799
3575
  ItModal = __decorate([
2800
3576
  customElement('it-modal'),
2801
3577
  __metadata("design:paramtypes", [])