@italia/notification 1.0.0-alpha.9 → 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,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);
@@ -842,7 +930,7 @@ class FormControl extends BaseLocalizedComponent {
842
930
  });
843
931
  // TODO: verificare se serve davvero con il fatto che usiamo form-controller
844
932
  // static formAssociated = true;
845
- // @property()
933
+ // @property()
846
934
  // internals = this.attachInternals();
847
935
  this._touched = false;
848
936
  /** The name of the input, submitted as a name/value pair with form data. */
@@ -1086,11 +1174,74 @@ __decorate([
1086
1174
  __metadata("design:type", Object)
1087
1175
  ], FormControl.prototype, "validationMessage", void 0);
1088
1176
 
1177
+ /**
1178
+ * Returns the nearest focusable ancestor of `el` by walking up parentElement.
1179
+ * Used as the last-resort fallback when a self-removing component (chip, alert)
1180
+ * has no adjacent sibling of the same type to shift focus to.
1181
+ *
1182
+ * "Focusable ancestor" means an element with tabindex >= 0. The container that
1183
+ * wraps a chip group or alert list is the expected target; authors following the
1184
+ * WAI-ARIA pattern should give it tabindex="0".
1185
+ */
1186
+ function focusableFallbackAncestor(el) {
1187
+ let current = el.parentElement;
1188
+ while (current) {
1189
+ const tab = current.getAttribute('tabindex');
1190
+ if (tab !== null && parseInt(tab, 10) >= 0)
1191
+ return current;
1192
+ current = current.parentElement;
1193
+ }
1194
+ return null;
1195
+ }
1196
+ /** Mirrors FocusTrapController's notion of "focusable", scoped to the handful of
1197
+ * interactive elements consumers actually place next to alert/chip/notification. */
1198
+ const FOCUSABLE_SELECTORS = [
1199
+ 'a[href]',
1200
+ 'button:not([disabled])',
1201
+ 'input:not([disabled]):not([type="hidden"])',
1202
+ 'select:not([disabled])',
1203
+ 'textarea:not([disabled])',
1204
+ '[tabindex]:not([tabindex="-1"])',
1205
+ 'it-button:not([disabled])',
1206
+ ].join(',');
1207
+ /**
1208
+ * True last-resort fallback for when a self-removing component (alert, chip,
1209
+ * notification) has neither an adjacent sibling of the same type nor a
1210
+ * `focusableFallbackAncestor` (i.e. no author-provided `tabindex="0"` wrapper) —
1211
+ * the common case in practice, since most real usages don't add that wrapper.
1212
+ * Without this, focus silently drops to `<body>` with no way for a keyboard/AT
1213
+ * user to tell where they ended up.
1214
+ *
1215
+ * Finds the closest focusable element to `el` anywhere in the document, walking
1216
+ * outward in document order: the nearest one that comes before `el` (closer to
1217
+ * where the user's attention already was), falling back to the nearest one after.
1218
+ * This is a coarse, page-wide search — it may land focus on something not
1219
+ * visually adjacent — but it is deterministic and strictly better than silently
1220
+ * losing focus.
1221
+ */
1222
+ function nearestFocusableInDocument(el) {
1223
+ const candidates = Array.from(document.querySelectorAll(FOCUSABLE_SELECTORS)).filter((candidate) => candidate !== el && !el.contains(candidate));
1224
+ if (!candidates.length)
1225
+ return null;
1226
+ let closestBefore = null;
1227
+ let closestAfter = null;
1228
+ candidates.forEach((candidate) => {
1229
+ // eslint-disable-next-line no-bitwise
1230
+ if (el.compareDocumentPosition(candidate) & Node.DOCUMENT_POSITION_PRECEDING) {
1231
+ closestBefore = candidate; // querySelectorAll returns document order, so the last match wins
1232
+ }
1233
+ else if (!closestAfter) {
1234
+ closestAfter = candidate; // first match after `el` in document order
1235
+ }
1236
+ });
1237
+ return closestBefore ?? closestAfter;
1238
+ }
1239
+
1089
1240
  if (typeof window !== 'undefined') {
1090
1241
  window._itAnalytics = window._itAnalytics || {};
1091
1242
  window._itAnalytics = {
1092
1243
  ...window._itAnalytics,
1093
- version: '1.0.0-alpha.9',
1244
+ version: '1.0.0-beta.0',
1094
1245
  };
1095
1246
  }
