@italia/modal 1.0.0-alpha.9 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,6 +478,26 @@ 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);
@@ -438,6 +526,158 @@ const BaseLocalizedComponent = LocalizeMixin(BaseComponent);
438
526
  * focus-trap npm package, and a11y-dialog.
439
527
  */
440
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
+ }
441
681
  /**
442
682
  * Verifica se un elemento è effettivamente focusabile e tabbabile.
443
683
  * Elementi con tabindex="-1" sono focusabili programmaticamente ma non tabbabili.
@@ -469,6 +709,10 @@ class FocusTrapController {
469
709
  this._isActive = false;
470
710
  this._previousActiveElement = null;
471
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;
472
716
  /** Timer ID for the focus call scheduled inside activate(). Cancelled by deactivate()
473
717
  * to prevent focus firing after the trap has been torn down (fast open/close, unmount). */
474
718
  this._pendingFocusTimer = null;
@@ -487,6 +731,32 @@ class FocusTrapController {
487
731
  break;
488
732
  }
489
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
+ };
490
760
  this.host = host;
491
761
  this.config = config;
492
762
  this.host.addController(this);
@@ -517,7 +787,9 @@ class FocusTrapController {
517
787
  // Usa document capture: cattura Tab/Escape prima di qualsiasi handler,
518
788
  // indipendentemente da shadow DOM, delegatesFocus e slot retargeting.
519
789
  document.addEventListener('keydown', this._handleKeyDown, true);
790
+ document.addEventListener('focusin', this._handleFocusIn, true);
520
791
  this.updateFocusableElements();
792
+ this._lastKnownFocusIndex = -1;
521
793
  // FIX Safari: trick engine
522
794
  // Diamo al browser un istante per processare il ricalcolo del layout
523
795
  requestAnimationFrame(() => {
@@ -533,6 +805,7 @@ class FocusTrapController {
533
805
  }
534
806
  }
535
807
  else {
808
+ // eslint-disable-next-line no-console
536
809
  console.warn("FocusTrap: missing 'initialFocus' callback, provide one");
537
810
  }
538
811
  });
@@ -548,6 +821,8 @@ class FocusTrapController {
548
821
  }
549
822
  this._isActive = false;
550
823
  document.removeEventListener('keydown', this._handleKeyDown, true);
824
+ document.removeEventListener('focusin', this._handleFocusIn, true);
825
+ this._lastKnownFocusIndex = -1;
551
826
  if (!options?.skipFocusRestore) {
552
827
  this._restoreFocus();
553
828
  }
@@ -569,20 +844,21 @@ class FocusTrapController {
569
844
  return;
570
845
  }
571
846
  const candidates = [];
572
- const direct = Array.from(container.querySelectorAll(FocusTrapController.FOCUSABLE_SELECTORS));
573
- candidates.push(...direct);
574
- // Tutti gli elementi slottati
575
- const slots = Array.from(container.querySelectorAll('slot'));
576
- slots.forEach((slot) => {
577
- slot.assignedElements({ flatten: true }).forEach((el) => {
578
- if (!(el instanceof HTMLElement))
579
- return;
580
- if (el === trigger)
581
- return;
582
- if (el.matches(FocusTrapController.FOCUSABLE_SELECTORS))
583
- candidates.push(el);
584
- Array.from(el.querySelectorAll(FocusTrapController.FOCUSABLE_SELECTORS)).forEach((nested) => candidates.push(nested));
585
- });
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
+ }
586
862
  });
587
863
  // Filtra solo elementi veramente focusabili e rimuovi duplicati
588
864
  this._focusableElements = Array.from(new Set(candidates)).filter((el) => {
@@ -615,15 +891,24 @@ class FocusTrapController {
615
891
  return active;
616
892
  }
617
893
  _handleTab(event) {
618
- // ANTI RACE CONDITION: se l'utente è troppo veloce, forza un ricalcolo immediato
619
- if (this._focusableElements.length === 0)
620
- this.updateFocusableElements();
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') {
900
+ return;
901
+ }
902
+ }
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();
621
906
  if (this._focusableElements.length === 0)
622
907
  return; // Se è ancora vuoto, non bloccare il Tab
623
908
  event.preventDefault();
624
- const activeElement = FocusTrapController.getActiveElement();
625
909
  let currentIndex = this._focusableElements.indexOf(activeElement);
626
910
  if (currentIndex === -1 && activeElement) {
911
+ // 1. Walk shadow host chain (covers delegatesFocus custom elements)
627
912
  let parent = activeElement.getRootNode()?.host;
628
913
  while (parent && currentIndex === -1) {
629
914
  currentIndex = this._focusableElements.indexOf(parent);
@@ -631,16 +916,43 @@ class FocusTrapController {
631
916
  parent = parent.getRootNode()?.host;
632
917
  }
633
918
  }
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));
925
+ }
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));
932
+ }
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');
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
+ }
634
946
  if (event.shiftKey) {
635
947
  if (currentIndex <= 0)
636
- this._last?.focus();
948
+ FocusTrapController.focusCandidate(this._last);
637
949
  else
638
- this._focusableElements[currentIndex - 1]?.focus();
950
+ FocusTrapController.focusCandidate(this._focusableElements[currentIndex - 1]);
639
951
  }
