@nanahoshi/mona-ui 0.24.10 → 0.25.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.
Files changed (165) hide show
  1. package/README.md +9 -0
  2. package/chart/README.md +223 -77
  3. package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +11 -10
  4. package/fesm2022/nanahoshi-mona-ui-avatar.mjs +37 -20
  5. package/fesm2022/nanahoshi-mona-ui-breadcrumb.mjs +239 -47
  6. package/fesm2022/nanahoshi-mona-ui-button-group.mjs +184 -31
  7. package/fesm2022/nanahoshi-mona-ui-button.mjs +47 -11
  8. package/fesm2022/nanahoshi-mona-ui-calendar.mjs +17 -13
  9. package/fesm2022/nanahoshi-mona-ui-card.mjs +54 -30
  10. package/fesm2022/nanahoshi-mona-ui-chart.mjs +1909 -666
  11. package/fesm2022/nanahoshi-mona-ui-check-box.mjs +112 -31
  12. package/fesm2022/nanahoshi-mona-ui-chip.mjs +131 -89
  13. package/fesm2022/nanahoshi-mona-ui-circular-progress-bar.mjs +59 -19
  14. package/fesm2022/nanahoshi-mona-ui-collapsible.mjs +118 -41
  15. package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +243 -212
  16. package/fesm2022/nanahoshi-mona-ui-color-palette.mjs +155 -86
  17. package/fesm2022/nanahoshi-mona-ui-color-picker.mjs +161 -131
  18. package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +12 -11
  19. package/fesm2022/nanahoshi-mona-ui-common.mjs +18 -1
  20. package/fesm2022/nanahoshi-mona-ui-date-picker.mjs +10 -9
  21. package/fesm2022/nanahoshi-mona-ui-datetime-picker.mjs +10 -9
  22. package/fesm2022/nanahoshi-mona-ui-dialog.mjs +2 -2
  23. package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +2 -2
  24. package/fesm2022/nanahoshi-mona-ui-dropdown-list.mjs +10 -9
  25. package/fesm2022/nanahoshi-mona-ui-editor.mjs +25 -24
  26. package/fesm2022/nanahoshi-mona-ui-expansion-panel.mjs +202 -33
  27. package/fesm2022/nanahoshi-mona-ui-fieldset.mjs +31 -10
  28. package/fesm2022/nanahoshi-mona-ui-filter.mjs +1 -1
  29. package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-DhKLnW06.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-2tVhD2hK.mjs} +2 -2
  30. package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-voGbKOiB.mjs → nanahoshi-mona-ui-grid-grid-list.component-BAN70Wcn.mjs} +4 -4
  31. package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-HQ1Kv6R9.mjs → nanahoshi-mona-ui-grid-grid-row.component-C_kCaA5b.mjs} +7 -7
  32. package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-PNLJFcuH.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-BsNfrAHz.mjs} +4 -4
  33. package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-BO19AVwC.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-CEfVa7eo.mjs} +27 -29
  34. package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
  35. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +146 -5
  36. package/fesm2022/nanahoshi-mona-ui-internal-filter-input.mjs +2 -2
  37. package/fesm2022/nanahoshi-mona-ui-internal-indicator-icon.mjs +1 -1
  38. package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +5 -5
  39. package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +7 -7
  40. package/fesm2022/nanahoshi-mona-ui-internal.mjs +183 -47
  41. package/fesm2022/nanahoshi-mona-ui-label.mjs +111 -15
  42. package/fesm2022/nanahoshi-mona-ui-list-box.mjs +1 -1
  43. package/fesm2022/nanahoshi-mona-ui-list-view.mjs +1 -1
  44. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +111 -5
  45. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +103 -5
  46. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +103 -5
  47. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +100 -6
  48. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +90 -5
  49. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +103 -5
  50. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +90 -5
  51. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +90 -5
  52. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +103 -5
  53. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +105 -5
  54. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +103 -5
  55. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +90 -5
  56. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +90 -5
  57. package/fesm2022/nanahoshi-mona-ui-menubar.mjs +2 -2
  58. package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +14 -13
  59. package/fesm2022/nanahoshi-mona-ui-notification.mjs +1 -1
  60. package/fesm2022/nanahoshi-mona-ui-numeric-text-box.mjs +13 -12
  61. package/fesm2022/nanahoshi-mona-ui-otp-input.mjs +192 -56
  62. package/fesm2022/nanahoshi-mona-ui-pager.mjs +1 -1
  63. package/fesm2022/nanahoshi-mona-ui-placeholder.mjs +3 -1
  64. package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +2 -2
  65. package/fesm2022/nanahoshi-mona-ui-progress-bar.mjs +60 -29
  66. package/fesm2022/nanahoshi-mona-ui-radio-button.mjs +334 -37
  67. package/fesm2022/nanahoshi-mona-ui-rating.mjs +84 -30
  68. package/fesm2022/nanahoshi-mona-ui-scroll-view.mjs +274 -108
  69. package/fesm2022/nanahoshi-mona-ui-segmented.mjs +127 -37
  70. package/fesm2022/nanahoshi-mona-ui-sheet.mjs +2 -2
  71. package/fesm2022/nanahoshi-mona-ui-sidebar.mjs +595 -170
  72. package/fesm2022/nanahoshi-mona-ui-skeleton.mjs +3 -2
  73. package/fesm2022/nanahoshi-mona-ui-slider.mjs +323 -166
  74. package/fesm2022/nanahoshi-mona-ui-spinner.mjs +167 -82
  75. package/fesm2022/nanahoshi-mona-ui-split-button.mjs +3 -3
  76. package/fesm2022/nanahoshi-mona-ui-splitter.mjs +273 -165
  77. package/fesm2022/nanahoshi-mona-ui-stepper.mjs +219 -132
  78. package/fesm2022/nanahoshi-mona-ui-switch.mjs +84 -32
  79. package/fesm2022/nanahoshi-mona-ui-tabs.mjs +337 -116
  80. package/fesm2022/nanahoshi-mona-ui-text-area.mjs +10 -12
  81. package/fesm2022/nanahoshi-mona-ui-text-box.mjs +21 -8
  82. package/fesm2022/nanahoshi-mona-ui-theme.mjs +444 -88
  83. package/fesm2022/nanahoshi-mona-ui-time-picker.mjs +10 -9
  84. package/fesm2022/nanahoshi-mona-ui-time-selector.mjs +15 -14
  85. package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +17 -3
  86. package/fesm2022/nanahoshi-mona-ui-window.mjs +1 -1
  87. package/i18n/catalogs/en-US.messages.json +90 -5
  88. package/locales/ar-sa/ar-sa.messages.json +90 -5
  89. package/locales/de-de/de-de.messages.json +90 -5
  90. package/locales/es-es/es-es.messages.json +90 -5
  91. package/locales/fr-fr/fr-fr.messages.json +91 -6
  92. package/locales/id-id/id-id.messages.json +90 -5
  93. package/locales/it-it/it-it.messages.json +90 -5
  94. package/locales/ja-jp/ja-jp.messages.json +90 -5
  95. package/locales/ko-kr/ko-kr.messages.json +90 -5
  96. package/locales/pt-br/pt-br.messages.json +90 -5
  97. package/locales/ru-ru/ru-ru.messages.json +90 -5
  98. package/locales/tr-tr/tr-tr.messages.json +90 -5
  99. package/locales/zh-cn/zh-cn.messages.json +90 -5
  100. package/locales/zh-tw/zh-tw.messages.json +90 -5
  101. package/package.json +2 -1
  102. package/styles.css +156 -0
  103. package/types/nanahoshi-mona-ui-auto-complete.d.ts +1 -0
  104. package/types/nanahoshi-mona-ui-avatar.d.ts +18 -11
  105. package/types/nanahoshi-mona-ui-breadcrumb.d.ts +62 -14
  106. package/types/nanahoshi-mona-ui-button-group.d.ts +86 -16
  107. package/types/nanahoshi-mona-ui-button.d.ts +26 -3
  108. package/types/nanahoshi-mona-ui-calendar.d.ts +1 -0
  109. package/types/nanahoshi-mona-ui-card.d.ts +22 -6
  110. package/types/nanahoshi-mona-ui-chart.d.ts +519 -527
  111. package/types/nanahoshi-mona-ui-check-box.d.ts +54 -13
  112. package/types/nanahoshi-mona-ui-chip.d.ts +31 -18
  113. package/types/nanahoshi-mona-ui-circular-progress-bar.d.ts +21 -5
  114. package/types/nanahoshi-mona-ui-collapsible.d.ts +20 -11
  115. package/types/nanahoshi-mona-ui-color-gradient.d.ts +62 -36
  116. package/types/nanahoshi-mona-ui-color-palette.d.ts +65 -27
  117. package/types/nanahoshi-mona-ui-color-picker.d.ts +64 -23
  118. package/types/nanahoshi-mona-ui-combo-box.d.ts +1 -0
  119. package/types/nanahoshi-mona-ui-common.d.ts +28 -2
  120. package/types/nanahoshi-mona-ui-date-picker.d.ts +1 -0
  121. package/types/nanahoshi-mona-ui-datetime-picker.d.ts +1 -0
  122. package/types/nanahoshi-mona-ui-dropdown-list.d.ts +1 -0
  123. package/types/nanahoshi-mona-ui-editor.d.ts +1 -0
  124. package/types/nanahoshi-mona-ui-expansion-panel.d.ts +51 -7
  125. package/types/nanahoshi-mona-ui-fieldset.d.ts +18 -4
  126. package/types/nanahoshi-mona-ui-grid.d.ts +0 -1
  127. package/types/nanahoshi-mona-ui-i18n.d.ts +130 -3
  128. package/types/nanahoshi-mona-ui-internal.d.ts +95 -14
  129. package/types/nanahoshi-mona-ui-label.d.ts +17 -2
  130. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +85 -0
  131. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +85 -0
  132. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +85 -0
  133. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +85 -0
  134. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +85 -0
  135. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +85 -0
  136. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +85 -0
  137. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +85 -0
  138. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +85 -0
  139. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +85 -0
  140. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +85 -0
  141. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +85 -0
  142. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +85 -0
  143. package/types/nanahoshi-mona-ui-multi-select.d.ts +1 -0
  144. package/types/nanahoshi-mona-ui-numeric-text-box.d.ts +1 -0
  145. package/types/nanahoshi-mona-ui-otp-input.d.ts +49 -12
  146. package/types/nanahoshi-mona-ui-placeholder.d.ts +2 -1
  147. package/types/nanahoshi-mona-ui-progress-bar.d.ts +21 -9
  148. package/types/nanahoshi-mona-ui-radio-button.d.ts +165 -20
  149. package/types/nanahoshi-mona-ui-rating.d.ts +21 -6
  150. package/types/nanahoshi-mona-ui-scroll-view.d.ts +59 -27
  151. package/types/nanahoshi-mona-ui-segmented.d.ts +52 -24
  152. package/types/nanahoshi-mona-ui-sidebar.d.ts +104 -41
  153. package/types/nanahoshi-mona-ui-skeleton.d.ts +1 -1
  154. package/types/nanahoshi-mona-ui-slider.d.ts +99 -35
  155. package/types/nanahoshi-mona-ui-spinner.d.ts +9 -5
  156. package/types/nanahoshi-mona-ui-splitter.d.ts +31 -10
  157. package/types/nanahoshi-mona-ui-stepper.d.ts +58 -12
  158. package/types/nanahoshi-mona-ui-switch.d.ts +32 -10
  159. package/types/nanahoshi-mona-ui-tabs.d.ts +75 -20
  160. package/types/nanahoshi-mona-ui-text-area.d.ts +7 -7
  161. package/types/nanahoshi-mona-ui-text-box.d.ts +2 -0
  162. package/types/nanahoshi-mona-ui-theme.d.ts +392 -15
  163. package/types/nanahoshi-mona-ui-time-picker.d.ts +1 -0
  164. package/types/nanahoshi-mona-ui-time-selector.d.ts +1 -0
  165. package/types/nanahoshi-mona-ui-tooltip.d.ts +7 -1