1096
1247
 
@@ -1105,19 +1256,6 @@ const NOTIFICATION_STATUS_COLORS = {
1105
1256
  const NOTIFICATION_FIX = ['top', 'bottom', 'left', 'right'];
1106
1257
 
1107
1258
  var styles = css`@charset "UTF-8";
1108
- /***************************** 1 ****************************************/
1109
- /***************************** 2 ****************************************/
1110
- /***************************** 1 ****************************************/
1111
- /***************************** 2 ****************************************/
1112
- /***************************** 1 ****************************************/
1113
- /***************************** 2 ****************************************/
1114
- /***************************** 3 ****************************************/
1115
- /***************************** 1 ****************************************/
1116
- /***************************** 2 ****************************************/
1117
- /***************************** 3 ****************************************/
1118
- /***************************** NEUTRAL 1 ****************************************/
1119
- /***************************** NEUTRAL 2 ****************************************/
1120
- /***************************** NEUTRAL 2 / 3 ****************************************/
1121
1259
  .fade {
1122
1260
  transition: opacity 0.15s linear;
1123
1261
  }
@@ -1264,7 +1402,7 @@ var styles = css`@charset "UTF-8";
1264
1402
  }
1265
1403
  .notification.with-icon p {
1266
1404
  margin-bottom: 0;
1267
- margin-left: var(--bsi-spacing-xl);
1405
+ margin-left: var(--bsi-spacing-l);
1268
1406
  }