640
952
  else if (currentIndex === -1 || currentIndex >= this._focusableElements.length - 1)
641
- this._first?.focus();
953
+ FocusTrapController.focusCandidate(this._first);
642
954
  else
643
- this._focusableElements[currentIndex + 1]?.focus();
955
+ FocusTrapController.focusCandidate(this._focusableElements[currentIndex + 1]);
644
956
  }
645
957
  _restoreFocus() {
646
958
  const target = this._previousActiveElement;
@@ -665,6 +977,25 @@ FocusTrapController.FOCUSABLE_SELECTORS = [
665
977
  'select:not([disabled])',
666
978
  '[tabindex]',
667
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])',
668
999
  ].join(',');
669
1000
 
670
1001
  //
@@ -1095,7 +1426,7 @@ class FormControl extends BaseLocalizedComponent {
1095
1426
  });
1096
1427
  // TODO: verificare se serve davvero con il fatto che usiamo form-controller
1097
1428
  // static formAssociated = true;
1098
- // @property()
1429
+ // @property()
1099
1430
  // internals = this.attachInternals();
1100
1431
  this._touched = false;
1101
1432
  /** The name of the input, submitted as a name/value pair with form data. */
@@ -1339,6 +1670,49 @@ __decorate([
1339
1670
  __metadata("design:type", Object)
1340
1671
  ], FormControl.prototype, "validationMessage", void 0);
1341
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
+
1342
1716
  class WindowManager {
1343
1717
  static init() {
1344
1718
  if (this.initialized)
@@ -1421,110 +1795,11 @@ if (typeof window !== 'undefined') {
1421
1795
  window._itAnalytics = window._itAnalytics || {};
1422
1796
  window._itAnalytics = {
1423
1797
  ...window._itAnalytics,
1424
- version: '1.0.0-alpha.9',
1798
+ version: '1.0.0-beta.1',
1425
1799
  };
1426
1800
  }
1427
1801
 
1428
1802
  var styles = css`@charset "UTF-8";
1429
- /***************************** 1 ****************************************/
1430
- /***************************** 2 ****************************************/
1431
- /***************************** 1 ****************************************/
1432
- /***************************** 2 ****************************************/
1433
- /***************************** 1 ****************************************/
1434
- /***************************** 2 ****************************************/
1435
- /***************************** 3 ****************************************/
1436
- /***************************** 1 ****************************************/
1437
- /***************************** 2 ****************************************/
1438
- /***************************** 3 ****************************************/
1439
- /***************************** NEUTRAL 1 ****************************************/
1440
- /***************************** NEUTRAL 2 ****************************************/
1441
- /***************************** NEUTRAL 2 / 3 ****************************************/
1442
- .d-none {
1443
- display: none !important;
1444
- }
1445
-
1446
- .d-block {
1447
- display: block !important;
1448
- }
1449
-
1450
- .d-flex {
1451
- display: flex !important;
1452
- }
1453
-
1454
- .overflow-auto {
1455
- overflow: auto !important;
1456
- }
1457
-
1458
- .overflow-hidden {
1459
- overflow: hidden !important;
1460
- }
1461
-
1462
- @media (min-width: 576px) {
1463
- .d-sm-none {
1464
- display: none !important;
1465
- }
1466
- .d-sm-block {
1467
- display: block !important;
1468
- }
1469
- .d-sm-flex {
1470
- display: flex !important;
1471
- }
1472
- }
1473
- @media (min-width: 768px) {
1474
- .d-md-none {
1475
- display: none !important;
1476
- }
1477
- .d-md-block {
1478
- display: block !important;
1479
- }
1480
- .d-md-flex {
1481
- display: flex !important;
1482
- }
1483
- }
1484
- @media (min-width: 992px) {
1485
- .d-lg-none {
1486
- display: none !important;
1487
- }
1488
- .d-lg-block {
1489
- display: block !important;
1490
- }
1491
- .d-lg-flex {
1492
- display: flex !important;
1493
- }
1494
- }
1495
- @media (min-width: 1200px) {
1496
- .d-xl-none {
1497
- display: none !important;
1498
- }
1499
- .d-xl-block {
1500
- display: block !important;
1501
- }
1502
- .d-xl-flex {
1503
- display: flex !important;
1504
- }
1505
- }
1506
- @media (min-width: 1400px) {
1507
- .d-xxl-none {
1508
- display: none !important;
1509
- }
1510
- .d-xxl-block {
1511
- display: block !important;
1512
- }
1513
- .d-xxl-flex {
1514
- display: flex !important;
1515
- }
1516
- }
1517
- @media print {
1518
- .d-print-none {
1519
- display: none !important;
1520
- }
1521
- .d-print-block {
1522
- display: block !important;
1523
- }
1524
- .d-print-flex {
1525
- display: flex !important;
1526
- }
1527
- }
1528
1803
  .modal {
1529
1804
  --bsi-modal-bg: var(--bsi-color-background-inverse);
1530
1805
  --bsi-modal-border-color: transparent;
@@ -1562,6 +1837,7 @@ var styles = css`@charset "UTF-8";
1562
1837
  }
1563
1838
 
1564
1839
  .modal-dialog-scrollable {
1840
+ --bsi-modal-margin: 0;
1565
1841
  height: calc(100% - var(--bsi-modal-margin) * 2);
1566
1842
  }
1567
1843
  .modal-dialog-scrollable .modal-content {
@@ -1573,6 +1849,7 @@ var styles = css`@charset "UTF-8";
1573
1849
  }
1574
1850
 
1575
1851
  .modal-dialog-centered {
1852
+ --bsi-modal-margin: 0;
1576
1853
  display: flex;
1577
1854
  align-items: center;
1578
1855
  min-height: calc(100% - var(--bsi-modal-margin) * 2);
@@ -1656,6 +1933,10 @@ var styles = css`@charset "UTF-8";
1656
1933
  --bsi-modal-margin: 1.5rem;
1657
1934
  --bsi-modal-box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
1658
1935
  }
1936
+ .modal-dialog-scrollable,
1937
+ .modal-dialog-centered {
1938
+ --bsi-modal-margin: 1.5rem;
1939
+ }
1659
1940
  .modal-dialog {
1660
1941
  max-width: var(--bsi-modal-width);
1661
1942
  }
@@ -1836,10 +2117,17 @@ var styles = css`@charset "UTF-8";
1836
2117
  .modal.popconfirm-modal .modal-dialog .modal-footer {
1837
2118
  justify-content: flex-start;
1838
2119
  }
2120
+ .modal.it-dialog-scrollable .modal-dialog {
2121
+ --bsi-modal-margin: 0.5rem;
2122
+ height: calc(100% - var(--bsi-modal-margin) * 2);
2123
+ margin: var(--bsi-modal-margin) auto;
2124
+ }
1839
2125
  .modal.it-dialog-scrollable .modal-dialog .modal-content {
1840
2126
  display: flex;
1841
2127
  flex-direction: column;
1842
- height: calc(100vh - 208px);
2128
+ height: 100%;
2129
+ max-height: 100%;
2130
+ overflow: hidden;
1843
2131
  border-radius: 0;
1844
2132
  }
1845
2133
  .modal.it-dialog-scrollable .modal-dialog .modal-content .modal-header {
@@ -1855,19 +2143,19 @@ var styles = css`@charset "UTF-8";
1855
2143
  flex-shrink: 0;
1856
2144
  }