@@ -1,6 +1,6 @@
1
1
  import { PreventableEvent } from '@nanahoshi/mona-ui/common';
2
2
  import * as i0 from '@angular/core';
3
- import { Directive, computed, input, inject, DestroyRef, signal, viewChild, viewChildren, ElementRef, model, output, afterRenderEffect, untracked, afterNextRender, Component, contentChild, TemplateRef, ChangeDetectionStrategy, linkedSignal, contentChildren } from '@angular/core';
3
+ import { Directive, computed, input, inject, DestroyRef, ElementRef, signal, viewChildren, viewChild, model, output, afterRenderEffect, untracked, afterNextRender, Component, contentChild, TemplateRef, booleanAttribute, linkedSignal, contentChildren, effect } from '@angular/core';
4
4
  import { NgTemplateOutlet } from '@angular/common';
5
5
  import { firstOrDefault, select } from '@mirei/ts-collections';
6
6
  import { twMerge } from 'tailwind-merge';
@@ -46,8 +46,7 @@ class TabContentTemplateDirective {
46
46
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TabContentTemplateDirective, decorators: [{
47
47
  type: Directive,
48
48
  args: [{
49
- selector: "ng-template[monaTabContentTemplate]",
50
- standalone: true
49
+ selector: "ng-template[monaTabContentTemplate]"
51
50
  }]
52
51
  }] });
53
52
 
@@ -58,8 +57,7 @@ class TabTitleTemplateDirective {
58
57
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TabTitleTemplateDirective, decorators: [{
59
58
  type: Directive,
60
59
  args: [{
61
- selector: "ng-template[monaTabTitleTemplate]",
62
- standalone: true
60
+ selector: "ng-template[monaTabTitleTemplate]"
63
61
  }]
64
62
  }] });
65
63
 
@@ -97,15 +95,15 @@ const tabListListThemeVariants = cva(`
97
95
  }
98
96
  });
99
97
  const tabListListItemThemeVariants = cva(`
100
- relative flex shrink-0 cursor-pointer outline-none
101
- focus-visible:ring-2 focus-visible:ring-focus-indicator/35
98
+ relative flex shrink-0 cursor-pointer
102
99
  transition-colors duration-(--mona-motion-standard) ease-out
103
100
  `, {
104
101
  variants: {
105
102
  active: {
106
103
  true: `
107
104
  text-foreground font-semibold
108
- after:absolute after:content-[''] after:bg-primary
105
+ after:absolute after:content-[''] after:bg-[var(--mona-indicator-color,var(--color-primary))]
106
+ after:forced-color-adjust-none forced-colors:after:bg-[Highlight]
109
107
  `,
110
108
  false: "text-muted-foreground hover:bg-hover hover:text-foreground"
111
109
  },
@@ -120,9 +118,9 @@ const tabListListItemThemeVariants = cva(`
120
118
  right: "w-full items-center justify-start text-start after:inset-y-0 after:start-0 after:w-[2px]"
121
119
  },
122
120
  size: {
123
- small: "h-8 px-2 text-xs",
124
- medium: "h-9 px-3 text-sm",
125
- large: "h-10 px-4 text-sm"
121
+ small: "h-8 text-xs",
122
+ medium: "h-9 text-sm",
123
+ large: "h-10 text-sm"
126
124
  }
127
125
  },