1269
1407
  .notification.with-icon.success {
1270
1408
  --bsi-notification-inset-line-color: var(--bsi-color-border-success);
@@ -1304,6 +1442,299 @@ var styles = css`@charset "UTF-8";
1304
1442
  box-shadow: none;
1305
1443
  }
1306
1444
 
1445
+ *,
1446
+ *::before,
1447
+ *::after {
1448
+ box-sizing: border-box;
1449
+ }
1450
+
1451
+ @media (prefers-reduced-motion: no-preference) {
1452
+ :root {
1453
+ scroll-behavior: smooth;
1454
+ }
1455
+ }
1456
+
1457
+ body {
1458
+ margin: 0;
1459
+ -webkit-text-size-adjust: 100%;
1460
+ -webkit-tap-highlight-color: hsla(0, 0%, 0%, 0);
1461
+ }
1462
+
1463
+ hr {
1464
+ margin: 1rem 0;
1465
+ color: inherit;
1466
+ border: 0;
1467
+ border-top: 1px solid;
1468
+ opacity: 0.25;
1469
+ }
1470
+
1471
+ p {
1472
+ margin-top: 0;
1473
+ margin-bottom: var(--bsi-paragraph-spacing);
1474
+ }
1475
+
1476
+ abbr[title] {
1477
+ text-decoration: underline dotted;
1478
+ cursor: help;
1479
+ text-decoration-skip-ink: none;
1480
+ }
1481
+
1482
+ address {
1483
+ margin-bottom: var(--bsi-spacing-s);
1484
+ font-style: normal;
1485
+ line-height: inherit;
1486
+ }
1487
+
1488
+ ol,
1489
+ ul {
1490
+ padding-left: var(--bsi-spacing-l);
1491
+ }
1492
+
1493
+ ol,
1494
+ ul,
1495
+ dl {
1496
+ margin-top: 0;
1497
+ margin-bottom: var(--bsi-spacing-s);
1498
+ }
1499
+
1500
+ ol ol,
1501
+ ul ul,
1502
+ ol ul,
1503
+ ul ol {
1504
+ margin-bottom: 0;
1505
+ }
1506
+
1507
+ dt {
1508
+ font-weight: var(--bsi-font-weight-strong);
1509
+ }
1510
+
1511
+ dd {
1512
+ margin-bottom: var(--bsi-spacing-xxs);
1513
+ margin-left: 0;
1514
+ }
1515
+
1516
+ blockquote {
1517
+ margin: 0 0 var(--bsi-spacing-s);
1518
+ }
1519
+
1520
+ sub,
1521
+ sup {
1522
+ position: relative;
1523
+ font-size: var(--bsi-font-size-1);
1524
+ line-height: 0;
1525
+ vertical-align: baseline;
1526
+ }
1527
+
1528
+ sub {
1529
+ bottom: -0.25em;
1530
+ }
1531
+
1532
+ sup {
1533
+ top: -0.5em;
1534
+ }
1535
+
1536
+ a {
1537
+ color: var(--bsi-color-link);
1538
+ text-decoration: underline;
1539
+ text-decoration-skip-ink: auto;
1540
+ text-underline-offset: 2px;
1541
+ }
1542
+ a:hover {
1543
+ color: var(--bsi-color-link-hover);
1544
+ cursor: pointer;
1545
+ }
1546
+
1547
+ pre,
1548
+ code,
1549
+ kbd,
1550
+ samp {
1551
+ font-size: 1em;
1552
+ }
1553
+
1554
+ pre {
1555
+ display: block;
1556
+ margin-top: 0;
1557
+ margin-bottom: var(--bsi-paragraph-spacing);
1558
+ overflow: auto;
1559
+ }
1560
+ pre code {
1561
+ word-break: normal;
1562
+ }
1563
+
1564
+ a > code {
1565
+ color: inherit;
1566
+ }
1567
+
1568
+ figure {
1569
+ margin: 0 0 1rem;
1570
+ }
1571
+
1572
+ img,
1573
+ svg {
1574
+ vertical-align: middle;
1575
+ }
1576
+
1577
+ table {
1578
+ caption-side: bottom;
1579
+ border-collapse: collapse;
1580
+ }
1581
+
1582
+ caption {
1583
+ padding-top: 0.5rem;
1584
+ padding-bottom: 0.5rem;
1585
+ color: hsl(210, 17%, 44%);
1586
+ text-align: left;
1587
+ }
1588
+
1589
+ th {
1590
+ text-align: inherit;
1591
+ text-align: -webkit-match-parent;
1592
+ }
1593
+
1594
+ thead,
1595
+ tbody,
1596
+ tfoot,
1597
+ tr,
1598
+ td,
1599
+ th {
1600
+ border-color: inherit;
1601
+ border-style: solid;
1602
+ border-width: 0;
1603
+ }
1604
+
1605
+ label {
1606
+ display: inline-block;
1607
+ }
1608
+
1609
+ button {
1610
+ border-radius: 0;
1611
+ }
1612
+
1613
+ button:focus:not(:focus-visible) {
1614
+ outline: 0;
1615
+ }
1616
+
1617
+ input,
1618
+ button,
1619
+ select,
1620
+ optgroup,
1621
+ textarea {
1622
+ margin: 0;
1623
+ font-family: inherit;
1624
+ font-size: inherit;
1625
+ line-height: inherit;
1626
+ }
1627
+
1628
+ button,
1629
+ select {
1630
+ text-transform: none;
1631
+ }
1632
+
1633
+ [role=button] {
1634
+ cursor: pointer;
1635
+ }
1636
+
1637
+ select {
1638
+ word-wrap: normal;
1639
+ }
1640
+ select:disabled {
1641
+ opacity: 1;
1642
+ }
1643
+
1644
+ [list]:not([type=date]):not([type=datetime-local]):not([type=month]):not([type=week]):not([type=time])::-webkit-calendar-picker-indicator {
1645
+ display: none !important;
1646
+ }
1647
+
1648
+ button,
1649
+ [type=button],
1650
+ [type=reset],
1651
+ [type=submit] {
1652
+ -webkit-appearance: button;
1653
+ }
1654
+ button:not(:disabled),
1655
+ [type=button]:not(:disabled),
1656
+ [type=reset]:not(:disabled),
1657
+ [type=submit]:not(:disabled) {
1658
+ cursor: pointer;
1659
+ }
1660
+
1661
+ ::-moz-focus-inner {
1662
+ padding: 0;
1663
+ border-style: none;
1664
+ }
1665
+
1666
+ textarea {
1667
+ resize: vertical;
1668
+ }
1669
+
1670
+ fieldset {
1671
+ min-width: 0;
1672
+ padding: 0;
1673
+ margin: 0;
1674
+ border: 0;
1675
+ }
1676
+
1677
+ ::-webkit-datetime-edit-fields-wrapper,
1678
+ ::-webkit-datetime-edit-text,
1679
+ ::-webkit-datetime-edit-minute,
1680
+ ::-webkit-datetime-edit-hour-field,
1681
+ ::-webkit-datetime-edit-day-field,
1682
+ ::-webkit-datetime-edit-month-field,
1683
+ ::-webkit-datetime-edit-year-field {
1684
+ padding: 0;
1685
+ }
1686
+
1687
+ ::-webkit-inner-spin-button {
1688
+ height: auto;
1689
+ }
1690
+
1691
+ [type=search] {
1692
+ outline-offset: -2px;
1693
+ -webkit-appearance: textfield;
1694
+ }
1695
+
1696
+ /* rtl:raw:
1697
+ [type="tel"],
1698
+ [type="url"],
1699
+ [type="email"],
1700
+ [type="number"] {
1701
+ direction: ltr;
1702
+ }
1703
+ */
1704
+ ::-webkit-search-decoration {
1705
+ -webkit-appearance: none;
1706
+ }
1707
+
1708
+ ::-webkit-color-swatch-wrapper {
1709
+ padding: 0;
1710
+ }
1711
+
1712
+ ::file-selector-button {
1713
+ font: inherit;
1714
+ -webkit-appearance: button;
1715
+ }
1716
+
1717
+ output {
1718
+ display: inline-block;
1719
+ }
1720
+
1721
+ iframe {
1722
+ border: 0;
1723
+ }
1724
+
1725
+ summary {
1726
+ display: list-item;
1727
+ cursor: pointer;
1728
+ }
1729
+
1730
+ progress {
1731
+ vertical-align: baseline;
1732
+ }
1733
+
1734
+ [hidden] {
1735
+ display: none !important;
1736
+ }
1737
+
1307
1738
  body {
1308
1739
  font-family: var(--bsi-font-sans);
1309
1740
  }
@@ -1601,6 +2032,35 @@ blockquote.blockquote-card.dark .blockquote-footer,
1601
2032
  text-transform: uppercase;
1602
2033
  }
1603
2034
 
2035
+ .me-2 {
2036
+ margin-right: 0.5rem !important;
2037
+ }
2038
+
2039
+ @media (min-width: 576px) {
2040
+ .me-sm-2 {
2041
+ margin-right: 0.5rem !important;
2042
+ }
2043
+ }
2044
+ @media (min-width: 768px) {
2045
+ .me-md-2 {
2046
+ margin-right: 0.5rem !important;
2047
+ }
2048
+ }
2049
+ @media (min-width: 992px) {
2050
+ .me-lg-2 {
2051
+ margin-right: 0.5rem !important;
2052
+ }
2053
+ }
2054
+ @media (min-width: 1200px) {
2055
+ .me-xl-2 {
2056
+ margin-right: 0.5rem !important;
2057
+ }
2058
+ }
2059
+ @media (min-width: 1400px) {
2060
+ .me-xxl-2 {
2061
+ margin-right: 0.5rem !important;
2062
+ }
2063
+ }
1604
2064
  /**
1605
2065
  * Copied from bsi reboot
1606
2066
  */
@@ -1611,6 +2071,10 @@ blockquote.blockquote-card.dark .blockquote-footer,
1611
2071
  }
1612
2072
 
1613
2073
  /* END copied from bsi reboot */
2074
+ .notification {
2075
+ z-index: var(--bsi-notification-z-index, 2);
2076
+ }
2077
+
1614
2078
  ::slotted(p) {
1615
2079
  margin-top: var(--bsi-spacing-xxs) !important;
1616
2080
  color: var(--bsi-notification-text-color);
@@ -1633,36 +2097,6 @@ blockquote.blockquote-card.dark .blockquote-footer,
1633
2097
  }
1634
2098
  .notification-close:hover {
1635
2099
  --bsi-icon-default: hsl(210, 100%, 40%);
1636
- }
1637
-
1638
- .me-2 {
1639
- margin-right: 0.5rem !important;
1640
- }
1641
-
1642
- @media (min-width: 576px) {
1643
- .me-sm-2 {
1644
- margin-right: 0.5rem !important;
1645
- }
1646
- }
1647
- @media (min-width: 768px) {
1648
- .me-md-2 {
1649
- margin-right: 0.5rem !important;
1650
- }
1651
- }
1652
- @media (min-width: 992px) {
1653
- .me-lg-2 {
1654
- margin-right: 0.5rem !important;
1655
- }
1656
- }
1657
- @media (min-width: 1200px) {
1658
- .me-xl-2 {
1659
- margin-right: 0.5rem !important;
1660
- }
1661
- }
1662
- @media (min-width: 1400px) {
1663
- .me-xxl-2 {
1664
- margin-right: 0.5rem !important;
1665
- }
1666
2100
  }`;
1667
2101
 
1668
2102
  const translation$1 = {
@@ -1684,6 +2118,14 @@ const translation = {
1684
2118
  var ItNotification_1;
1685
2119
  registerTranslation(translation$1);
1686
2120
  registerTranslation(translation);
2121
+ /**
2122
+ * Componente Notification.
2123
+ *
2124
+ * @element it-notification
2125
+ *
2126
+ * @fires it-notification-show - Quando la notifica viene mostrata
2127
+ * @fires it-notification-close - Quando la notifica viene chiusa (click sul pulsante di chiusura, scomparsa automatica o chiamata a `hide()`)
2128
+ */
1687
2129
  let ItNotification = ItNotification_1 = class ItNotification extends BaseLocalizedComponent {
1688
2130
  constructor() {
1689
2131
  super(...arguments);
@@ -1693,6 +2135,10 @@ let ItNotification = ItNotification_1 = class ItNotification extends BaseLocaliz
1693
2135
  this.timeout = 3000;
1694
2136
  this.isShown = false;
1695
2137
  this.isTransitioning = false;
2138
+ /** Element focused right before `show()` was called (e.g. the button that triggered it).
2139
+ * Restored on `hide()` if focus was left inside the notification (e.g. its close button),
2140
+ * since there is no author-provided trigger slot to fall back on like `it-modal` has. */
2141
+ this._returnFocusTarget = null;
1696
2142
  }
1697
2143
  updated(_changedProperties) {
1698
2144
  super.updated(_changedProperties);
@@ -1713,6 +2159,11 @@ let ItNotification = ItNotification_1 = class ItNotification extends BaseLocaliz
1713
2159
  this.isShown = true;
1714
2160
  if (this.fade)
1715
2161
  this.isTransitioning = true;
2162
+ const previouslyFocused = document.activeElement;
2163
+ this._returnFocusTarget =
2164
+ previouslyFocused && previouslyFocused !== document.body && previouslyFocused !== this
2165
+ ? previouslyFocused
2166
+ : null;
1716
2167
  const timeoutVal = timeout ?? this.timeout;
1717
2168
  this.container.style.display = 'block';
1718
2169
  if (this.fade) {
@@ -1724,6 +2175,15 @@ let ItNotification = ItNotification_1 = class ItNotification extends BaseLocaliz
1724
2175
  this.offsetHeight;
1725
2176
  }
1726
2177
  this.isShown = true;
2178
+ // Inject the flattened slot text into the dedicated live region so that
2179
+ // NVDA/JAWS announce the notification (they do not resolve slotted content
2180
+ // across the shadow boundary at announcement time).
2181
+ this.updateComplete.then(() => this.announce());
2182
+ this.dispatchEvent(new CustomEvent('it-notification-show', {
2183
+ bubbles: true,
2184
+ composed: true,
2185
+ detail: { notification: this },
2186
+ }));
1727
2187
  setTimeout(() => {
1728
2188
  this.isTransitioning = false;
1729
2189
  if (!this.dismissable && timeoutVal) {
@@ -1740,8 +2200,29 @@ let ItNotification = ItNotification_1 = class ItNotification extends BaseLocaliz
1740
2200
  this.isShown = false;
1741
2201
  if (this.fade)
1742
2202
  this.isTransitioning = true;
2203
+ this.dispatchEvent(new CustomEvent('it-notification-close', {
2204
+ bubbles: true,
2205
+ composed: true,
2206
+ detail: { notification: this },
2207
+ }));
1743
2208
  setTimeout(() => {
2209
+ // The container is about to become display:none, which would otherwise silently
2210
+ // drop focus to <body> if it currently holds it (e.g. right after a click on the
2211
+ // close button). Restore it to whatever had focus before show() (e.g. the button
2212
+ // that triggered it) — there is no author-provided trigger slot to target like
2213
+ // it-modal has. Fall back to the nearest focusable ancestor (the it-alert/it-chip
2214
+ // convention) if that element is gone.
2215
+ if (this.shadowRoot?.activeElement) {
2216
+ const target = this._returnFocusTarget && this._returnFocusTarget.isConnected
2217
+ ? this._returnFocusTarget
2218
+ : (focusableFallbackAncestor(this) ?? nearestFocusableInDocument(this));
2219
+ target?.focus();
2220
+ }
2221
+ this._returnFocusTarget = null;
1744
2222
  this.container.style.display = 'none';
2223
+ // Clear the live region so a subsequent show() re-announces even when
2224
+ // the content is identical.
2225
+ this.liveRegion.textContent = '';
1745
2226
  this.isTransitioning = false;
1746
2227
  }, this.fade ? ItNotification_1.TRANSITION_DURATION : 0);
1747
2228
  }
@@ -1751,6 +2232,18 @@ let ItNotification = ItNotification_1 = class ItNotification extends BaseLocaliz
1751
2232
  }
1752
2233
  return 'h2';
1753
2234
  }
2235
+ getSlotText(name) {
2236
+ const selector = name ? `slot[name="${name}"]` : 'slot:not([name])';
2237
+ const slot = this.shadowRoot?.querySelector(selector);
2238
+ return (slot?.assignedNodes({ flatten: true }) ?? [])
2239
+ .map((node) => node.textContent?.trim() ?? '')
2240
+ .filter(Boolean)
2241
+ .join(' ')
2242
+ .trim();
2243
+ }
2244
+ announce() {
2245
+ this.liveRegion.textContent = [this.getSlotText('title'), this.getSlotText()].filter(Boolean).join('. ');
2246
+ }
1754
2247
  render() {
1755
2248
  const classes = this.composeClass('notification', {
1756
2249
  'with-icon': !!this.icon,
@@ -1765,27 +2258,24 @@ let ItNotification = ItNotification_1 = class ItNotification extends BaseLocaliz
1765
2258
  });
1766
2259
  const headingTag = unsafeStatic(this.getHeadingLevel());
1767
2260
  return html `
1768
- <div
1769
- class="${classes}"
1770
- role="alert"
1771
- aria-labelledby="heading"
1772
- part="notification"
1773
- aria-hidden="${ifDefined(this.isShown ? undefined : 'true')}"
1774
- >
1775
- ${html$1 `
1776
- <${headingTag} class=${headingClasses} id="heading" part="title">
1777
- ${this.icon
2261
+ <div role="alert" class="visually-hidden" part="live-region"></div>
2262
+ <div class="${classes}" part="notification">
2263
+ <div aria-hidden="true">
2264
+ ${html$1 `
2265
+ <${headingTag} class=${headingClasses} id=${`${this._id}-heading`} part="title">
2266
+ ${this.icon
1778
2267
  ? html `<it-icon
1779
- class="icon me-2"
1780
- size="sm"
1781
- color=${ifDefined(this.status ? NOTIFICATION_STATUS_COLORS[this.status] : undefined)}
1782
- name="${this.icon}"
1783
- align="none"
1784
- ></it-icon>`
2268
+ class="icon me-2"
2269
+ size="sm"
2270
+ color=${ifDefined(this.status ? NOTIFICATION_STATUS_COLORS[this.status] : undefined)}
2271
+ name="${this.icon}"
2272
+ align="none"
2273
+ ></it-icon>`
1785
2274
  : ''}<slot name="title"></slot>
1786
- </${headingTag}>
1787
- `}
1788
- <slot></slot>
2275
+ </${headingTag}>
2276
+ `}
2277
+ <slot></slot>
2278
+ </div>
1789
2279
  ${this.dismissable
1790
2280
  ? html `
1791
2281
  <button type="button" class="btn notification-close" @click=${this.hide}>
@@ -1831,9 +2321,13 @@ __decorate([
1831
2321
  __metadata("design:type", Number)
1832
2322
  ], ItNotification.prototype, "timeout", void 0);
1833
2323
  __decorate([
1834
- query('[role="alert"]'),
2324
+ query('[part="notification"]'),
1835
2325
  __metadata("design:type", HTMLElement)
1836
2326
  ], ItNotification.prototype, "container", void 0);
2327
+ __decorate([
2328
+ query('[part="live-region"]'),
2329
+ __metadata("design:type", HTMLElement)
2330
+ ], ItNotification.prototype, "liveRegion", void 0);
1837
2331
  __decorate([
1838
2332
  state(),
1839
2333
  __metadata("design:type", Object)