1857
2145
  .modal.it-dialog-scrollable .modal-dialog.modal-dialog-left {
1858
- height: 100vh;
2146
+ height: 100%;
1859
2147
  margin: 0 var(--bsi-spacing-m) 0 0;
1860
2148
  }
1861
2149
  .modal.it-dialog-scrollable .modal-dialog.modal-dialog-left .modal-content {
1862
- height: 100vh;
2150
+ height: 100%;
1863
2151
  }
1864
2152
  .modal.it-dialog-scrollable .modal-dialog.modal-dialog-right {
1865
- height: 100vh;
2153
+ height: 100%;
1866
2154
  margin: 0 0 0 var(--bsi-spacing-m);
1867
2155
  float: right;
1868
2156
  }
1869
2157
  .modal.it-dialog-scrollable .modal-dialog.modal-dialog-right .modal-content {
1870
- height: 100vh;
2158
+ height: 100%;
1871
2159
  }
1872
2160
  .modal.fade .modal-dialog {
1873
2161
  transition: var(--bsi-modal-transition);
@@ -1907,22 +2195,312 @@ var styles = css`@charset "UTF-8";
1907
2195
  margin: 0;
1908
2196
  }
1909
2197
  .modal .modal-dialog.modal-dialog-left .modal-content {
1910
- height: 100vh;
2198
+ height: 100%;
1911
2199
  }
1912
2200
  .modal .modal-dialog.modal-dialog-right {
1913
2201
  margin: 0;
1914
2202
  float: right;
1915
2203
  }
1916
2204
  .modal .modal-dialog.modal-dialog-right .modal-content {
1917
- height: 100vh;
2205
+ height: 100%;
1918
2206
  }
1919
2207
  .modal.it-dialog-scrollable .modal-dialog {
1920
- margin: 64px auto;
2208
+ --bsi-modal-margin: min(64px, 10vh);
1921
2209
  }
1922
- .modal.it-dialog-scrollable .modal-dialog .modal-content {
1923
- height: calc(100vh - 128px);
2210
+ }
2211
+ *,
2212
+ *::before,
2213
+ *::after {
2214
+ box-sizing: border-box;
2215
+ }
2216
+
2217
+ @media (prefers-reduced-motion: no-preference) {
2218
+ :root {
2219
+ scroll-behavior: smooth;
1924
2220
  }
1925
2221
  }
2222
+
2223
+ body {
2224
+ margin: 0;
2225
+ -webkit-text-size-adjust: 100%;
2226
+ -webkit-tap-highlight-color: hsla(0, 0%, 0%, 0);
2227
+ }
2228
+
2229
+ hr {
2230
+ margin: 1rem 0;
2231
+ color: inherit;
2232
+ border: 0;
2233
+ border-top: 1px solid;
2234
+ opacity: 0.25;
2235
+ }
2236
+
2237
+ p {
2238
+ margin-top: 0;
2239
+ margin-bottom: var(--bsi-paragraph-spacing);
2240
+ }
2241
+
2242
+ abbr[title] {
2243
+ text-decoration: underline dotted;
2244
+ cursor: help;
2245
+ text-decoration-skip-ink: none;
2246
+ }
2247
+
2248
+ address {
2249
+ margin-bottom: var(--bsi-spacing-s);
2250
+ font-style: normal;
2251
+ line-height: inherit;
2252
+ }
2253
+
2254
+ ol,
2255
+ ul {
2256
+ padding-left: var(--bsi-spacing-l);
2257
+ }
2258
+
2259
+ ol,
2260
+ ul,
2261
+ dl {
2262
+ margin-top: 0;
2263
+ margin-bottom: var(--bsi-spacing-s);
2264
+ }
2265
+
2266
+ ol ol,
2267
+ ul ul,
2268
+ ol ul,
2269
+ ul ol {
2270
+ margin-bottom: 0;
2271
+ }
2272
+
2273
+ dt {
2274
+ font-weight: var(--bsi-font-weight-strong);
2275
+ }
2276
+
2277
+ dd {
2278
+ margin-bottom: var(--bsi-spacing-xxs);
2279
+ margin-left: 0;
2280
+ }
2281
+
2282
+ blockquote {
2283
+ margin: 0 0 var(--bsi-spacing-s);
2284
+ }
2285
+
2286
+ sub,
2287
+ sup {
2288
+ position: relative;
2289
+ font-size: var(--bsi-font-size-1);
2290
+ line-height: 0;
2291
+ vertical-align: baseline;
2292
+ }
2293
+
2294
+ sub {
2295
+ bottom: -0.25em;
2296
+ }
2297
+
2298
+ sup {
2299
+ top: -0.5em;
2300
+ }
2301
+
2302
+ a {
2303
+ color: var(--bsi-color-link);
2304
+ text-decoration: underline;
2305
+ text-decoration-skip-ink: auto;
2306
+ text-underline-offset: 2px;
2307
+ }
2308
+ a:hover {
2309
+ color: var(--bsi-color-link-hover);
2310
+ cursor: pointer;
2311
+ }
2312
+
2313
+ pre,
2314
+ code,
2315
+ kbd,
2316
+ samp {
2317
+ font-size: 1em;
2318
+ }
2319
+
2320
+ pre {
2321
+ display: block;
2322
+ margin-top: 0;
2323
+ margin-bottom: var(--bsi-paragraph-spacing);
2324
+ overflow: auto;
2325
+ }
2326
+ pre code {
2327
+ word-break: normal;
2328
+ }
2329
+
2330
+ a > code {
2331
+ color: inherit;
2332
+ }
2333
+
2334
+ figure {
2335
+ margin: 0 0 1rem;
2336
+ }
2337
+
2338
+ img,
2339
+ svg {
2340
+ vertical-align: middle;
2341
+ }
2342
+
2343
+ table {
2344
+ caption-side: bottom;
2345
+ border-collapse: collapse;
2346
+ }
2347
+
2348
+ caption {
2349
+ padding-top: 0.5rem;
2350
+ padding-bottom: 0.5rem;
2351
+ color: hsl(210, 17%, 44%);
2352
+ text-align: left;
2353
+ }
2354
+
2355
+ th {
2356
+ text-align: inherit;
2357
+ text-align: -webkit-match-parent;
2358
+ }
2359
+
2360
+ thead,
2361
+ tbody,
2362
+ tfoot,
2363
+ tr,
2364
+ td,
2365
+ th {
2366
+ border-color: inherit;
2367
+ border-style: solid;
2368
+ border-width: 0;
2369
+ }
2370
+
2371
+ label {
2372
+ display: inline-block;
2373
+ }
2374
+
2375
+ button {
2376
+ border-radius: 0;
2377
+ }
2378
+
2379
+ button:focus:not(:focus-visible) {
2380
+ outline: 0;
2381
+ }
2382
+
2383
+ input,
2384
+ button,
2385
+ select,
2386
+ optgroup,
2387
+ textarea {
2388
+ margin: 0;
2389
+ font-family: inherit;
2390
+ font-size: inherit;
2391
+ line-height: inherit;
2392
+ }
2393
+
2394
+ button,
2395
+ select {
2396
+ text-transform: none;
2397
+ }
2398
+
2399
+ [role=button] {
2400
+ cursor: pointer;
2401
+ }
2402
+
2403
+ select {
2404
+ word-wrap: normal;
2405
+ }
2406
+ select:disabled {
2407
+ opacity: 1;
2408
+ }
2409
+
2410
+ [list]:not([type=date]):not([type=datetime-local]):not([type=month]):not([type=week]):not([type=time])::-webkit-calendar-picker-indicator {
2411
+ display: none !important;
2412
+ }
2413
+
2414
+ button,
2415
+ [type=button],
2416
+ [type=reset],
2417
+ [type=submit] {
2418
+ -webkit-appearance: button;
2419
+ }
2420
+ button:not(:disabled),
2421
+ [type=button]:not(:disabled),
2422
+ [type=reset]:not(:disabled),
2423
+ [type=submit]:not(:disabled) {
2424
+ cursor: pointer;
2425
+ }
2426
+
2427
+ ::-moz-focus-inner {
2428
+ padding: 0;
2429
+ border-style: none;
2430
+ }
2431
+
2432
+ textarea {
2433
+ resize: vertical;
2434
+ }
2435
+
2436
+ fieldset {
2437
+ min-width: 0;
2438
+ padding: 0;
2439
+ margin: 0;
2440
+ border: 0;
2441
+ }
2442
+
2443
+ ::-webkit-datetime-edit-fields-wrapper,
2444
+ ::-webkit-datetime-edit-text,
2445
+ ::-webkit-datetime-edit-minute,
2446
+ ::-webkit-datetime-edit-hour-field,
2447
+ ::-webkit-datetime-edit-day-field,
2448
+ ::-webkit-datetime-edit-month-field,
2449
+ ::-webkit-datetime-edit-year-field {
2450
+ padding: 0;
2451
+ }
2452
+
2453
+ ::-webkit-inner-spin-button {
2454
+ height: auto;
2455
+ }
2456
+
2457
+ [type=search] {
2458
+ outline-offset: -2px;
2459
+ -webkit-appearance: textfield;
2460
+ }
2461
+
2462
+ /* rtl:raw:
2463
+ [type="tel"],
2464
+ [type="url"],
2465
+ [type="email"],
2466
+ [type="number"] {
2467
+ direction: ltr;
2468
+ }
2469
+ */
2470
+ ::-webkit-search-decoration {
2471
+ -webkit-appearance: none;
2472
+ }
2473
+
2474
+ ::-webkit-color-swatch-wrapper {
2475
+ padding: 0;
2476
+ }
2477
+
2478
+ ::file-selector-button {
2479
+ font: inherit;
2480
+ -webkit-appearance: button;
2481
+ }
2482
+
2483
+ output {
2484
+ display: inline-block;
2485
+ }
2486
+
2487
+ iframe {
2488
+ border: 0;
2489
+ }
2490
+
2491
+ summary {
2492
+ display: list-item;
2493
+ cursor: pointer;
2494
+ }
2495
+
2496
+ progress {
2497
+ vertical-align: baseline;
2498
+ }
2499
+
2500
+ [hidden] {
2501
+ display: none !important;
2502
+ }
2503
+
1926
2504
  body {
1927
2505
  font-family: var(--bsi-font-sans);
1928
2506
  }
@@ -2233,6 +2811,92 @@ blockquote.blockquote-card.dark .blockquote-footer,
2233
2811
  border: 0 !important;
2234
2812
  }
2235
2813
 
2814
+ .d-none {
2815
+ display: none !important;
2816
+ }
2817
+
2818
+ .d-block {
2819
+ display: block !important;
2820
+ }
2821
+
2822
+ .d-flex {
2823
+ display: flex !important;
2824
+ }
2825
+
2826
+ .overflow-auto {
2827
+ overflow: auto !important;
2828
+ }
2829
+
2830
+ .overflow-hidden {
2831
+ overflow: hidden !important;
2832
+ }
2833
+
2834
+ @media (min-width: 576px) {
2835
+ .d-sm-none {
2836
+ display: none !important;
2837
+ }
2838
+ .d-sm-block {
2839
+ display: block !important;
2840
+ }
2841
+ .d-sm-flex {
2842
+ display: flex !important;
2843
+ }
2844
+ }
2845
+ @media (min-width: 768px) {
2846
+ .d-md-none {
2847
+ display: none !important;
2848
+ }
2849
+ .d-md-block {
2850
+ display: block !important;
2851
+ }
2852
+ .d-md-flex {
2853
+ display: flex !important;
2854
+ }
2855
+ }
2856
+ @media (min-width: 992px) {
2857
+ .d-lg-none {
2858
+ display: none !important;
2859
+ }
2860
+ .d-lg-block {
2861
+ display: block !important;
2862
+ }
2863
+ .d-lg-flex {
2864
+ display: flex !important;
2865
+ }
2866
+ }
2867
+ @media (min-width: 1200px) {
2868
+ .d-xl-none {
2869
+ display: none !important;
2870
+ }
2871
+ .d-xl-block {
2872
+ display: block !important;
2873
+ }
2874
+ .d-xl-flex {
2875
+ display: flex !important;
2876
+ }
2877
+ }
2878
+ @media (min-width: 1400px) {
2879
+ .d-xxl-none {
2880
+ display: none !important;
2881
+ }
2882
+ .d-xxl-block {
2883
+ display: block !important;
2884
+ }
2885
+ .d-xxl-flex {
2886
+ display: flex !important;
2887
+ }
2888
+ }
2889
+ @media print {
2890
+ .d-print-none {
2891
+ display: none !important;
2892
+ }
2893
+ .d-print-block {
2894
+ display: block !important;
2895
+ }
2896
+ .d-print-flex {
2897
+ display: flex !important;
2898
+ }
2899
+ }
2236
2900
  :host {
2237
2901
  display: block;
2238
2902
  --it-focus-ring-safari-fix: none;
@@ -2283,6 +2947,13 @@ blockquote.blockquote-card.dark .blockquote-footer,
2283
2947
  overflow-y: auto;
2284
2948
  }
2285
2949
 
2950
+ :host([close-button-placement=backdrop]) .btn-close[part~=close-button] {
2951
+ --bsi-icon-default: white;
2952
+ position: absolute;
2953
+ top: 1rem;
2954
+ right: -2.5rem;
2955
+ }
2956
+
2286
2957
  .it-dialog-scrollable {
2287
2958
  overflow-y: hidden;
2288
2959
  }
@@ -2321,6 +2992,21 @@ blockquote.blockquote-card.dark .blockquote-footer,
2321
2992
  right: 0;
2322
2993
  }`;
2323
2994
 
2995
+ /**
2996
+ * Componente Modal per finestre di dialogo modali.
2997
+ *
2998
+ * @element it-modal
2999
+ *
3000
+ * @slot trigger - Elemento che apre la modale (es. it-button)
3001
+ * @slot content - Contenuto principale della modale (body)
3002
+ * @slot header-icon - Icona opzionale nell'header
3003
+ * @slot footer - Azioni del footer (pulsanti)
3004
+ *
3005
+ * @fires it-modal-open - Quando la modale si apre (cancelable: `preventDefault()` impedisce l'apertura)
3006
+ * @fires it-modal-close - Quando la modale si chiude (cancelable: `preventDefault()` impedisce la chiusura)
3007
+ *
3008
+ * @prop {string} close-button-placement - Posizione del pulsante di chiusura: `header` (default) o `backdrop` (sopra lo sfondo scuro, utile per menu offcanvas)
3009
+ */
2324
3010
  const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
2325
3011
  let ItModal = class ItModal extends BaseComponent {
2326
3012
  get _triggerElement() {
@@ -2332,14 +3018,17 @@ let ItModal = class ItModal extends BaseComponent {
2332
3018
  this.open = undefined;
2333
3019
  this.modalTitle = '';
2334
3020
  this.modalDescription = '';
3021
+ this.customHeader = false;
2335
3022
  this.size = '';
2336
3023
  this.scrollable = false;
2337
3024
  this.staticBackdrop = false;
2338
3025
  this.hideCloseButton = false;
3026
+ this.closeButtonPlacement = 'header';
2339
3027
  this.itAriaLabel = '';
2340
3028
  this.closeLabel = '';
2341
3029
  this.disableAnimation = false;
2342
3030
  this.footerShadow = false;
3031
+ this.defaultFocusClose = false;
2343
3032
  this._titleId = '';
2344
3033
  this._triggerId = '';
2345
3034
  this._descriptionId = '';
@@ -2405,7 +3094,7 @@ let ItModal = class ItModal extends BaseComponent {
2405
3094
  this._descriptionId = this.generateId('modal-description');
2406
3095
  this._focusTrap = new FocusTrapController(this, {
2407
3096
  getContainer: () => this._modalElement,
2408
- initialFocus: () => this._modalElement,
3097
+ initialFocus: () => this._entryPoint(),
2409
3098
  getTrigger: () => this._triggerElement,
2410
3099
  onEscape: () => {
2411
3100
  this._safariMouseInteraction = false;
@@ -2416,6 +3105,19 @@ let ItModal = class ItModal extends BaseComponent {
2416
3105
  connectedCallback() {
2417
3106
  super.connectedCallback?.();
2418
3107
  }
3108
+ /**
3109
+ * Element the focus enters on when the modal opens.
3110
+ *
3111
+ * Deliberately not the `[role="dialog"]` element: NVDA doesn't announce the role when focus
3112
+ * lands on the dialog element itself (nvaccess/nvda#8620), so the user is told the name of the
3113
+ * modal but never that it is a dialog — unlike VoiceOver, JAWS and Narrator, which announce it.
3114
+ * Entering on a descendant instead has the dialog announced as its ancestor, role included.
3115
+ * `.modal-content` is a container and not a control, so its content is still read out after the
3116
+ * announcement, exactly as it was when focus landed on the dialog.
3117
+ */
3118
+ _entryPoint() {
3119
+ return this.defaultFocusClose ? this._closeButton : (this._contentElement ?? this._modalElement);
3120
+ }
2419
3121
  disconnectedCallback() {
2420
3122
  super.disconnectedCallback?.();
2421
3123
  this._removeTriggerListeners();
@@ -2430,18 +3132,29 @@ let ItModal = class ItModal extends BaseComponent {
2430
3132
  show() {
2431
3133
  if (this.open || this.isAnimating)
2432
3134
  return;
2433
- this._originalTrigger = this._triggerElement;
2434
- this.dispatchEvent(new CustomEvent('it-modal-open', { detail: { modal: this }, bubbles: true, composed: true }));
2435
- this.open = true;
3135
+ // `it-modal-open` is cancelable: calling `preventDefault()` stops the modal
3136
+ // from opening (the consumer can open it later by calling `show()` again).
3137
+ dispatchCancelable(this, 'it-modal-open', { modal: this }, () => {
3138
+ this._originalTrigger = this._triggerElement;
3139
+ this.open = true;
3140
+ });
2436
3141
  }
2437
3142
  hide() {
2438
3143
  if (!this.open || this.isAnimating)
2439
3144
  return;
2440
- this.dispatchEvent(new CustomEvent('it-modal-close', { detail: { modal: this }, bubbles: true, composed: true }));
2441
- this._hideModal();
3145
+ // `it-modal-close` is cancelable: calling `preventDefault()` keeps the modal
3146
+ // open (the consumer can close it later by calling `hide()`).
3147
+ dispatchCancelable(this, 'it-modal-close', { modal: this }, () => {
3148
+ this._hideModal();
3149
+ });
2442
3150
  }
2443
3151
  toggle() {
2444
- this.open = !this.open;
3152
+ if (this.open) {
3153
+ this.hide();
3154
+ }
3155
+ else {
3156
+ this.show();
3157
+ }
2445
3158
  }
2446
3159
  updated(changedProperties) {
2447
3160
  if (changedProperties.has('open')) {
@@ -2708,60 +3421,64 @@ let ItModal = class ItModal extends BaseComponent {
2708
3421
  'modal-xl': this.size === 'xl',
2709
3422
  };
2710
3423
  }
3424
+ _renderCloseButton() {
3425
+ if (this.hideCloseButton || this.variant === 'popconfirm') {
3426
+ return '';
3427
+ }
3428
+ return html `<it-button
3429
+ class="btn-close"
3430
+ variant="link"
3431
+ size="lg"
3432
+ part="close-button"
3433
+ exportparts="focusable, button, button:close-button-button"
3434
+ @click="${() => this.hide()}"
3435
+ >
3436
+ <it-icon name="it-close" size="lg"></it-icon>
3437
+ <span class="visually-hidden">${this.closeLabel}</span>
3438
+ </it-button>`;
3439
+ }
2711
3440
  render() {
2712
- const hasHeader = this.modalTitle || (this._headerSlot?.assignedElements({ flatten: true }).length || 0) > 0;
2713
- const ariaLabel = !hasHeader ? this.itAriaLabel || undefined : undefined;
3441
+ const hasHeader = (this.modalTitle || this._headerSlot?.assignedElements({ flatten: true }).length > 0) && !this.customHeader;
2714
3442
  const enableFocusContent = this.scrollable || this.position === 'left' || this.position === 'right';
3443
+ let ariaLabelledBy = hasHeader ? this._titleId : undefined;
3444
+ if (this.itAriaLabel) {
3445
+ ariaLabelledBy = undefined;
3446
+ }
2715
3447
  return html `
2716
3448
  <slot name="trigger" @slotchange=${this._onTriggerSlotChange}></slot>
2717
3449
  <div
2718
3450
  class="${classMap(this._modalClasses)}"
2719
3451
  role="dialog"
2720
3452
  aria-modal="true"
2721
- aria-labelledby="${ifDefined(hasHeader ? this._titleId : undefined)}"
3453
+ aria-labelledby="${ifDefined(ariaLabelledBy)}"
2722
3454
  aria-describedby="${ifDefined(this._descriptionId)}"
2723
- aria-label="${ifDefined(ariaLabel)}"
3455
+ aria-label="${ifDefined(this.itAriaLabel || undefined)}"
2724
3456
  aria-hidden="${!this.open}"
2725
3457
  tabindex="-1"
2726
3458
  @click="${this._handleBackdropClick}"
2727
3459
  part="modal"
2728
3460
  >
2729
- <!-- TRICK SAFARI ENGINE -->
2730
- <div
2731
- id="safari-focus-anchor"
2732
- tabindex="-1"
2733
- aria-hidden="true"
2734
- style="position: absolute; width: 0; height: 0; outline: none;"
2735
- ></div>
2736
3461
  <div
2737
3462
  class="${classMap(this._modalBodyClasses)}"
2738
- role="document"
2739
3463
  @click="${this._handleDialogClick}"
2740
3464
  part="modal-content-wrapper"
2741
3465
  >
3466
+ ${this.closeButtonPlacement === 'backdrop' ? this._renderCloseButton() : ''}
2742
3467
  <div class="visually-hidden" id="${this._descriptionId}">
2743
3468
  <slot name="description" @slotchange="${this._onHeaderSlotChange}">${this.modalDescription}</slot>
2744
3469
  </div>
2745
- <div class="modal-content" part="modal-content">
3470
+ <div class="modal-content" tabindex="-1" part="modal-content">
2746
3471
  <div
2747
3472
  class="${hasHeader || (this.variant !== 'popconfirm' && !this.hideCloseButton) ? 'modal-header' : ''}"
2748
3473
  part="modal-header"
2749
3474
  >
2750
3475
  <slot name="header-icon"></slot>
2751
- <h2 id="${this._titleId}" class="modal-title">
2752
- <slot name="header" @slotchange="${this._onHeaderSlotChange}">${this.modalTitle}</slot>
2753
- </h2>
2754
- ${!this.hideCloseButton && this.variant !== 'popconfirm'
2755
- ? html `<it-button
2756
- class="btn-close"
2757
- variant="link"
2758
- size="lg"
2759
- exportparts="focusable, button"
2760
- @click="${() => this.hide()}"
2761
- ><it-icon name="it-close" size="lg"></it-icon
2762
- ><span class="visually-hidden">${this.closeLabel}</span></it-button
2763
- >`
2764
- : ''}
3476
+ ${hasHeader
3477
+ ? html `<h2 id="${this._titleId}" class="modal-title">
3478
+ <slot name="header" @slotchange="${this._onHeaderSlotChange}">${this.modalTitle}</slot>
3479
+ </h2>`
3480
+ : html `<div><slot name="header" @slotchange="${this._onHeaderSlotChange}"></slot></div>`}
3481
+ ${this.closeButtonPlacement === 'header' ? this._renderCloseButton() : ''}
2765
3482
  </div>
2766
3483
  <div class="modal-body" tabindex="${enableFocusContent ? '0' : '-1'}" part="focusable modal-body">
2767
3484
  <slot name="content"></slot>
@@ -2795,6 +3512,10 @@ __decorate([
2795
3512
  property({ type: String, attribute: 'modal-description', reflect: true }),
2796
3513
  __metadata("design:type", Object)
2797
3514
  ], ItModal.prototype, "modalDescription", void 0);
3515
+ __decorate([
3516
+ property({ type: Boolean, attribute: 'custom-header', reflect: true }),
3517
+ __metadata("design:type", Object)
3518
+ ], ItModal.prototype, "customHeader", void 0);
2798
3519
  __decorate([
2799
3520
  property({ type: String, reflect: true }),
2800
3521
  __metadata("design:type", String)
@@ -2815,6 +3536,10 @@ __decorate([
2815
3536
  property({ type: Boolean, attribute: 'hide-close-button', reflect: true }),
2816
3537
  __metadata("design:type", Object)
2817
3538
  ], ItModal.prototype, "hideCloseButton", void 0);
3539
+ __decorate([
3540
+ property({ type: String, attribute: 'close-button-placement', reflect: true }),
3541
+ __metadata("design:type", String)
3542
+ ], ItModal.prototype, "closeButtonPlacement", void 0);
2818
3543
  __decorate([
2819
3544
  property({ type: String, reflect: true }),
2820
3545
  __metadata("design:type", String)
@@ -2835,6 +3560,10 @@ __decorate([
2835
3560
  property({ type: Boolean, attribute: 'footer-shadow', reflect: true }),
2836
3561
  __metadata("design:type", Object)
2837
3562
  ], ItModal.prototype, "footerShadow", void 0);
3563
+ __decorate([
3564
+ property({ type: Boolean, attribute: 'default-focus-close', reflect: true }),
3565
+ __metadata("design:type", Object)
3566
+ ], ItModal.prototype, "defaultFocusClose", void 0);
2838
3567
  __decorate([
2839
3568
  query('[role="dialog"]'),
2840
3569
  __metadata("design:type", HTMLElement)
@@ -2859,6 +3588,14 @@ __decorate([
2859
3588
  query('.modal-dialog'),
2860
3589
  __metadata("design:type", HTMLElement)
2861
3590
  ], ItModal.prototype, "_dialogElement", void 0);
3591
+ __decorate([
3592
+ query('.modal-content'),
3593
+ __metadata("design:type", HTMLElement)
3594
+ ], ItModal.prototype, "_contentElement", void 0);
3595
+ __decorate([
3596
+ query('[part="close-button"]'),
3597
+ __metadata("design:type", HTMLElement)
3598
+ ], ItModal.prototype, "_closeButton", void 0);
2862
3599
  __decorate([
2863
3600
  state(),
2864
3601
  __metadata("design:type", Object)