128
126
  defaultVariants: {
@@ -130,6 +128,34 @@ const tabListListItemThemeVariants = cva(`
130
128
  size: "medium"
131
129
  }
132
130
  });
131
+ /** Inset, because the strip clips anything outside it. */
132
+ const tabListTabThemeVariants = cva(`
133
+ flex h-full min-w-0 flex-1 items-center
134
+ focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus-indicator
135
+ `, {
136
+ variants: {
137
+ position: {
138
+ top: "justify-center whitespace-nowrap",
139
+ bottom: "justify-center whitespace-nowrap",
140
+ left: "justify-start text-start",
141
+ right: "justify-start text-start"
142
+ },
143
+ size: {
144
+ small: "px-2",
145
+ medium: "px-3",
146
+ large: "px-4"
147
+ }
148
+ },
149
+ defaultVariants: {
150
+ position: "top",
151
+ size: "medium"
152
+ }
153
+ });
154
+ /** The icon is 16 pixels. The pseudo-element makes the target 24. */
155
+ const tabListCloseButtonThemeVariants = cva(`
156
+ relative -ms-1 me-2 h-fit w-min self-center px-0
157
+ before:absolute before:-inset-1 before:content-['']
158
+ `);
133
159
  const tabListScrollButtonThemeVariants = cva(`
134
160
  flex self-stretch items-center justify-center px-2
135
161
  text-muted-foreground
@@ -206,23 +232,35 @@ function getTabOrientation(position) {
206
232
  class TabListComponent {
207
233
  #destroyRef;
208
234
  #direction;
235
+ #hostElement;
209
236
  #i18n;
210
- #keydown$;
211
237
  #scrollIntent$;
238
+ /** The tab that focus is in, kept when the tab is removed, so focus can go to the selected tab instead of being lost. */
239
+ #focusedTabId;
212
240
  #resizeObserver;
213
241
  constructor() {
214
242
  this.#destroyRef = inject(DestroyRef);
215
243
  this.#direction = injectComponentDirection();
244
+ this.#hostElement = inject(ElementRef).nativeElement;
216
245
  this.#i18n = inject(MonaI18nService);
217
- this.#keydown$ = new Subject();
218
246
  this.#scrollIntent$ = new Subject();
247
+ /** The tab that focus is in, kept when the tab is removed, so focus can go to the selected tab instead of being lost. */
248
+ this.#focusedTabId = null;
219
249
  this.#resizeObserver = null;
220
- this.isRtl = computed(() => this.#direction() === "rtl", /* @ts-ignore */
221
- ...(ngDevMode ? [{ debugName: "isRtl" }] : /* istanbul ignore next */ []));
222
250
  this.baseClass = computed(() => {
223
251
  return tabListBaseThemeVariants({ position: this.position() });
224
252
  }, /* @ts-ignore */
225
253
  ...(ngDevMode ? [{ debugName: "baseClass" }] : /* istanbul ignore next */ []));
254
+ this.closeButtonClass = computed(() => {
255
+ return tabListCloseButtonThemeVariants();
256
+ }, /* @ts-ignore */
257
+ ...(ngDevMode ? [{ debugName: "closeButtonClass" }] : /* istanbul ignore next */ []));
258
+ this.hasClosableTabs = computed(() => {
259
+ return this.closable() || Array.from(this.tabList()).some(tab => tab.closable);
260
+ }, /* @ts-ignore */
261
+ ...(ngDevMode ? [{ debugName: "hasClosableTabs" }] : /* istanbul ignore next */ []));
262
+ this.isRtl = computed(() => this.#direction() === "rtl", /* @ts-ignore */
263
+ ...(ngDevMode ? [{ debugName: "isRtl" }] : /* istanbul ignore next */ []));
226
264
  this.listClass = computed(() => {
227
265
  return tabListListThemeVariants({ position: this.position() });
228
266
  }, /* @ts-ignore */
@@ -242,9 +280,18 @@ class TabListComponent {
242
280
  return tabListScrollButtonThemeVariants();
243
281
  }, /* @ts-ignore */
244
282
  ...(ngDevMode ? [{ debugName: "scrollButtonClass" }] : /* istanbul ignore next */ []));
283
+ this.tabClass = computed(() => {
284
+ return tabListTabThemeVariants({ position: this.position(), size: this.size() });
285
+ }, /* @ts-ignore */
286
+ ...(ngDevMode ? [{ debugName: "tabClass" }] : /* istanbul ignore next */ []));
287
+ this.tabElements = viewChildren("tabElement", /* @ts-ignore */
288
+ ...(ngDevMode ? [{ debugName: "tabElements" }] : /* istanbul ignore next */ []));
245
289
  this.tabListElement = viewChild.required("tabListElement", /* @ts-ignore */
246
290
  ...(ngDevMode ? [{ debugName: "tabListElement" }] : /* istanbul ignore next */ []));
247
- this.tabListItems = viewChildren(TabListItemDirective, { ...(ngDevMode ? { debugName: "tabListItems" } : /* istanbul ignore next */ {}), read: ElementRef });
291
+ this.ariaLabel = input("", /* @ts-ignore */
292
+ ...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
293
+ this.ariaLabelledBy = input("", /* @ts-ignore */
294
+ ...(ngDevMode ? [{ debugName: "ariaLabelledBy" }] : /* istanbul ignore next */ []));
248
295
  this.closable = input(false, /* @ts-ignore */
249
296
  ...(ngDevMode ? [{ debugName: "closable" }] : /* istanbul ignore next */ []));
250
297
  this.disabled = input(false, /* @ts-ignore */
@@ -269,54 +316,72 @@ class TabListComponent {
269
316
  this.tabSelect = output();
270
317
  afterRenderEffect({
271
318
  read: () => {
272
- this.tabList();
319
+ const tabs = Array.from(this.tabList());
273
320
  this.position();
274
321
  untracked(() => {
275
322
  this.updateScrollVisibility();
323
+ this.restoreFocus(tabs);
276
324
  });
277
325
  }
278
326
  });
279
- this.setupScrolling();
280
- afterNextRender({
281
- write: () => {
282
- const selectedTab = firstOrDefault(this.tabList(), t => t.id === this.selectedTabId());
283
- if (selectedTab) {
284
- this.selectedTabId.set(selectedTab.id);
285
- }
286
- },
327
+ afterRenderEffect({
287
328
  read: () => {
288
- this.setupKeyboardNavigation();
289
- this.setupResizeObserver();
329
+ const selectedId = this.selectedTabId();
330
+ untracked(() => this.scrollTabIntoStrip(selectedId));
290
331
  }
291
332
  });
292
- inject(DestroyRef).onDestroy(() => this.#resizeObserver?.disconnect());
333
+ this.setupScrolling();
334
+ afterNextRender({
335
+ read: () => this.setupResizeObserver()
336
+ });
337
+ this.#destroyRef.onDestroy(() => this.#resizeObserver?.disconnect());
293
338
  }
294
339
  focusSelectedTab() {
295
- const tabList = this.tabList();
296
- const selectedTab = firstOrDefault(tabList, t => t.id === this.selectedTabId());
340
+ const selectedTab = firstOrDefault(this.tabList(), t => t.id === this.selectedTabId());
297
341
  if (selectedTab) {
298
342
  this.focusTab(selectedTab);
299
343
  }
300
344
  }
301
- onKeydown(event) {
302
- this.#keydown$.next(event);
345
+ onFocusIn(event) {
346
+ this.#focusedTabId = event.target.closest("[data-tab-id]")?.getAttribute("data-tab-id") ?? null;
347
+ }
348
+ onFocusOut(event) {
349
+ const target = event.target;
350
+ // Some browsers fire this while removing the focused tab, so only a target that's still there can mean focus left.
351
+ // It runs after the focusin of a move within the strip, which has already recorded where focus went.
352
+ queueMicrotask(() => {
353
+ const root = this.#hostElement.getRootNode();
354
+ if (target.isConnected && !this.#hostElement.contains(root.activeElement)) {
355
+ this.#focusedTabId = null;
356
+ }
357
+ });
303
358
  }
304
- onTabClick(tab, tabListElement, event) {
305
- if (tab.id === this.selectedTabId()) {
359
+ onKeydown(event) {
360
+ if (event.altKey || event.ctrlKey || event.metaKey) {
306
361
  return;
307
362
  }
308
- const selectEvent = new TabSelectEvent(tab.index, event);
309
- this.tabSelect.emit(selectEvent);
310
- if (selectEvent.isDefaultPrevented()) {
363
+ const tabs = Array.from(this.tabList());
364
+ const currentTab = this.tabFromEvent(tabs, event);
365
+ if (!currentTab) {
311
366
  return;
312
367
  }
313
- this.selectTab(tab);
314
- window.setTimeout(() => {
315
- const listElement = tabListElement.querySelector("li[data-selected='true']");
316
- if (listElement) {
317
- listElement.scrollIntoView({ behavior: "auto", block: "nearest", inline: "nearest" });
368
+ if (event.key === "Tab") {
369
+ if (!event.shiftKey) {
370
+ this.handleTabKey(tabs, event);
318
371
  }
319
- });
372
+ return;
373
+ }
374
+ if (!event.shiftKey) {
375
+ this.handleTabStripKey(tabs, currentTab, event);
376
+ }
377
+ }
378
+ onTabClick(tab, event) {
379
+ if (tab.disabled || this.disabled() || tab.id === this.selectedTabId()) {
380
+ return;
381
+ }
382
+ if (!this.emitTabSelect(tab, event)) {
383
+ this.selectTab(tab);
384
+ }
320
385
  }
321
386
  onTabClose(tab, event) {
322
387
  event.stopPropagation();
@@ -332,18 +397,28 @@ class TabListComponent {
332
397
  stopScrolling() {
333
398
  this.#scrollIntent$.next(null);
334
399
  }
400
+ /**
401
+ * Selects the tab and moves focus to it. A vetoed selection still moves focus, so the keyboard can get past a tab it
402
+ * isn't allowed to select.
403
+ */
335
404
  activateTab(tab, event) {
336
- const prevented = this.emitTabSelect(tab, event);
337
- if (!prevented) {
405
+ if (tab.id !== this.selectedTabId() && !this.emitTabSelect(tab, event)) {
338
406
  this.selectTab(tab);
339
- this.focusSelectedTab();
340
407
  }
408
+ this.focusTab(tab);
409
+ }
410
+ adjacentEnabledTab(tabs, from, offset) {
411
+ const start = tabs.indexOf(from);
412
+ for (let step = 1; step <= tabs.length; step++) {
413
+ const candidate = tabs[(start + offset * step + tabs.length * step) % tabs.length];
414
+ if (this.isTabEnabled(candidate)) {
415
+ return candidate;
416
+ }
417
+ }
418
+ return undefined;
341
419
  }
342
420
  emitTabClose(tabItem, event) {
343
- const selected = tabItem.id === this.selectedTabId();
344
- const tabCloseEvent = new TabCloseEvent(tabItem.index, selected, event);
345
- this.tabClose.emit(tabCloseEvent);
346
- return tabCloseEvent.isDefaultPrevented();
421
+ this.tabClose.emit(new TabCloseEvent(tabItem.index, tabItem.id === this.selectedTabId(), event));
347
422
  }
348
423
  emitTabSelect(tab, event) {
349
424
  const selectEvent = new TabSelectEvent(tab.index, event);
@@ -351,9 +426,7 @@ class TabListComponent {
351
426
  return selectEvent.isDefaultPrevented();
352
427
  }
353
428
  focusTab(tab) {
354
- const tabListItems = this.tabListItems();
355
- const tabListItem = tabListItems.find(t => t.nativeElement.getAttribute("data-tab-id") === tab.id);
356
- tabListItem?.nativeElement.focus();
429
+ this.tabElementOf(tab.id)?.focus();
357
430
  }
358
431
  getNavigationDirection(event) {
359
432
  if (this.orientation() === "vertical") {
@@ -374,77 +447,106 @@ class TabListComponent {
374
447
  }
375
448
  return null;
376
449
  }
377
- handleKeyboardEvents(event) {
378
- const tabList = this.tabList();
379
- const tabs = Array.from(tabList);
450
+ handleTabKey(tabs, event) {
380
451
  const selectedTab = tabs.find(t => t.id === this.selectedTabId());
381
452
  if (!selectedTab) {
382
453
  return;
383
454
  }
384
- if (event.key === "Tab") {
385
- if (!event.shiftKey) {
386
- this.handleTabKey(selectedTab, event);
387
- }
388
- return;
455
+ // The root node, because a document lookup finds nothing inside a shadow root.
456
+ const root = this.#hostElement.getRootNode();
457
+ const panel = root.getElementById(selectedTab.id + "-panel");
458
+ if (panel) {
459
+ event.preventDefault();
460
+ panel.focus();
389
461
  }
390
- const listDisabled = this.disabled();
391
- const enabledTabs = tabs.filter(t => !t.disabled && !listDisabled);
462
+ }
463
+ handleTabStripKey(tabs, currentTab, event) {
464
+ const enabledTabs = tabs.filter(t => this.isTabEnabled(t));
392
465
  if (enabledTabs.length === 0) {
393
466
  return;
394
467
  }
395
- const selectedEnabledIndex = enabledTabs.indexOf(selectedTab);
396
- const selectedIndex = selectedEnabledIndex === -1 ? 0 : selectedEnabledIndex;
397
468
  const navigationDirection = this.getNavigationDirection(event);
398
- if (navigationDirection === "previous") {
399
- event.preventDefault();
400
- this.activateTab(enabledTabs[selectedIndex === 0 ? enabledTabs.length - 1 : selectedIndex - 1], event);
401
- return;
402
- }
403
- if (navigationDirection === "next") {
469
+ if (navigationDirection) {
404
470
  event.preventDefault();
405
- this.activateTab(enabledTabs[selectedIndex === enabledTabs.length - 1 ? 0 : selectedIndex + 1], event);
471
+ const target = this.adjacentEnabledTab(tabs, currentTab, navigationDirection === "next" ? 1 : -1);
472
+ if (target) {
473
+ this.activateTab(target, event);
474
+ }
406
475
  return;
407
476
  }
408
477
  switch (event.key) {
409
478
  case "Home":
479
+ event.preventDefault();
410
480
  this.activateTab(enabledTabs[0], event);
411
481
  break;
412
482
  case "End":
483
+ event.preventDefault();
413
484
  this.activateTab(enabledTabs[enabledTabs.length - 1], event);
414
485
  break;
415
486
  case "Delete":
416
487
  case "Backspace":
417
- if (!selectedTab.disabled && !listDisabled && (selectedTab.closable || this.closable())) {
418
- this.emitTabClose(selectedTab, event);
488
+ if (this.isTabEnabled(currentTab) && (currentTab.closable || this.closable())) {
489
+ event.preventDefault();
490
+ this.emitTabClose(currentTab, event);
419
491
  }
420
492
  break;
421
493
  }
422
494
  }
423
- handleTabKey(tab, event) {
424
- event.preventDefault();
425
- const panelId = tab.id + "-panel";
426
- const panel = document.getElementById(panelId);
427
- if (panel) {
428
- panel.focus();
429
- }
495
+ isTabEnabled(tab) {
496
+ return !tab.disabled && !this.disabled();
430
497
  }
431
498
  performScroll(element, direction) {
432
499
  let offset = direction === "previous" ? -100 : 100;
500
+ const reducedMotion = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
501
+ const behavior = reducedMotion ? "auto" : "smooth";
433
502
  if (this.orientation() === "vertical") {
434
- element.scrollBy({ top: offset, behavior: "smooth" });
503
+ element.scrollBy({ top: offset, behavior });
435
504
  return;
436
505
  }
437
506
  if (this.isRtl()) {
438
507
  offset = -offset;
439
508
  }
440
- element.scrollBy({ left: offset, behavior: "smooth" });
509
+ element.scrollBy({ left: offset, behavior });
510
+ }
511
+ restoreFocus(tabs) {
512
+ const focusedTabId = this.#focusedTabId;
513
+ if (focusedTabId === null || tabs.some(tab => tab.id === focusedTabId)) {
514
+ return;
515
+ }
516
+ this.#focusedTabId = null;
517
+ const root = this.#hostElement.getRootNode();
518
+ const active = root.activeElement;
519
+ if (!active || active === this.#hostElement.ownerDocument.body) {
520
+ this.focusSelectedTab();
521
+ }
522
+ }
523
+ /**
524
+ * Scrolls only the strip. `scrollIntoView` would also scroll the page, which a selection made by code, or the first
525
+ * render, has no business doing.
526
+ */
527
+ scrollTabIntoStrip(tabId) {
528
+ const tabElement = tabId === null ? undefined : this.tabElementOf(tabId);
529
+ if (!tabElement) {
530
+ return;
531
+ }
532
+ const list = this.tabListElement().nativeElement;
533
+ const listRect = list.getBoundingClientRect();
534
+ const tabRect = tabElement.getBoundingClientRect();
535
+ if (this.orientation() === "vertical") {
536
+ const top = Math.min(tabRect.top - listRect.top, 0) || Math.max(tabRect.bottom - listRect.bottom, 0);
537
+ if (top !== 0) {
538
+ list.scrollBy({ top });
539
+ }
540
+ return;
541
+ }
542
+ const left = Math.min(tabRect.left - listRect.left, 0) || Math.max(tabRect.right - listRect.right, 0);
543
+ if (left !== 0) {
544
+ list.scrollBy({ left });
545
+ }
441
546
  }
442
547
  selectTab(tab) {
443
548
  this.selectedTabId.set(tab.id);
444
549
  }
445
- setupKeyboardNavigation() {
446
- this.#keydown$.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(event => this.handleKeyboardEvents(event));
447
- }
448
550
  setupResizeObserver() {
449
551
  this.#resizeObserver = new ResizeObserver(entries => {
450
552
  window.requestAnimationFrame(() => {
@@ -468,6 +570,21 @@ class TabListComponent {
468
570
  }))
469
571
  .subscribe();
470
572
  }
573
+ tabElementOf(tabId) {
574
+ return this.tabElements().find(tab => tab.nativeElement.id === tabId + "-tab")?.nativeElement;
575
+ }
576
+ /**
577
+ * The tab a key press applies to: the one focus is in, which may not be the selected one after a vetoed selection.
578
+ * Keys pressed anywhere else in the strip, such as on a close button, belong to no tab.
579
+ */
580
+ tabFromEvent(tabs, event) {
581
+ const target = event.target;
582
+ if (!target) {
583
+ return tabs.find(tab => tab.id === this.selectedTabId());
584
+ }
585
+ const tabElement = target.closest("[role='tab']");
586
+ return tabElement ? tabs.find(tab => tab.id + "-tab" === tabElement.id) : undefined;
587
+ }
471
588
  updateScrollVisibility() {
472
589
  asapScheduler.schedule(() => {
473
590
  const element = this.tabListElement().nativeElement;
@@ -476,7 +593,7 @@ class TabListComponent {
476
593
  });
477
594
  }
478
595
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TabListComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
479
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: TabListComponent, isStandalone: true, selector: "mona-tab-list", inputs: { closable: { classPropertyName: "closable", publicName: "closable", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: true, transformFunction: null }, selectedTabId: { classPropertyName: "selectedTabId", publicName: "selectedTabId", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: true, transformFunction: null }, tabList: { classPropertyName: "tabList", publicName: "tabList", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { selectedTabId: "selectedTabIdChange", tabClose: "tabClose", tabSelect: "tabSelect" }, host: { listeners: { "keydown": "onKeydown($event)" }, properties: { "class": "baseClass()" } }, viewQueries: [{ propertyName: "tabListElement", first: true, predicate: ["tabListElement"], descendants: true, isSignal: true }, { propertyName: "tabListItems", predicate: TabListItemDirective, descendants: true, read: ElementRef, isSignal: true }], ngImport: i0, template: "@if (overflowControlsVisible()) {\n <button\n monaButton\n look=\"link\"\n size=\"small\"\n [class]=\"scrollButtonClass()\"\n [attr.aria-label]=\"messages().scrollPrevious\"\n (click)=\"startScrolling(tabListElement, 'previous', 'single')\"\n (pointerdown)=\"startContinuousScroll($event, tabListElement, 'previous')\"\n (pointerup)=\"stopScrolling()\"\n (pointercancel)=\"stopScrolling()\"\n [attr.aria-hidden]=\"true\"\n tabindex=\"-1\">\n @if (orientation() === 'vertical') {\n <svg lucideChevronUp [size]=\"16\"></svg>\n } @else {\n <svg lucideChevronLeft [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n </button>\n}\n<div [class]=\"listWrapperClass()\">\n <ul [class]=\"listClass()\" #tabListElement role=\"tablist\" [attr.aria-orientation]=\"orientation()\">\n @for (tab of tabList(); track tab) {\n @let selected = tab.id === selectedTabId();\n @let itemDisabled = tab.disabled || disabled();\n <li\n monaTabListItem\n [id]=\"tab.id + '-tab'\"\n [active]=\"selected\"\n [disabled]=\"itemDisabled\"\n [position]=\"position()\"\n [size]=\"size()\"\n role=\"tab\"\n [tabindex]=\"selected ? 0 : -1\"\n [attr.aria-selected]=\"selected\"\n [attr.aria-disabled]=\"itemDisabled\"\n [attr.aria-controls]=\"tab.id + '-panel'\"\n [attr.data-selected]=\"selected\"\n [attr.data-tab-id]=\"tab.id\"\n (click)=\"onTabClick(tab, tabListElement, $event)\">\n <div>\n @if (tab.titleTemplate) {\n <ng-container [ngTemplateOutlet]=\"tab.titleTemplate\"></ng-container>\n } @else {\n <span>{{ tab.title }}</span>\n }\n </div>\n @if (tab.closable || closable()) {\n <button\n monaButton\n look=\"link\"\n [disabled]=\"itemDisabled\"\n [attr.aria-label]=\"messages().closeTab\"\n (click)=\"onTabClose(tab, $event)\"\n class=\"px-0 h-fit ms-1 w-min\"\n tabindex=\"-1\">\n <svg lucideX [size]=\"16\"></svg>\n </button>\n }\n </li>\n }\n </ul>\n</div>\n@if (overflowControlsVisible()) {\n <button\n monaButton\n look=\"link\"\n size=\"small\"\n [class]=\"scrollButtonClass()\"\n [attr.aria-label]=\"messages().scrollNext\"\n (click)=\"startScrolling(tabListElement, 'next', 'single')\"\n (pointerdown)=\"startContinuousScroll($event, tabListElement, 'next')\"\n (pointerup)=\"stopScrolling()\"\n (pointercancel)=\"stopScrolling()\"\n [attr.aria-hidden]=\"true\"\n tabindex=\"-1\">\n @if (orientation() === 'vertical') {\n <svg lucideChevronDown [size]=\"16\"></svg>\n } @else {\n <svg lucideChevronRight [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n </button>\n}\n", dependencies: [{ kind: "directive", type: ButtonDirective, selector: "button[monaButton]", inputs: ["aria-haspopup", "disabled", "iconOnly", "loading", "look", "rounded", "selected", "size", "tabindex", "toggleable", "type", "class"], outputs: ["lookChange", "selectedChange"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: TabListItemDirective, selector: "li[monaTabListItem]", inputs: ["active", "disabled", "position", "size"] }, { kind: "component", type: LucideChevronDown, selector: "svg[lucideChevronDown]" }, { kind: "component", type: LucideChevronLeft, selector: "svg[lucideChevronLeft]" }, { kind: "component", type: LucideChevronRight, selector: "svg[lucideChevronRight]" }, { kind: "component", type: LucideChevronUp, selector: "svg[lucideChevronUp]" }, { kind: "component", type: LucideX, selector: "svg[lucideX]" }] }); }
596
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: TabListComponent, isStandalone: true, selector: "mona-tab-list", inputs: { ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledBy: { classPropertyName: "ariaLabelledBy", publicName: "ariaLabelledBy", isSignal: true, isRequired: false, transformFunction: null }, closable: { classPropertyName: "closable", publicName: "closable", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: true, transformFunction: null }, selectedTabId: { classPropertyName: "selectedTabId", publicName: "selectedTabId", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: true, transformFunction: null }, tabList: { classPropertyName: "tabList", publicName: "tabList", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { selectedTabId: "selectedTabIdChange", tabClose: "tabClose", tabSelect: "tabSelect" }, host: { listeners: { "focusin": "onFocusIn($event)", "focusout": "onFocusOut($event)", "keydown": "onKeydown($event)" }, properties: { "class": "baseClass()" } }, viewQueries: [{ propertyName: "tabElements", predicate: ["tabElement"], descendants: true, isSignal: true }, { propertyName: "tabListElement", first: true, predicate: ["tabListElement"], descendants: true, isSignal: true }], ngImport: i0, template: "@if (overflowControlsVisible()) {\n <button\n monaButton\n type=\"button\"\n look=\"link\"\n size=\"small\"\n [class]=\"scrollButtonClass()\"\n [attr.aria-label]=\"messages().scrollPrevious\"\n (click)=\"startScrolling(tabListElement, 'previous', 'single')\"\n (pointerdown)=\"startContinuousScroll($event, tabListElement, 'previous')\"\n (pointerup)=\"stopScrolling()\"\n (pointercancel)=\"stopScrolling()\"\n [attr.aria-hidden]=\"true\"\n tabindex=\"-1\">\n @if (orientation() === 'vertical') {\n <svg lucideChevronUp [size]=\"16\"></svg>\n } @else {\n <svg lucideChevronLeft [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n </button>\n}\n<div [class]=\"listWrapperClass()\">\n <ul\n [class]=\"listClass()\"\n #tabListElement\n role=\"tablist\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n [attr.aria-orientation]=\"orientation()\">\n @for (tab of tabList(); track tab.id) {\n @let selected = tab.id === selectedTabId();\n @let itemDisabled = tab.disabled || disabled();\n @let tabClosable = tab.closable || closable();\n <li\n monaTabListItem\n [active]=\"selected\"\n [disabled]=\"itemDisabled\"\n [position]=\"position()\"\n [size]=\"size()\"\n role=\"presentation\"\n [attr.data-selected]=\"selected\"\n [attr.data-tab-id]=\"tab.id\">\n <div\n #tabElement\n [class]=\"tabClass()\"\n [id]=\"tab.id + '-tab'\"\n role=\"tab\"\n [tabindex]=\"selected ? 0 : -1\"\n [attr.aria-selected]=\"selected\"\n [attr.aria-disabled]=\"itemDisabled\"\n [attr.aria-controls]=\"tab.id + '-panel'\"\n [attr.aria-keyshortcuts]=\"tabClosable && !itemDisabled ? 'Delete Backspace' : null\"\n (click)=\"onTabClick(tab, $event)\">\n <div>\n @if (tab.titleTemplate) {\n <ng-container [ngTemplateOutlet]=\"tab.titleTemplate\"></ng-container>\n } @else {\n <span>{{ tab.title }}</span>\n }\n </div>\n </div>\n @if (tabClosable) {\n <!-- For the pointer. A button assistive technology can see isn't allowed inside a tablist. -->\n <button\n monaButton\n type=\"button\"\n look=\"link\"\n data-tab-close\n [disabled]=\"itemDisabled\"\n [attr.aria-hidden]=\"true\"\n [attr.aria-label]=\"messages().closeTab\"\n (click)=\"onTabClose(tab, $event)\"\n [class]=\"closeButtonClass()\"\n tabindex=\"-1\">\n <svg lucideX [size]=\"16\"></svg>\n </button>\n }\n </li>\n }\n </ul>\n</div>\n@if (hasClosableTabs()) {\n <!-- The same action for assistive technology, outside the tablist. The keyboard's route is Delete. -->\n <div class=\"sr-only\">\n @for (tab of tabList(); track tab.id) {\n @if (tab.closable || closable()) {\n <button\n type=\"button\"\n tabindex=\"-1\"\n [id]=\"tab.id + '-close'\"\n [disabled]=\"tab.disabled || disabled()\"\n [attr.aria-label]=\"messages().closeTab\"\n [attr.aria-labelledby]=\"tab.id + '-close ' + tab.id + '-tab'\"\n [attr.data-tab-id]=\"tab.id\"\n (click)=\"onTabClose(tab, $event)\"></button>\n }\n }\n </div>\n}\n@if (overflowControlsVisible()) {\n <button\n monaButton\n type=\"button\"\n look=\"link\"\n size=\"small\"\n [class]=\"scrollButtonClass()\"\n [attr.aria-label]=\"messages().scrollNext\"\n (click)=\"startScrolling(tabListElement, 'next', 'single')\"\n (pointerdown)=\"startContinuousScroll($event, tabListElement, 'next')\"\n (pointerup)=\"stopScrolling()\"\n (pointercancel)=\"stopScrolling()\"\n [attr.aria-hidden]=\"true\"\n tabindex=\"-1\">\n @if (orientation() === 'vertical') {\n <svg lucideChevronDown [size]=\"16\"></svg>\n } @else {\n <svg lucideChevronRight [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n </button>\n}\n", dependencies: [{ kind: "directive", type: ButtonDirective, selector: "button[monaButton]", inputs: ["aria-haspopup", "disabled", "iconOnly", "loading", "look", "rounded", "selected", "size", "tabindex", "toggleable", "type", "class", "value"], outputs: ["lookChange", "selectedChange"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: TabListItemDirective, selector: "li[monaTabListItem]", inputs: ["active", "disabled", "position", "size"] }, { kind: "component", type: LucideChevronDown, selector: "svg[lucideChevronDown]" }, { kind: "component", type: LucideChevronLeft, selector: "svg[lucideChevronLeft]" }, { kind: "component", type: LucideChevronRight, selector: "svg[lucideChevronRight]" }, { kind: "component", type: LucideChevronUp, selector: "svg[lucideChevronUp]" }, { kind: "component", type: LucideX, selector: "svg[lucideX]" }] }); }
480
597
  }
481
598
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TabListComponent, decorators: [{
482
599
  type: Component,
@@ -491,9 +608,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
491
608
  LucideX
492
609
  ], host: {
493
610
  "[class]": "baseClass()",
611
+ "(focusin)": "onFocusIn($event)",
612
+ "(focusout)": "onFocusOut($event)",
494
613
  "(keydown)": "onKeydown($event)"
495
- }, template: "@if (overflowControlsVisible()) {\n <button\n monaButton\n look=\"link\"\n size=\"small\"\n [class]=\"scrollButtonClass()\"\n [attr.aria-label]=\"messages().scrollPrevious\"\n (click)=\"startScrolling(tabListElement, 'previous', 'single')\"\n (pointerdown)=\"startContinuousScroll($event, tabListElement, 'previous')\"\n (pointerup)=\"stopScrolling()\"\n (pointercancel)=\"stopScrolling()\"\n [attr.aria-hidden]=\"true\"\n tabindex=\"-1\">\n @if (orientation() === 'vertical') {\n <svg lucideChevronUp [size]=\"16\"></svg>\n } @else {\n <svg lucideChevronLeft [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n </button>\n}\n<div [class]=\"listWrapperClass()\">\n <ul [class]=\"listClass()\" #tabListElement role=\"tablist\" [attr.aria-orientation]=\"orientation()\">\n @for (tab of tabList(); track tab) {\n @let selected = tab.id === selectedTabId();\n @let itemDisabled = tab.disabled || disabled();\n <li\n monaTabListItem\n [id]=\"tab.id + '-tab'\"\n [active]=\"selected\"\n [disabled]=\"itemDisabled\"\n [position]=\"position()\"\n [size]=\"size()\"\n role=\"tab\"\n [tabindex]=\"selected ? 0 : -1\"\n [attr.aria-selected]=\"selected\"\n [attr.aria-disabled]=\"itemDisabled\"\n [attr.aria-controls]=\"tab.id + '-panel'\"\n [attr.data-selected]=\"selected\"\n [attr.data-tab-id]=\"tab.id\"\n (click)=\"onTabClick(tab, tabListElement, $event)\">\n <div>\n @if (tab.titleTemplate) {\n <ng-container [ngTemplateOutlet]=\"tab.titleTemplate\"></ng-container>\n } @else {\n <span>{{ tab.title }}</span>\n }\n </div>\n @if (tab.closable || closable()) {\n <button\n monaButton\n look=\"link\"\n [disabled]=\"itemDisabled\"\n [attr.aria-label]=\"messages().closeTab\"\n (click)=\"onTabClose(tab, $event)\"\n class=\"px-0 h-fit ms-1 w-min\"\n tabindex=\"-1\">\n <svg lucideX [size]=\"16\"></svg>\n </button>\n }\n </li>\n }\n </ul>\n</div>\n@if (overflowControlsVisible()) {\n <button\n monaButton\n look=\"link\"\n size=\"small\"\n [class]=\"scrollButtonClass()\"\n [attr.aria-label]=\"messages().scrollNext\"\n (click)=\"startScrolling(tabListElement, 'next', 'single')\"\n (pointerdown)=\"startContinuousScroll($event, tabListElement, 'next')\"\n (pointerup)=\"stopScrolling()\"\n (pointercancel)=\"stopScrolling()\"\n [attr.aria-hidden]=\"true\"\n tabindex=\"-1\">\n @if (orientation() === 'vertical') {\n <svg lucideChevronDown [size]=\"16\"></svg>\n } @else {\n <svg lucideChevronRight [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n </button>\n}\n" }]
496
- }], ctorParameters: () => [], propDecorators: { tabListElement: [{ type: i0.ViewChild, args: ["tabListElement", { isSignal: true }] }], tabListItems: [{ type: i0.ViewChildren, args: [i0.forwardRef(() => TabListItemDirective), { ...{ read: ElementRef }, isSignal: true }] }], closable: [{ type: i0.Input, args: [{ isSignal: true, alias: "closable", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: true }] }], selectedTabId: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedTabId", required: false }] }, { type: i0.Output, args: ["selectedTabIdChange"] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: true }] }], tabClose: [{ type: i0.Output, args: ["tabClose"] }], tabList: [{ type: i0.Input, args: [{ isSignal: true, alias: "tabList", required: true }] }], tabSelect: [{ type: i0.Output, args: ["tabSelect"] }] } });
614
+ }, template: "@if (overflowControlsVisible()) {\n <button\n monaButton\n type=\"button\"\n look=\"link\"\n size=\"small\"\n [class]=\"scrollButtonClass()\"\n [attr.aria-label]=\"messages().scrollPrevious\"\n (click)=\"startScrolling(tabListElement, 'previous', 'single')\"\n (pointerdown)=\"startContinuousScroll($event, tabListElement, 'previous')\"\n (pointerup)=\"stopScrolling()\"\n (pointercancel)=\"stopScrolling()\"\n [attr.aria-hidden]=\"true\"\n tabindex=\"-1\">\n @if (orientation() === 'vertical') {\n <svg lucideChevronUp [size]=\"16\"></svg>\n } @else {\n <svg lucideChevronLeft [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n </button>\n}\n<div [class]=\"listWrapperClass()\">\n <ul\n [class]=\"listClass()\"\n #tabListElement\n role=\"tablist\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n [attr.aria-orientation]=\"orientation()\">\n @for (tab of tabList(); track tab.id) {\n @let selected = tab.id === selectedTabId();\n @let itemDisabled = tab.disabled || disabled();\n @let tabClosable = tab.closable || closable();\n <li\n monaTabListItem\n [active]=\"selected\"\n [disabled]=\"itemDisabled\"\n [position]=\"position()\"\n [size]=\"size()\"\n role=\"presentation\"\n [attr.data-selected]=\"selected\"\n [attr.data-tab-id]=\"tab.id\">\n <div\n #tabElement\n [class]=\"tabClass()\"\n [id]=\"tab.id + '-tab'\"\n role=\"tab\"\n [tabindex]=\"selected ? 0 : -1\"\n [attr.aria-selected]=\"selected\"\n [attr.aria-disabled]=\"itemDisabled\"\n [attr.aria-controls]=\"tab.id + '-panel'\"\n [attr.aria-keyshortcuts]=\"tabClosable && !itemDisabled ? 'Delete Backspace' : null\"\n (click)=\"onTabClick(tab, $event)\">\n <div>\n @if (tab.titleTemplate) {\n <ng-container [ngTemplateOutlet]=\"tab.titleTemplate\"></ng-container>\n } @else {\n <span>{{ tab.title }}</span>\n }\n </div>\n </div>\n @if (tabClosable) {\n <!-- For the pointer. A button assistive technology can see isn't allowed inside a tablist. -->\n <button\n monaButton\n type=\"button\"\n look=\"link\"\n data-tab-close\n [disabled]=\"itemDisabled\"\n [attr.aria-hidden]=\"true\"\n [attr.aria-label]=\"messages().closeTab\"\n (click)=\"onTabClose(tab, $event)\"\n [class]=\"closeButtonClass()\"\n tabindex=\"-1\">\n <svg lucideX [size]=\"16\"></svg>\n </button>\n }\n </li>\n }\n </ul>\n</div>\n@if (hasClosableTabs()) {\n <!-- The same action for assistive technology, outside the tablist. The keyboard's route is Delete. -->\n <div class=\"sr-only\">\n @for (tab of tabList(); track tab.id) {\n @if (tab.closable || closable()) {\n <button\n type=\"button\"\n tabindex=\"-1\"\n [id]=\"tab.id + '-close'\"\n [disabled]=\"tab.disabled || disabled()\"\n [attr.aria-label]=\"messages().closeTab\"\n [attr.aria-labelledby]=\"tab.id + '-close ' + tab.id + '-tab'\"\n [attr.data-tab-id]=\"tab.id\"\n (click)=\"onTabClose(tab, $event)\"></button>\n }\n }\n </div>\n}\n@if (overflowControlsVisible()) {\n <button\n monaButton\n type=\"button\"\n look=\"link\"\n size=\"small\"\n [class]=\"scrollButtonClass()\"\n [attr.aria-label]=\"messages().scrollNext\"\n (click)=\"startScrolling(tabListElement, 'next', 'single')\"\n (pointerdown)=\"startContinuousScroll($event, tabListElement, 'next')\"\n (pointerup)=\"stopScrolling()\"\n (pointercancel)=\"stopScrolling()\"\n [attr.aria-hidden]=\"true\"\n tabindex=\"-1\">\n @if (orientation() === 'vertical') {\n <svg lucideChevronDown [size]=\"16\"></svg>\n } @else {\n <svg lucideChevronRight [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n </button>\n}\n" }]
615
+ }], ctorParameters: () => [], propDecorators: { tabElements: [{ type: i0.ViewChildren, args: ["tabElement", { isSignal: true }] }], tabListElement: [{ type: i0.ViewChild, args: ["tabListElement", { isSignal: true }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: false }] }], ariaLabelledBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabelledBy", required: false }] }], closable: [{ type: i0.Input, args: [{ isSignal: true, alias: "closable", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: true }] }], selectedTabId: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedTabId", required: false }] }, { type: i0.Output, args: ["selectedTabIdChange"] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: true }] }], tabClose: [{ type: i0.Output, args: ["tabClose"] }], tabList: [{ type: i0.Input, args: [{ isSignal: true, alias: "tabList", required: true }] }], tabSelect: [{ type: i0.Output, args: ["tabSelect"] }] } });
497
616
 
498
617
  class TabComponent {
499
618
  constructor() {
@@ -522,20 +641,21 @@ class TabComponent {
522
641
  this.contentTemplate = contentChild(TabContentTemplateDirective, { ...(ngDevMode ? { debugName: "contentTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
523
642
  this.titleTemplate = contentChild(TabTitleTemplateDirective, { ...(ngDevMode ? { debugName: "titleTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
524
643
  /**
525
- * @description Displays a close button on this tab. Overrides the parent `mona-tabs` component's `closable` input.
644
+ * @description Displays a close button on this tab. Turning it on here shows the button even when the parent
645
+ * `mona-tabs` has `closable` off; turning it off here doesn't hide a button the parent asked for.
526
646
  * @default false
527
647
  */
528
- this.closable = input(false, /* @ts-ignore */
529
- ...(ngDevMode ? [{ debugName: "closable" }] : /* istanbul ignore next */ []));
648
+ this.closable = input(false, { ...(ngDevMode ? { debugName: "closable" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
530
649
  /**
531
- * @description Renders this tab with reduced visual emphasis and removes pointer and keyboard interaction.
532
- * Overrides the parent `mona-tabs` component's `disabled` input.
650
+ * @description Renders this tab with reduced visual emphasis and removes pointer and keyboard interaction. A tab is
651
+ * disabled when this or the parent `mona-tabs` component's `disabled` input is on.
533
652
  * @default false
534
653
  */
535
- this.disabled = input(false, /* @ts-ignore */
536
- ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
654
+ this.disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
537
655
  /**
538
- * @description Whether the tab is selected.
656
+ * @description Whether the tab is selected. Setting it to `true` selects the tab unless it's disabled, and it
657
+ * follows the selection, so `[(selected)]` stays current. Setting it to `false` doesn't clear the selection, because
658
+ * a group of tabs always keeps one selected.
539
659
  * @default false
540
660
  */
541
661
  this.selected = model(false, /* @ts-ignore */
@@ -549,23 +669,46 @@ class TabComponent {
549
669
  }
550
670
  #id;
551
671
  #tabItem;
672
+ /**
673
+ * @internal
674
+ */
552
675
  get tabItem() {
553
676
  return this.#tabItem();
554
677
  }
555
678
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TabComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
556
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.6", type: TabComponent, isStandalone: true, selector: "mona-tab", inputs: { closable: { classPropertyName: "closable", publicName: "closable", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, selected: { classPropertyName: "selected", publicName: "selected", isSignal: true, isRequired: false, transformFunction: null }, title: { classPropertyName: "title", publicName: "title", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { selected: "selectedChange" }, queries: [{ propertyName: "contentTemplate", first: true, predicate: TabContentTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "titleTemplate", first: true, predicate: TabTitleTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }], ngImport: i0, template: "", isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
679
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.6", type: TabComponent, isStandalone: true, selector: "mona-tab", inputs: { closable: { classPropertyName: "closable", publicName: "closable", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, selected: { classPropertyName: "selected", publicName: "selected", isSignal: true, isRequired: false, transformFunction: null }, title: { classPropertyName: "title", publicName: "title", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { selected: "selectedChange" }, queries: [{ propertyName: "contentTemplate", first: true, predicate: TabContentTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "titleTemplate", first: true, predicate: TabTitleTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }], ngImport: i0, template: "", isInline: true }); }
557
680
  }
558
681
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TabComponent, decorators: [{
559
682
  type: Component,
560
683
  args: [{
561
684
  selector: "mona-tab",
562
- template: "",
563
- changeDetection: ChangeDetectionStrategy.OnPush
685
+ template: ""
564
686
  }]
565
687
  }], propDecorators: { contentTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => TabContentTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], titleTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => TabTitleTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], closable: [{ type: i0.Input, args: [{ isSignal: true, alias: "closable", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], selected: [{ type: i0.Input, args: [{ isSignal: true, alias: "selected", required: false }] }, { type: i0.Output, args: ["selectedChange"] }], title: [{ type: i0.Input, args: [{ isSignal: true, alias: "title", required: false }] }] } });
566
688
 
689
+ function isEnabled(tab) {
690
+ return !tab.disabled;
691
+ }
692
+ /** The tab to select after the selected one is gone: the one that took its place, else the nearest before it. */
693
+ function neighborOf(tabs, removedIndex) {
694
+ return tabs.slice(removedIndex).find(isEnabled) ?? tabs.slice(0, removedIndex).reverse().find(isEnabled);
695
+ }
567
696
  class TabsComponent {
697
+ #flaggedTabId;
698
+ #reportedIndex;
699
+ /**
700
+ * Whether the tabs have rendered. A tab in an `@for` gets its inputs after this component first reads it, so until then
701
+ * a selection is only a first guess, and a tab that turns out to be disabled was never really selected.
702
+ */
703
+ #tabsSettled;
568
704
  constructor() {
705
+ this.#flaggedTabId = null;
706
+ this.#reportedIndex = null;
707
+ /**
708
+ * Whether the tabs have rendered. A tab in an `@for` gets its inputs after this component first reads it, so until then
709
+ * a selection is only a first guess, and a tab that turns out to be disabled was never really selected.
710
+ */
711
+ this.#tabsSettled = false;
569
712
  this.baseClass = computed(() => {
570
713
  const variantClass = tabsBaseThemeVariants({ position: this.position() });
571
714
  const userClass = this.userClass();
@@ -578,11 +721,17 @@ class TabsComponent {
578
721
  ...(ngDevMode ? [{ debugName: "contentClass" }] : /* istanbul ignore next */ []));
579
722
  this.selectedTabId = linkedSignal({ ...(ngDevMode ? { debugName: "selectedTabId" } : /* istanbul ignore next */ {}), source: () => this.tabList(),
580
723
  computation: (tabList, previous) => {
581
- const previousId = previous?.value;
582
- if (previousId && tabList.any(t => t.id === previousId)) {
724
+ const tabs = tabList.toArray();
725
+ const previousId = previous?.value ?? null;
726
+ if (previousId === null || !this.#tabsSettled) {
727
+ const requested = tabs[untracked(this.selectedIndex)];
728
+ return (requested && isEnabled(requested) ? requested : tabs.find(isEnabled))?.id ?? null;
729
+ }
730
+ if (tabs.some(tab => tab.id === previousId)) {
583
731
  return previousId;
584
732
  }
585
- return tabList.firstOrDefault()?.id ?? null;
733
+ const removedIndex = previous?.source.toArray().findIndex(tab => tab.id === previousId) ?? 0;
734
+ return neighborOf(tabs, removedIndex)?.id ?? null;
586
735
  } });
587
736
  this.tabList = computed(() => {
588
737
  const tabs = this.tabs();
@@ -596,29 +745,44 @@ class TabsComponent {
596
745
  this.tabs = contentChildren(TabComponent, /* @ts-ignore */
597
746
  ...(ngDevMode ? [{ debugName: "tabs" }] : /* istanbul ignore next */ []));
598
747
  /**
599
- * @description Displays a close button on each tab, unless overridden per tab.
748
+ * @description Accessible name for the tab list.
749
+ * @default ""
750
+ */
751
+ this.ariaLabel = input("", { ...(ngDevMode ? { debugName: "ariaLabel" } : /* istanbul ignore next */ {}), alias: "aria-label" });
752
+ /**
753
+ * @description The id of an element that names the tab list. Takes precedence over `aria-label`.
754
+ * @default ""
755
+ */
756
+ this.ariaLabelledBy = input("", { ...(ngDevMode ? { debugName: "ariaLabelledBy" } : /* istanbul ignore next */ {}), alias: "aria-labelledby" });
757
+ /**
758
+ * @description Displays a close button on each tab. A tab's own `closable` can add a button, not remove this one.
600
759
  * @default false
601
760
  */
602
- this.closable = input(false, /* @ts-ignore */
603
- ...(ngDevMode ? [{ debugName: "closable" }] : /* istanbul ignore next */ []));
761
+ this.closable = input(false, { ...(ngDevMode ? { debugName: "closable" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
604
762
  /**
605
763
  * @description Renders every tab with reduced visual emphasis and removes pointer and keyboard interaction.
606
764
  * @default false
607
765
  */
608
- this.disabled = input(false, /* @ts-ignore */
609
- ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
766
+ this.disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
610
767
  /**
611
768
  * @description Keeps a tab's content in the DOM after it is deselected instead of removing it.
612
769
  * @default true
613
770
  */
614
- this.keepTabContent = input(true, /* @ts-ignore */
615
- ...(ngDevMode ? [{ debugName: "keepTabContent" }] : /* istanbul ignore next */ []));
771
+ this.keepTabContent = input(true, { ...(ngDevMode ? { debugName: "keepTabContent" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
616
772
  /**
617
773
  * @description Placement of the tab list relative to the tab content.
618
774
  * @default "top"
619
775
  */
620
776
  this.position = input("top", /* @ts-ignore */
621
777
  ...(ngDevMode ? [{ debugName: "position" }] : /* istanbul ignore next */ []));
778
+ /**
779
+ * @description The zero-based index of the selected tab. Writing it selects that tab, unless it's disabled or out of
780
+ * range, in which case the value goes back to the selected tab's index. It also changes when the component moves the
781
+ * selection itself, such as when the selected tab is removed.
782
+ * @default 0
783
+ */
784
+ this.selectedIndex = model(0, /* @ts-ignore */
785
+ ...(ngDevMode ? [{ debugName: "selectedIndex" }] : /* istanbul ignore next */ []));
622
786
  /**
623
787
  * @description Size preset controlling the tabs' dimensions.
624
788
  * @default "medium"
@@ -626,11 +790,13 @@ class TabsComponent {
626
790
  this.size = input("medium", /* @ts-ignore */
627
791
  ...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
628
792
  /**
629
- * @description Emitted with a {@link TabCloseEvent} when a tab is closed.
793
+ * @description Emitted with a {@link TabCloseEvent} when a close is requested. The component doesn't remove the tab:
794
+ * remove it from whatever renders the `mona-tab` elements.
630
795
  */
631
796
  this.tabClose = output();
632
797
  /**
633
- * @description Emitted with a {@link TabSelectEvent} when a tab is selected. This event is preventable.
798
+ * @description Emitted with a {@link TabSelectEvent} before a click or key selects a tab. This event is preventable.
799
+ * It doesn't fire for selections made through `selectedIndex` or `selected`, or when the selected tab is removed.
634
800
  */
635
801
  this.tabSelect = output();
636
802
  /**
@@ -638,6 +804,20 @@ class TabsComponent {
638
804
  * @default ""
639
805
  */
640
806
  this.userClass = input("", { ...(ngDevMode ? { debugName: "userClass" } : /* istanbul ignore next */ {}), alias: "class" });
807
+ effect(() => {
808
+ const requested = this.selectedIndex();
809
+ untracked(() => this.applyRequestedIndex(requested));
810
+ });
811
+ effect(() => {
812
+ const items = this.tabList().toArray();
813
+ const selectedId = this.selectedTabId();
814
+ untracked(() => this.syncSelection(items, selectedId));
815
+ });
816
+ afterRenderEffect({
817
+ read: () => {
818
+ this.#tabsSettled = this.tabList().length > 0;
819
+ }
820
+ });
641
821
  }
642
822
  handlePanelKeyDown(event) {
643
823
  if (event.key === "Tab" && event.shiftKey) {
@@ -648,15 +828,56 @@ class TabsComponent {
648
828
  this.tabListComponent().focusSelectedTab();
649
829
  }
650
830
  }
831
+ applyRequestedIndex(requested) {
832
+ if (requested === this.#reportedIndex) {
833
+ return;
834
+ }
835
+ const items = this.tabList().toArray();
836
+ if (items.length === 0) {
837
+ return; // Tabs may still be on their way, and the linked signal reads the index when they arrive.
838
+ }
839
+ const tab = items[requested];
840
+ if (tab && isEnabled(tab)) {
841
+ this.selectedTabId.set(tab.id);
842
+ }
843
+ this.reportIndex(items, this.selectedTabId());
844
+ }
845
+ reportIndex(items, selectedId) {
846
+ const index = items.findIndex(item => item.id === selectedId);
847
+ if (index !== -1) {
848
+ this.#reportedIndex = index;
849
+ this.selectedIndex.set(index);
850
+ }
851
+ }
852
+ /**
853
+ * Brings the three views of the selection together. A tab newly flagged `selected` from outside wins, and the first
854
+ * one wins when there are several. Every tab's `selected` and the index are then written to match, so a flag that was
855
+ * already seen, or one this method wrote, can't take the selection back.
856
+ */
857
+ syncSelection(items, selectedId) {
858
+ const incoming = items.find(item => item.selected && item.id !== this.#flaggedTabId && item.id !== selectedId && isEnabled(item));
859
+ const nextId = incoming?.id ?? selectedId;
860
+ if (incoming) {
861
+ this.selectedTabId.set(incoming.id);
862
+ }
863
+ this.#flaggedTabId = nextId;
864
+ for (const tab of this.tabs()) {
865
+ tab.selected.set(tab.tabItem.id === nextId);
866
+ }
867
+ this.reportIndex(items, nextId);
868
+ }
651
869
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TabsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
652
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: TabsComponent, isStandalone: true, selector: "mona-tabs", inputs: { closable: { classPropertyName: "closable", publicName: "closable", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, keepTabContent: { classPropertyName: "keepTabContent", publicName: "keepTabContent", isSignal: true, isRequired: false, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, userClass: { classPropertyName: "userClass", publicName: "class", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { tabClose: "tabClose", tabSelect: "tabSelect" }, host: { properties: { "class": "baseClass()" } }, queries: [{ propertyName: "tabs", predicate: TabComponent, isSignal: true }], viewQueries: [{ propertyName: "tabListComponent", first: true, predicate: TabListComponent, descendants: true, isSignal: true }], ngImport: i0, template: "<mona-tab-list\n [closable]=\"closable()\"\n [disabled]=\"disabled()\"\n [position]=\"position()\"\n [size]=\"size()\"\n [tabList]=\"tabList()\"\n [selectedTabId]=\"selectedTabId()\"\n (selectedTabIdChange)=\"selectedTabId.set($event)\"\n (tabClose)=\"tabClose.emit($event)\"\n (tabSelect)=\"tabSelect.emit($event)\"></mona-tab-list>\n<div [class]=\"contentClass()\">\n @for (tab of tabList(); track tab) {\n @let selected = tab.id === selectedTabId();\n @let tabLoaded = keepTabContent() || selected;\n @let tabHidden = keepTabContent() && !selected;\n @if (tabLoaded) {\n <div\n class=\"w-full h-full outline-none rounded-sm focus-visible:outline-2 focus-visible:outline-focus-indicator focus-visible:outline-offset-2\"\n [class.hidden]=\"tabHidden\"\n role=\"tabpanel\"\n [id]=\"tab.id + '-panel'\"\n tabindex=\"0\"\n (keydown)=\"handlePanelKeyDown($event)\"\n [attr.aria-hidden]=\"tabHidden\"\n [attr.aria-labelledby]=\"tab.id + '-tab'\">\n <ng-container [ngTemplateOutlet]=\"tab.contentTemplate\"></ng-container>\n </div>\n }\n }\n</div>\n", dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: TabListComponent, selector: "mona-tab-list", inputs: ["closable", "disabled", "position", "selectedTabId", "size", "tabList"], outputs: ["selectedTabIdChange", "tabClose", "tabSelect"] }] }); }
870
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: TabsComponent, isStandalone: true, selector: "mona-tabs", inputs: { ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledBy: { classPropertyName: "ariaLabelledBy", publicName: "aria-labelledby", isSignal: true, isRequired: false, transformFunction: null }, closable: { classPropertyName: "closable", publicName: "closable", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, keepTabContent: { classPropertyName: "keepTabContent", publicName: "keepTabContent", isSignal: true, isRequired: false, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, selectedIndex: { classPropertyName: "selectedIndex", publicName: "selectedIndex", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, userClass: { classPropertyName: "userClass", publicName: "class", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { selectedIndex: "selectedIndexChange", tabClose: "tabClose", tabSelect: "tabSelect" }, host: { properties: { "class": "baseClass()", "attr.aria-label": "null", "attr.aria-labelledby": "null" } }, queries: [{ propertyName: "tabs", predicate: TabComponent, isSignal: true }], viewQueries: [{ propertyName: "tabListComponent", first: true, predicate: TabListComponent, descendants: true, isSignal: true }], ngImport: i0, template: "<mona-tab-list\n [ariaLabel]=\"ariaLabel()\"\n [ariaLabelledBy]=\"ariaLabelledBy()\"\n [closable]=\"closable()\"\n [disabled]=\"disabled()\"\n [position]=\"position()\"\n [size]=\"size()\"\n [tabList]=\"tabList()\"\n [selectedTabId]=\"selectedTabId()\"\n (selectedTabIdChange)=\"selectedTabId.set($event)\"\n (tabClose)=\"tabClose.emit($event)\"\n (tabSelect)=\"tabSelect.emit($event)\"></mona-tab-list>\n<div [class]=\"contentClass()\">\n @for (tab of tabList(); track tab.id) {\n @let selected = tab.id === selectedTabId();\n @let tabLoaded = keepTabContent() || selected;\n @let tabHidden = keepTabContent() && !selected;\n @if (tabLoaded) {\n <div\n class=\"w-full h-full rounded-sm focus-visible:outline-2 focus-visible:outline-focus-indicator focus-visible:-outline-offset-2\"\n [class.hidden]=\"tabHidden\"\n role=\"tabpanel\"\n [id]=\"tab.id + '-panel'\"\n tabindex=\"0\"\n (keydown)=\"handlePanelKeyDown($event)\"\n [attr.aria-hidden]=\"tabHidden\"\n [attr.aria-labelledby]=\"tab.id + '-tab'\">\n <ng-container [ngTemplateOutlet]=\"tab.contentTemplate\"></ng-container>\n </div>\n }\n }\n</div>\n", dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: TabListComponent, selector: "mona-tab-list", inputs: ["ariaLabel", "ariaLabelledBy", "closable", "disabled", "position", "selectedTabId", "size", "tabList"], outputs: ["selectedTabIdChange", "tabClose", "tabSelect"] }] }); }
653
871
  }
654
872
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TabsComponent, decorators: [{
655
873
  type: Component,
656
874
  args: [{ selector: "mona-tabs", imports: [NgTemplateOutlet, TabListComponent], host: {
657
- "[class]": "baseClass()"
658
- }, template: "<mona-tab-list\n [closable]=\"closable()\"\n [disabled]=\"disabled()\"\n [position]=\"position()\"\n [size]=\"size()\"\n [tabList]=\"tabList()\"\n [selectedTabId]=\"selectedTabId()\"\n (selectedTabIdChange)=\"selectedTabId.set($event)\"\n (tabClose)=\"tabClose.emit($event)\"\n (tabSelect)=\"tabSelect.emit($event)\"></mona-tab-list>\n<div [class]=\"contentClass()\">\n @for (tab of tabList(); track tab) {\n @let selected = tab.id === selectedTabId();\n @let tabLoaded = keepTabContent() || selected;\n @let tabHidden = keepTabContent() && !selected;\n @if (tabLoaded) {\n <div\n class=\"w-full h-full outline-none rounded-sm focus-visible:outline-2 focus-visible:outline-focus-indicator focus-visible:outline-offset-2\"\n [class.hidden]=\"tabHidden\"\n role=\"tabpanel\"\n [id]=\"tab.id + '-panel'\"\n tabindex=\"0\"\n (keydown)=\"handlePanelKeyDown($event)\"\n [attr.aria-hidden]=\"tabHidden\"\n [attr.aria-labelledby]=\"tab.id + '-tab'\">\n <ng-container [ngTemplateOutlet]=\"tab.contentTemplate\"></ng-container>\n </div>\n }\n }\n</div>\n" }]
659
- }], propDecorators: { tabListComponent: [{ type: i0.ViewChild, args: [i0.forwardRef(() => TabListComponent), { isSignal: true }] }], tabs: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => TabComponent), { isSignal: true }] }], closable: [{ type: i0.Input, args: [{ isSignal: true, alias: "closable", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], keepTabContent: [{ type: i0.Input, args: [{ isSignal: true, alias: "keepTabContent", required: false }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], tabClose: [{ type: i0.Output, args: ["tabClose"] }], tabSelect: [{ type: i0.Output, args: ["tabSelect"] }], userClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }] } });
875
+ "[class]": "baseClass()",
876
+ // The name belongs to the tab list. Left on a host with no role, it would name nothing.
877
+ "[attr.aria-label]": "null",
878
+ "[attr.aria-labelledby]": "null"
879
+ }, template: "<mona-tab-list\n [ariaLabel]=\"ariaLabel()\"\n [ariaLabelledBy]=\"ariaLabelledBy()\"\n [closable]=\"closable()\"\n [disabled]=\"disabled()\"\n [position]=\"position()\"\n [size]=\"size()\"\n [tabList]=\"tabList()\"\n [selectedTabId]=\"selectedTabId()\"\n (selectedTabIdChange)=\"selectedTabId.set($event)\"\n (tabClose)=\"tabClose.emit($event)\"\n (tabSelect)=\"tabSelect.emit($event)\"></mona-tab-list>\n<div [class]=\"contentClass()\">\n @for (tab of tabList(); track tab.id) {\n @let selected = tab.id === selectedTabId();\n @let tabLoaded = keepTabContent() || selected;\n @let tabHidden = keepTabContent() && !selected;\n @if (tabLoaded) {\n <div\n class=\"w-full h-full rounded-sm focus-visible:outline-2 focus-visible:outline-focus-indicator focus-visible:-outline-offset-2\"\n [class.hidden]=\"tabHidden\"\n role=\"tabpanel\"\n [id]=\"tab.id + '-panel'\"\n tabindex=\"0\"\n (keydown)=\"handlePanelKeyDown($event)\"\n [attr.aria-hidden]=\"tabHidden\"\n [attr.aria-labelledby]=\"tab.id + '-tab'\">\n <ng-container [ngTemplateOutlet]=\"tab.contentTemplate\"></ng-container>\n </div>\n }\n }\n</div>\n" }]
880
+ }], ctorParameters: () => [], propDecorators: { tabListComponent: [{ type: i0.ViewChild, args: [i0.forwardRef(() => TabListComponent), { isSignal: true }] }], tabs: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => TabComponent), { isSignal: true }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-label", required: false }] }], ariaLabelledBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-labelledby", required: false }] }], closable: [{ type: i0.Input, args: [{ isSignal: true, alias: "closable", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], keepTabContent: [{ type: i0.Input, args: [{ isSignal: true, alias: "keepTabContent", required: false }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], selectedIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedIndex", required: false }] }, { type: i0.Output, args: ["selectedIndexChange"] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], tabClose: [{ type: i0.Output, args: ["tabClose"] }], tabSelect: [{ type: i0.Output, args: ["tabSelect"] }], userClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }] } });
660
881
 
661
882
  /*
662
883
  * Public API Surface of @nanahoshi/mona-ui/tabs