tyrell-components 1.0.0-RC14 → 1.0.0-RC15

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 (113) hide show
  1. package/README.md +9 -1
  2. package/css/tyrell-theme.css +25 -2
  3. package/css/tyrell.css +4 -0
  4. package/dist/tyrell-colors-static.css +1 -316
  5. package/dist/tyrell-theme.css +1 -1443
  6. package/dist/tyrell.css +1 -1390
  7. package/dist/tyrell.js +1 -1
  8. package/lib/base/ty-component.js +196 -196
  9. package/lib/components/button.d.ts +1 -1
  10. package/lib/components/button.js +261 -259
  11. package/lib/components/calendar-month.d.ts +2 -2
  12. package/lib/components/calendar-month.js +439 -416
  13. package/lib/components/calendar-navigation.js +238 -238
  14. package/lib/components/calendar.d.ts +5 -3
  15. package/lib/components/calendar.js +611 -602
  16. package/lib/components/checkbox.d.ts +1 -1
  17. package/lib/components/checkbox.js +273 -272
  18. package/lib/components/copy.d.ts +1 -1
  19. package/lib/components/copy.js +280 -278
  20. package/lib/components/date-picker.d.ts +8 -1
  21. package/lib/components/date-picker.js +1128 -1108
  22. package/lib/components/file-upload.js +404 -404
  23. package/lib/components/icon.js +141 -141
  24. package/lib/components/input.d.ts +1 -1
  25. package/lib/components/input.js +593 -596
  26. package/lib/components/modal.js +319 -319
  27. package/lib/components/option.js +167 -167
  28. package/lib/components/popup.js +233 -233
  29. package/lib/components/radio.d.ts +2 -2
  30. package/lib/components/radio.js +407 -406
  31. package/lib/components/resize-observer.js +67 -67
  32. package/lib/components/scroll-container.js +292 -294
  33. package/lib/components/select.d.ts +71 -12
  34. package/lib/components/select.js +1605 -1529
  35. package/lib/components/selected-tags.d.ts +1 -1
  36. package/lib/components/selected-tags.js +188 -182
  37. package/lib/components/step.js +62 -62
  38. package/lib/components/switch.d.ts +1 -1
  39. package/lib/components/switch.js +214 -213
  40. package/lib/components/tab.js +62 -62
  41. package/lib/components/tabs.d.ts +1 -0
  42. package/lib/components/tabs.js +523 -492
  43. package/lib/components/tag.d.ts +1 -1
  44. package/lib/components/tag.js +236 -235
  45. package/lib/components/textarea.d.ts +1 -1
  46. package/lib/components/textarea.js +457 -456
  47. package/lib/components/tooltip.js +283 -283
  48. package/lib/components/wizard.js +384 -384
  49. package/lib/icons/heroicons/micro.js +392 -392
  50. package/lib/icons/heroicons/mini.js +382 -382
  51. package/lib/icons/heroicons/outline.js +337 -337
  52. package/lib/icons/heroicons/solid.js +407 -407
  53. package/lib/icons/lucide.js +22843 -22843
  54. package/lib/icons/material/filled.js +9653 -9653
  55. package/lib/icons/material/outlined.js +10271 -10271
  56. package/lib/icons/material/round.js +10495 -10495
  57. package/lib/icons/material/sharp.js +9905 -9905
  58. package/lib/icons/material/two-tone.js +12792 -12792
  59. package/lib/index.js +21 -21
  60. package/lib/styles/button.js +200 -302
  61. package/lib/styles/calendar-month.js +123 -183
  62. package/lib/styles/calendar-navigation.d.ts +1 -1
  63. package/lib/styles/calendar-navigation.js +64 -79
  64. package/lib/styles/calendar.d.ts +1 -1
  65. package/lib/styles/calendar.js +9 -9
  66. package/lib/styles/checkbox.js +45 -72
  67. package/lib/styles/copy.js +67 -91
  68. package/lib/styles/custom-scrollbar.js +80 -100
  69. package/lib/styles/date-picker.js +261 -331
  70. package/lib/styles/field-size.d.ts +6 -0
  71. package/lib/styles/field-size.js +91 -0
  72. package/lib/styles/file-upload.js +139 -169
  73. package/lib/styles/icon.js +92 -156
  74. package/lib/styles/input.js +125 -241
  75. package/lib/styles/modal.js +67 -102
  76. package/lib/styles/option.d.ts +1 -1
  77. package/lib/styles/option.js +47 -67
  78. package/lib/styles/popup.js +34 -65
  79. package/lib/styles/radio.js +69 -96
  80. package/lib/styles/resize-observer.js +2 -5
  81. package/lib/styles/scroll-container.js +100 -130
  82. package/lib/styles/select-base.js +596 -773
  83. package/lib/styles/select.js +140 -228
  84. package/lib/styles/step.js +22 -29
  85. package/lib/styles/switch.js +34 -55
  86. package/lib/styles/tab.d.ts +1 -1
  87. package/lib/styles/tab.js +22 -29
  88. package/lib/styles/tabs.d.ts +1 -1
  89. package/lib/styles/tabs.js +186 -180
  90. package/lib/styles/tag.js +135 -188
  91. package/lib/styles/textarea.d.ts +1 -1
  92. package/lib/styles/textarea.js +205 -271
  93. package/lib/styles/tooltip.js +3 -3
  94. package/lib/styles/wizard.js +170 -226
  95. package/lib/types/common.d.ts +2 -0
  96. package/lib/types/common.js +6 -5
  97. package/lib/utils/calendar-utils.js +100 -100
  98. package/lib/utils/custom-scrollbar.js +272 -272
  99. package/lib/utils/flavor-sheet.js +14 -14
  100. package/lib/utils/icon-registry.js +127 -127
  101. package/lib/utils/loader-registry.js +3 -3
  102. package/lib/utils/locale.js +34 -34
  103. package/lib/utils/mobile.js +1 -1
  104. package/lib/utils/number-format.js +54 -54
  105. package/lib/utils/positioning.js +212 -212
  106. package/lib/utils/property-capture.js +36 -36
  107. package/lib/utils/property-manager.js +125 -125
  108. package/lib/utils/resize-observer.js +23 -23
  109. package/lib/utils/scroll-lock.js +57 -57
  110. package/lib/utils/styles.js +17 -17
  111. package/lib/version.d.ts +1 -1
  112. package/lib/version.js +1 -1
  113. package/package.json +4 -4
@@ -2,554 +2,585 @@ import { ensureStyles } from '../utils/styles.js';
2
2
  import { tabsStyles } from '../styles/tabs.js';
3
3
  const eventHandlers = new WeakMap();
4
4
  const resizeObservers = new WeakMap();
5
+ const pendingInitialSnap = new WeakSet();
5
6
  function getTabsAttributes(el) {
6
- return {
7
- width: el.getAttribute('width') || '100%',
8
- height: el.getAttribute('height') || '400px',
9
- active: el.getAttribute('active'),
10
- placement: (el.getAttribute('placement') || 'top'),
11
- };
7
+ return {
8
+ width: el.getAttribute('width') || '100%',
9
+ height: el.getAttribute('height') || '400px',
10
+ active: el.getAttribute('active'),
11
+ placement: (el.getAttribute('placement') || 'top'),
12
+ fixed: el.hasAttribute('fixed'),
13
+ };
12
14
  }
13
15
  function getChildTabs(el) {
14
- return Array.from(el.querySelectorAll('ty-tab'));
16
+ return Array.from(el.querySelectorAll('ty-tab'));
15
17
  }
16
18
  function getTabId(tab) {
17
- return tab.getAttribute('id');
19
+ return tab.getAttribute('id');
20
+ }
21
+ function getSlotLabel(tabsEl, tabId) {
22
+ return tabsEl.querySelector(`:scope > [slot='label-${tabId}']`);
18
23
  }
19
24
  function hasSlotLabel(tabsEl, tabId) {
20
- return tabsEl.querySelector(`[slot='label-${tabId}']`) !== null;
25
+ return getSlotLabel(tabsEl, tabId) !== null;
21
26
  }
22
27
  function getTabLabelType(tabsEl, tab) {
23
- const tabId = getTabId(tab);
24
- if (tabId && hasSlotLabel(tabsEl, tabId)) {
25
- return 'slot';
26
- }
27
- return 'text';
28
+ const tabId = getTabId(tab);
29
+ if (tabId && hasSlotLabel(tabsEl, tabId)) {
30
+ return 'slot';
31
+ }
32
+ return 'text';
28
33
  }
29
34
  function isTabDisabled(tab) {
30
- return tab.hasAttribute('disabled');
35
+ return tab.hasAttribute('disabled');
31
36
  }
32
37
  function hasCustomMarker(el) {
33
- return el.querySelector('[slot="marker"]') !== null;
38
+ return el.querySelector('[slot="marker"]') !== null;
34
39
  }
35
40
  function findTabIndex(tabs, tabId) {
36
- const index = tabs.findIndex(tab => getTabId(tab) === tabId);
37
- return index >= 0 ? index : undefined;
41
+ const index = tabs.findIndex(tab => getTabId(tab) === tabId);
42
+ return index >= 0 ? index : undefined;
43
+ }
44
+ function currentActive(el) {
45
+ const tabs = getChildTabs(el);
46
+ const id = getActiveTabId(el, tabs);
47
+ return { id, index: (id ? findTabIndex(tabs, id) : undefined) ?? 0 };
38
48
  }
39
49
  function getActiveTabId(el, tabs) {
40
- const activeAttr = el.getAttribute('active');
41
- if (activeAttr && findTabIndex(tabs, activeAttr) !== undefined) {
42
- return activeAttr;
43
- }
44
- if (tabs.length > 0) {
45
- return getTabId(tabs[0]);
46
- }
47
- return null;
50
+ const activeAttr = el.getAttribute('active');
51
+ if (activeAttr && findTabIndex(tabs, activeAttr) !== undefined) {
52
+ return activeAttr;
53
+ }
54
+ if (tabs.length > 0) {
55
+ return getTabId(tabs[0]);
56
+ }
57
+ return null;
48
58
  }
49
59
  function setActiveTab(el, tabId) {
50
- el.setAttribute('active', tabId);
60
+ el.setAttribute('active', tabId);
51
61
  }
52
62
  function dispatchTabChangeEvent(el, activeId, activeIndex, previousId, previousIndex) {
53
- const event = new CustomEvent('ty-tab-change', {
54
- detail: {
55
- activeId,
56
- activeIndex,
57
- previousId,
58
- previousIndex,
59
- },
60
- bubbles: true,
61
- cancelable: false,
62
- });
63
- el.dispatchEvent(event);
63
+ const event = new CustomEvent('ty-tab-change', {
64
+ detail: {
65
+ activeId,
66
+ activeIndex,
67
+ previousId,
68
+ previousIndex,
69
+ },
70
+ bubbles: true,
71
+ cancelable: false,
72
+ });
73
+ el.dispatchEvent(event);
64
74
  }
65
75
  function handleTabClick(el, tabId, event) {
66
- event.preventDefault();
67
- event.stopPropagation();
68
- setActiveTab(el, tabId);
76
+ event.preventDefault();
77
+ event.stopPropagation();
78
+ setActiveTab(el, tabId);
69
79
  }
70
80
  function cleanupEventListeners(el) {
71
- const handlers = eventHandlers.get(el);
72
- if (!handlers)
73
- return;
74
- const shadowRoot = el.shadowRoot;
75
- if (!shadowRoot)
76
- return;
77
- handlers.tabClickHandlers.forEach((handler, tabId) => {
78
- const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
79
- if (button) {
80
- button.removeEventListener('pointerdown', handler);
81
- }
82
- });
83
- handlers.tabKeyClickHandlers.forEach((handler, tabId) => {
84
- const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
85
- if (button) {
86
- button.removeEventListener('click', handler);
87
- }
88
- });
89
- handlers.tabClickHandlers.clear();
90
- handlers.tabKeyClickHandlers.clear();
81
+ const handlers = eventHandlers.get(el);
82
+ if (!handlers)
83
+ return;
84
+ const shadowRoot = el.shadowRoot;
85
+ if (!shadowRoot)
86
+ return;
87
+ handlers.tabClickHandlers.forEach((handler, tabId) => {
88
+ const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
89
+ if (button) {
90
+ button.removeEventListener('pointerdown', handler);
91
+ }
92
+ });
93
+ handlers.tabKeyClickHandlers.forEach((handler, tabId) => {
94
+ const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
95
+ if (button) {
96
+ button.removeEventListener('click', handler);
97
+ }
98
+ });
99
+ handlers.tabClickHandlers.clear();
100
+ handlers.tabKeyClickHandlers.clear();
91
101
  }
92
102
  function setupEventListeners(el, shadowRoot, tabs) {
93
- cleanupEventListeners(el);
94
- const handlers = {
95
- tabClickHandlers: new Map(),
96
- tabKeyClickHandlers: new Map(),
97
- };
98
- tabs.forEach((tab) => {
99
- const tabId = getTabId(tab);
100
- if (!tabId)
101
- return;
102
- const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
103
- if (button) {
104
- const handler = (e) => handleTabClick(el, tabId, e);
105
- const keyClickHandler = (e) => {
106
- if (e.detail === 0)
107
- handleTabClick(el, tabId, e);
108
- };
109
- button.addEventListener('pointerdown', handler);
110
- button.addEventListener('click', keyClickHandler);
111
- handlers.tabClickHandlers.set(tabId, handler);
112
- handlers.tabKeyClickHandlers.set(tabId, keyClickHandler);
113
- }
114
- });
115
- eventHandlers.set(el, handlers);
103
+ cleanupEventListeners(el);
104
+ const handlers = {
105
+ tabClickHandlers: new Map(),
106
+ tabKeyClickHandlers: new Map(),
107
+ };
108
+ tabs.forEach((tab) => {
109
+ const tabId = getTabId(tab);
110
+ if (!tabId)
111
+ return;
112
+ const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
113
+ if (button) {
114
+ const handler = (e) => handleTabClick(el, tabId, e);
115
+ const keyClickHandler = (e) => {
116
+ if (e.detail === 0)
117
+ handleTabClick(el, tabId, e);
118
+ };
119
+ button.addEventListener('pointerdown', handler);
120
+ button.addEventListener('click', keyClickHandler);
121
+ handlers.tabClickHandlers.set(tabId, handler);
122
+ handlers.tabKeyClickHandlers.set(tabId, keyClickHandler);
123
+ }
124
+ });
125
+ eventHandlers.set(el, handlers);
116
126
  }
117
127
  function updateTransform(el, activeIndex) {
118
- const shadowRoot = el.shadowRoot;
119
- if (!shadowRoot)
120
- return;
121
- const panelsWrapper = shadowRoot.querySelector('.panels-wrapper');
122
- if (!panelsWrapper)
123
- return;
124
- const containerWidth = el.offsetWidth;
125
- const offsetPx = activeIndex * containerWidth;
126
- panelsWrapper.style.transform = `translateX(-${offsetPx}px)`;
128
+ const shadowRoot = el.shadowRoot;
129
+ if (!shadowRoot)
130
+ return;
131
+ const panelsWrapper = shadowRoot.querySelector('.panels-wrapper');
132
+ if (!panelsWrapper)
133
+ return;
134
+ const containerWidth = el.offsetWidth;
135
+ const offsetPx = activeIndex * containerWidth;
136
+ panelsWrapper.style.transform = `translateX(-${offsetPx}px)`;
127
137
  }
128
138
  function updateAriaAttributes(el, shadowRoot, activeId) {
129
- const tabs = getChildTabs(el);
130
- tabs.forEach((tab, idx) => {
131
- const tabId = getTabId(tab);
132
- if (!tabId)
133
- return;
134
- const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
135
- const isActive = tabId === activeId;
136
- if (button) {
137
- button.setAttribute('aria-selected', String(isActive));
138
- button.setAttribute('tabindex', isActive ? '0' : '-1');
139
- button.setAttribute('data-active', String(isActive));
140
- const slottedLabel = el.querySelector(`[slot='label-${tabId}']`);
141
- if (slottedLabel) {
142
- slottedLabel.setAttribute('data-active', String(isActive));
143
- }
144
- }
145
- });
139
+ const tabs = getChildTabs(el);
140
+ tabs.forEach((tab, idx) => {
141
+ const tabId = getTabId(tab);
142
+ if (!tabId)
143
+ return;
144
+ const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
145
+ const isActive = tabId === activeId;
146
+ if (button) {
147
+ button.setAttribute('aria-selected', String(isActive));
148
+ button.setAttribute('tabindex', isActive ? '0' : '-1');
149
+ button.setAttribute('data-active', String(isActive));
150
+ const slottedLabel = getSlotLabel(el, tabId);
151
+ if (slottedLabel) {
152
+ slottedLabel.setAttribute('data-active', String(isActive));
153
+ }
154
+ }
155
+ });
146
156
  }
147
157
  function updatePanelInteraction(el, activeId) {
148
- const tabs = getChildTabs(el);
149
- tabs.forEach((tab) => {
150
- const tabId = getTabId(tab);
151
- if (!tabId)
152
- return;
153
- const isActive = tabId === activeId;
154
- tab.setAttribute('data-active', String(isActive));
155
- if (isActive) {
156
- tab.style.pointerEvents = 'auto';
157
- tab.style.opacity = '1';
158
- }
159
- else {
160
- tab.style.pointerEvents = 'none';
161
- tab.style.opacity = '0';
162
- }
163
- });
158
+ const tabs = getChildTabs(el);
159
+ tabs.forEach((tab) => {
160
+ const tabId = getTabId(tab);
161
+ if (!tabId)
162
+ return;
163
+ const isActive = tabId === activeId;
164
+ tab.setAttribute('data-active', String(isActive));
165
+ if (isActive) {
166
+ tab.style.pointerEvents = 'auto';
167
+ tab.style.opacity = '1';
168
+ }
169
+ else {
170
+ tab.style.pointerEvents = 'none';
171
+ tab.style.opacity = '0';
172
+ }
173
+ });
164
174
  }
165
175
  function calculateMarkerPosition(el, shadowRoot, activeId) {
166
- const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
167
- const buttonsContainer = shadowRoot.querySelector('.tab-buttons');
168
- if (!button || !buttonsContainer)
169
- return null;
170
- const buttonRect = button.getBoundingClientRect();
171
- const left = button.offsetLeft;
172
- const top = button.offsetTop;
173
- return {
174
- left,
175
- top,
176
- width: buttonRect.width,
177
- height: buttonRect.height,
178
- };
179
- }
180
- function updateMarker(el, activeId) {
181
- const shadowRoot = el.shadowRoot;
182
- if (!shadowRoot)
183
- return;
184
- const marker = shadowRoot.querySelector('.marker-wrapper');
185
- if (!marker)
186
- return;
187
- const position = calculateMarkerPosition(el, shadowRoot, activeId);
188
- if (!position)
189
- return;
190
- const snap = !marker.style.left || marker.offsetWidth === 0;
191
- if (snap)
192
- marker.style.transition = 'none';
193
- marker.style.left = `${position.left}px`;
194
- marker.style.top = `${position.top}px`;
195
- marker.style.width = `${position.width}px`;
196
- marker.style.height = `${position.height}px`;
197
- if (snap) {
198
- marker.offsetWidth;
199
- marker.style.transition = '';
200
- }
176
+ const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
177
+ const buttonsContainer = shadowRoot.querySelector('.tab-buttons');
178
+ if (!button || !buttonsContainer)
179
+ return null;
180
+ const left = button.offsetLeft;
181
+ const top = button.offsetTop;
182
+ const width = button.offsetWidth;
183
+ const height = button.offsetHeight;
184
+ return { left, top, width, height };
185
+ }
186
+ function updateMarker(el, activeId, forceSnap = false) {
187
+ const shadowRoot = el.shadowRoot;
188
+ if (!shadowRoot)
189
+ return;
190
+ const marker = shadowRoot.querySelector('.marker-wrapper');
191
+ if (!marker)
192
+ return;
193
+ const position = calculateMarkerPosition(el, shadowRoot, activeId);
194
+ if (!position)
195
+ return;
196
+ const snap = forceSnap || !marker.style.left || marker.offsetWidth === 0;
197
+ if (snap)
198
+ marker.style.transition = 'none';
199
+ marker.style.left = `${position.left}px`;
200
+ marker.style.top = `${position.top}px`;
201
+ marker.style.width = `${position.width}px`;
202
+ marker.style.height = `${position.height}px`;
203
+ if (snap) {
204
+ marker.offsetWidth;
205
+ marker.style.transition = '';
206
+ }
201
207
  }
202
208
  function updateActiveTabState(el, tabId, previousId) {
203
- const tabs = getChildTabs(el);
204
- const shadowRoot = el.shadowRoot;
205
- if (!shadowRoot)
206
- return;
207
- const currentIndex = previousId ? findTabIndex(tabs, previousId) : undefined;
208
- const newIndex = findTabIndex(tabs, tabId);
209
- if (previousId === tabId || newIndex === undefined)
210
- return;
211
- el.style.setProperty('--active-index', String(newIndex));
212
- updateTransform(el, newIndex);
213
- updateAriaAttributes(el, shadowRoot, tabId);
214
- updatePanelInteraction(el, tabId);
215
- updateMarker(el, tabId);
216
- const newPanel = tabs[newIndex];
217
- if (newPanel?.resetScroll) {
218
- newPanel.resetScroll();
219
- }
220
- dispatchTabChangeEvent(el, tabId, newIndex, previousId, currentIndex ?? null);
209
+ const tabs = getChildTabs(el);
210
+ const shadowRoot = el.shadowRoot;
211
+ if (!shadowRoot)
212
+ return;
213
+ const currentIndex = previousId ? findTabIndex(tabs, previousId) : undefined;
214
+ const newIndex = findTabIndex(tabs, tabId);
215
+ if (previousId === tabId || newIndex === undefined)
216
+ return;
217
+ el.style.setProperty('--active-index', String(newIndex));
218
+ updateTransform(el, newIndex);
219
+ updateAriaAttributes(el, shadowRoot, tabId);
220
+ updatePanelInteraction(el, tabId);
221
+ updateMarker(el, tabId, pendingInitialSnap.delete(el));
222
+ shadowRoot.querySelectorAll('.tab-overflow-item').forEach((item) => {
223
+ item.setAttribute('data-active', String(item.dataset.tabId === tabId));
224
+ });
225
+ const newPanel = tabs[newIndex];
226
+ if (newPanel?.resetScroll) {
227
+ newPanel.resetScroll();
228
+ }
229
+ dispatchTabChangeEvent(el, tabId, newIndex, previousId, currentIndex ?? null);
221
230
  }
222
231
  function setupResizeObserver(el) {
223
- const oldObserver = resizeObservers.get(el);
224
- if (oldObserver) {
225
- oldObserver.disconnect();
226
- }
227
- const observer = new ResizeObserver((entries) => {
228
- const entry = entries[0];
229
- const { width } = getTabsAttributes(el);
230
- const tabs = getChildTabs(el);
231
- const activeId = getActiveTabId(el, tabs);
232
- const activeIndex = activeId ? findTabIndex(tabs, activeId) : 0;
233
- if (width.includes('%')) {
234
- el.style.setProperty('--tabs-page-width', `${entry.contentRect.width}px`);
235
- }
236
- if (activeIndex !== undefined) {
237
- updateTransform(el, activeIndex);
238
- }
239
- if (activeId) {
240
- updateMarker(el, activeId);
241
- }
242
- updateOverflow(el);
243
- });
244
- observer.observe(el);
245
- resizeObservers.set(el, observer);
232
+ const oldObserver = resizeObservers.get(el);
233
+ if (oldObserver) {
234
+ oldObserver.disconnect();
235
+ }
236
+ const observer = new ResizeObserver((entries) => {
237
+ const entry = entries[0];
238
+ const { width } = getTabsAttributes(el);
239
+ const tabs = getChildTabs(el);
240
+ const activeId = getActiveTabId(el, tabs);
241
+ const activeIndex = activeId ? findTabIndex(tabs, activeId) : 0;
242
+ if (width.includes('%')) {
243
+ el.style.setProperty('--tabs-page-width', `${entry.contentRect.width}px`);
244
+ }
245
+ if (activeIndex !== undefined) {
246
+ updateTransform(el, activeIndex);
247
+ }
248
+ updateOverflow(el);
249
+ if (activeId) {
250
+ updateMarker(el, activeId);
251
+ scrollActiveIntoView(el, activeId, false);
252
+ }
253
+ });
254
+ observer.observe(el);
255
+ resizeObservers.set(el, observer);
246
256
  }
247
257
  function cleanupResizeObserver(el) {
248
- const observer = resizeObservers.get(el);
249
- if (observer) {
250
- observer.disconnect();
251
- resizeObservers.delete(el);
252
- }
258
+ const observer = resizeObservers.get(el);
259
+ if (observer) {
260
+ observer.disconnect();
261
+ resizeObservers.delete(el);
262
+ }
253
263
  }
254
264
  function renderTabButtons(tabsEl, tabs, activeId) {
255
- const buttons = tabs.map((tab) => {
256
- const tabId = getTabId(tab);
257
- if (!tabId)
258
- return '';
259
- const labelType = getTabLabelType(tabsEl, tab);
260
- const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
261
- const disabled = isTabDisabled(tab);
262
- const active = tabId === activeId;
263
- return `<button
264
- class="tab-button"
265
- role="tab"
266
- data-tab-id="${tabId}"
267
- id="tab-${tabId}"
268
- aria-selected="${active}"
269
- tabindex="${active ? '0' : '-1'}"
270
- data-active="${active}"
271
- ${disabled ? 'disabled aria-disabled="true"' : ''}
272
- >
273
- ${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : textLabel}
274
- </button>`;
275
- }).join('');
276
- return `
277
- <div class="tab-buttons" role="tablist" part="buttons-container">
278
- <div class="marker-wrapper" part="marker-wrapper">
279
- ${!hasCustomMarker(tabsEl) ? '<div class="default-marker"></div>' : ''}
280
- <slot name="marker"></slot>
281
- </div>
282
- ${buttons}
283
- </div>
284
- `;
265
+ const buttons = tabs.map((tab) => {
266
+ const tabId = getTabId(tab);
267
+ if (!tabId)
268
+ return '';
269
+ const labelType = getTabLabelType(tabsEl, tab);
270
+ const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
271
+ const disabled = isTabDisabled(tab);
272
+ const active = tabId === activeId;
273
+ return `<button
274
+ class="tab-button"
275
+ role="tab"
276
+ data-tab-id="${tabId}"
277
+ id="tab-${tabId}"
278
+ aria-selected="${active}"
279
+ tabindex="${active ? '0' : '-1'}"
280
+ data-active="${active}"
281
+ ${disabled ? 'disabled aria-disabled="true"' : ''}
282
+ >
283
+ ${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : `<span class="tab-label">${textLabel}</span>`}
284
+ </button>`;
285
+ }).join('');
286
+ return `
287
+ <div class="tab-buttons" role="tablist" part="buttons-container">
288
+ <div class="tab-strip" part="strip">
289
+ <div class="marker-wrapper" part="marker-wrapper">
290
+ ${!hasCustomMarker(tabsEl) ? '<div class="default-marker"></div>' : ''}
291
+ <slot name="marker"></slot>
292
+ </div>
293
+ ${buttons}
294
+ </div>
295
+ </div>
296
+ `;
285
297
  }
286
298
  function renderButtonsOnly(tabsEl, tabs, activeId) {
287
- return tabs.map((tab) => {
288
- const tabId = getTabId(tab);
289
- if (!tabId)
290
- return '';
291
- const labelType = getTabLabelType(tabsEl, tab);
292
- const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
293
- const disabled = isTabDisabled(tab);
294
- const active = tabId === activeId;
295
- return `<button
296
- class="tab-button"
297
- role="tab"
298
- data-tab-id="${tabId}"
299
- id="tab-${tabId}"
300
- aria-selected="${active}"
301
- tabindex="${active ? '0' : '-1'}"
302
- data-active="${active}"
303
- ${disabled ? 'disabled aria-disabled="true"' : ''}
304
- >
305
- ${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : textLabel}
306
- </button>`;
307
- }).join('');
308
- }
309
- const OVERFLOW_TRIGGER_WIDTH = 40;
299
+ return tabs.map((tab) => {
300
+ const tabId = getTabId(tab);
301
+ if (!tabId)
302
+ return '';
303
+ const labelType = getTabLabelType(tabsEl, tab);
304
+ const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
305
+ const disabled = isTabDisabled(tab);
306
+ const active = tabId === activeId;
307
+ return `<button
308
+ class="tab-button"
309
+ role="tab"
310
+ data-tab-id="${tabId}"
311
+ id="tab-${tabId}"
312
+ aria-selected="${active}"
313
+ tabindex="${active ? '0' : '-1'}"
314
+ data-active="${active}"
315
+ ${disabled ? 'disabled aria-disabled="true"' : ''}
316
+ >
317
+ ${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : `<span class="tab-label">${textLabel}</span>`}
318
+ </button>`;
319
+ }).join('');
320
+ }
310
321
  function getTabMenuLabel(tabsEl, tab) {
311
- const tabId = getTabId(tab);
312
- if (tabId && getTabLabelType(tabsEl, tab) === 'slot') {
313
- const slotted = tabsEl.querySelector(`[slot='label-${tabId}']`);
314
- return slotted?.textContent?.trim() || tabId;
315
- }
316
- return tab.getAttribute('label') || 'Tab';
322
+ const tabId = getTabId(tab);
323
+ if (tabId && getTabLabelType(tabsEl, tab) === 'slot') {
324
+ const slotted = getSlotLabel(tabsEl, tabId);
325
+ return slotted?.textContent?.trim() || tabId;
326
+ }
327
+ return tab.getAttribute('label') || 'Tab';
317
328
  }
318
329
  function removeOverflowMenu(shadowRoot) {
319
- shadowRoot.querySelector('.tab-overflow-trigger')?.remove();
320
- }
321
- function renderOverflowMenu(el, container, hiddenButtons, allTabs) {
322
- if (hiddenButtons.length === 0)
323
- return;
324
- const tabsById = new Map(allTabs.map((tab) => [getTabId(tab), tab]));
325
- const trigger = document.createElement('button');
326
- trigger.className = 'tab-overflow-trigger';
327
- trigger.type = 'button';
328
- trigger.setAttribute('aria-label', `${hiddenButtons.length} more tabs`);
329
- trigger.textContent = '⋯';
330
- const popup = document.createElement('ty-popup');
331
- popup.setAttribute('placement', 'bottom');
332
- const menu = document.createElement('div');
333
- menu.className = 'tab-overflow-menu';
334
- menu.setAttribute('role', 'menu');
335
- hiddenButtons.forEach((btn) => {
336
- const tabId = btn.dataset.tabId;
337
- const tab = tabId ? tabsById.get(tabId) : undefined;
338
- if (!tabId || !tab)
339
- return;
340
- const item = document.createElement('button');
341
- item.type = 'button';
342
- item.className = 'tab-overflow-item';
343
- item.setAttribute('role', 'menuitem');
344
- item.textContent = getTabMenuLabel(el, tab);
345
- if (isTabDisabled(tab)) {
346
- item.disabled = true;
347
- }
348
- else {
349
- item.addEventListener('click', () => {
350
- setActiveTab(el, tabId);
351
- popup.closePopup?.();
352
- });
353
- }
354
- menu.appendChild(item);
355
- });
356
- popup.appendChild(menu);
357
- trigger.appendChild(popup);
358
- container.appendChild(trigger);
330
+ shadowRoot.querySelector('.tab-overflow-trigger')?.remove();
331
+ }
332
+ function renderOverflowMenu(el, container, allTabs) {
333
+ const activeId = getActiveTabId(el, allTabs);
334
+ const trigger = document.createElement('button');
335
+ trigger.className = 'tab-overflow-trigger';
336
+ trigger.type = 'button';
337
+ trigger.setAttribute('aria-label', `${allTabs.length} tabs`);
338
+ trigger.textContent = '⋯';
339
+ const popup = document.createElement('ty-popup');
340
+ popup.setAttribute('placement', 'bottom');
341
+ const menu = document.createElement('div');
342
+ menu.className = 'tab-overflow-menu';
343
+ menu.setAttribute('role', 'menu');
344
+ allTabs.forEach((tab) => {
345
+ const tabId = getTabId(tab);
346
+ if (!tabId)
347
+ return;
348
+ const item = document.createElement('button');
349
+ item.type = 'button';
350
+ item.className = 'tab-overflow-item';
351
+ item.setAttribute('role', 'menuitem');
352
+ item.setAttribute('data-tab-id', tabId);
353
+ item.setAttribute('data-active', String(tabId === activeId));
354
+ item.textContent = getTabMenuLabel(el, tab);
355
+ if (isTabDisabled(tab)) {
356
+ item.disabled = true;
357
+ }
358
+ else {
359
+ item.addEventListener('click', () => {
360
+ setActiveTab(el, tabId);
361
+ popup.closePopup?.();
362
+ });
363
+ }
364
+ menu.appendChild(item);
365
+ });
366
+ popup.appendChild(menu);
367
+ trigger.appendChild(popup);
368
+ container.appendChild(trigger);
359
369
  }
360
370
  function updateOverflow(el) {
361
- const shadowRoot = el.shadowRoot;
362
- if (!shadowRoot)
363
- return;
364
- const container = shadowRoot.querySelector('.tab-buttons');
365
- if (!container)
366
- return;
367
- removeOverflowMenu(shadowRoot);
368
- const buttons = Array.from(container.querySelectorAll('.tab-button'));
369
- buttons.forEach((b) => b.classList.remove('overflow-hidden'));
370
- if (buttons.length === 0)
371
- return;
372
- const available = container.clientWidth;
373
- if (available <= 0)
374
- return;
375
- let total = 0;
376
- let cutoff = buttons.length;
377
- for (let i = 0; i < buttons.length; i++) {
378
- total += buttons[i].offsetWidth;
379
- if (total > available) {
380
- cutoff = i;
381
- break;
382
- }
383
- }
384
- if (cutoff >= buttons.length)
385
- return;
386
- total = 0;
387
- cutoff = buttons.length;
388
- for (let i = 0; i < buttons.length; i++) {
389
- total += buttons[i].offsetWidth;
390
- if (total > available - OVERFLOW_TRIGGER_WIDTH) {
391
- cutoff = i;
392
- break;
393
- }
394
- }
395
- cutoff = Math.max(cutoff, 1);
396
- const tabs = getChildTabs(el);
397
- const activeId = getActiveTabId(el, tabs);
398
- const hidden = new Set(buttons.slice(cutoff));
399
- const activeButton = activeId ? buttons.find((b) => b.dataset.tabId === activeId) : undefined;
400
- if (activeButton && hidden.has(activeButton)) {
401
- const lastVisible = buttons[cutoff - 1];
402
- hidden.delete(activeButton);
403
- hidden.add(lastVisible);
404
- }
405
- buttons.forEach((b) => b.classList.toggle('overflow-hidden', hidden.has(b)));
406
- renderOverflowMenu(el, container, buttons.filter((b) => hidden.has(b)), tabs);
371
+ const shadowRoot = el.shadowRoot;
372
+ if (!shadowRoot)
373
+ return;
374
+ const container = shadowRoot.querySelector('.tab-buttons');
375
+ const strip = shadowRoot.querySelector('.tab-strip');
376
+ if (!container || !strip)
377
+ return;
378
+ if (getTabsAttributes(el).fixed) {
379
+ removeOverflowMenu(shadowRoot);
380
+ strip.classList.add('unclipped');
381
+ strip.style.removeProperty('--fade-left');
382
+ strip.style.removeProperty('--fade-right');
383
+ return;
384
+ }
385
+ const savedScrollLeft = strip.scrollLeft;
386
+ removeOverflowMenu(shadowRoot);
387
+ if (strip.clientWidth <= 0)
388
+ return;
389
+ const buttons = strip.querySelectorAll('.tab-button');
390
+ const last = buttons[buttons.length - 1];
391
+ const contentWidth = last ? last.offsetLeft + last.offsetWidth : 0;
392
+ const stripWidth = strip.clientWidth;
393
+ const hidden = contentWidth - stripWidth;
394
+ strip.classList.toggle('unclipped', hidden <= 1);
395
+ if (hidden <= 1) {
396
+ strip.scrollLeft = savedScrollLeft;
397
+ updateEdgeFades(strip);
398
+ return;
399
+ }
400
+ renderOverflowMenu(el, container, getChildTabs(el));
401
+ const triggerCost = container.clientWidth - strip.clientWidth;
402
+ if (hidden <= triggerCost) {
403
+ removeOverflowMenu(shadowRoot);
404
+ }
405
+ strip.scrollLeft = savedScrollLeft;
406
+ updateEdgeFades(strip);
407
+ }
408
+ function updateEdgeFades(strip) {
409
+ const maxScroll = strip.scrollWidth - strip.clientWidth;
410
+ const fade = (distance) => `${distance > 1 ? Math.min(28, distance) : 0}px`;
411
+ strip.style.setProperty('--fade-left', fade(strip.scrollLeft));
412
+ strip.style.setProperty('--fade-right', fade(maxScroll - strip.scrollLeft));
413
+ }
414
+ function scrollActiveIntoView(el, activeId, smooth) {
415
+ const shadowRoot = el.shadowRoot;
416
+ if (!shadowRoot)
417
+ return;
418
+ const strip = shadowRoot.querySelector('.tab-strip');
419
+ const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
420
+ if (!strip || !button || strip.clientWidth <= 0)
421
+ return;
422
+ const centered = button.offsetLeft + button.offsetWidth / 2 - strip.clientWidth / 2;
423
+ const target = Math.max(0, Math.min(centered, strip.scrollWidth - strip.clientWidth));
424
+ if (Math.round(target) !== Math.round(strip.scrollLeft)) {
425
+ const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
426
+ strip.scrollTo({ left: target, behavior: smooth && !reduce ? 'smooth' : 'auto' });
427
+ }
407
428
  }
408
429
  function render(el) {
409
- const shadowRoot = el.shadowRoot;
410
- if (!shadowRoot)
411
- return;
412
- const { width, height, placement } = getTabsAttributes(el);
413
- const tabs = getChildTabs(el);
414
- const activeId = getActiveTabId(el, tabs);
415
- const activeIndex = activeId ? (findTabIndex(tabs, activeId) ?? 0) : 0;
416
- tabs.forEach((tab) => {
417
- const tabId = getTabId(tab);
418
- if (!tabId)
419
- return;
420
- tab.setAttribute('role', 'tabpanel');
421
- tab.setAttribute('aria-labelledby', `tab-${tabId}`);
422
- tab.setAttribute('tabindex', '0');
423
- });
424
- const existingContainer = shadowRoot.querySelector('.tabs-container');
425
- const existingButtons = shadowRoot.querySelector('.tab-buttons');
426
- const existingViewport = shadowRoot.querySelector('.panels-viewport');
427
- ensureStyles(shadowRoot, { css: tabsStyles, id: 'ty-tabs' });
428
- if (tabs.length > 7) {
429
- console.warn(`[ty-tabs] More than 7 tabs detected (${tabs.length} tabs). ` +
430
- 'This may cause overflow and poor UX. ' +
431
- 'Consider using sidebar navigation, accordion menu, or other patterns.');
432
- }
433
- el.style.setProperty('--tabs-width', width.includes('%') ? '100%' : width);
434
- el.style.setProperty('--tabs-height', height);
435
- el.style.setProperty('--active-index', String(activeIndex));
436
- if (existingContainer && existingButtons && existingViewport) {
437
- existingContainer.setAttribute('data-placement', placement);
438
- existingButtons.querySelector('.tab-overflow-trigger')?.remove();
439
- const allButtons = existingButtons.querySelectorAll('.tab-button');
440
- allButtons.forEach(button => button.remove());
441
- const buttonsHtml = renderButtonsOnly(el, tabs, activeId);
442
- const tempDiv = document.createElement('div');
443
- tempDiv.innerHTML = buttonsHtml;
444
- Array.from(tempDiv.children).forEach(button => {
445
- existingButtons.appendChild(button);
446
- });
447
- setupEventListeners(el, shadowRoot, tabs);
448
- updateAriaAttributes(el, shadowRoot, activeId || '');
449
- requestAnimationFrame(() => {
450
- const buttons = shadowRoot.querySelector('.tab-buttons');
451
- if (buttons) {
452
- const buttonsHeight = buttons.offsetHeight;
453
- el.style.setProperty('--buttons-height', `${buttonsHeight}px`);
454
- }
455
- updateTransform(el, activeIndex);
456
- if (activeId) {
457
- updateMarker(el, activeId);
458
- }
459
- updateOverflow(el);
460
- });
461
- if (activeId) {
462
- updatePanelInteraction(el, activeId);
463
- }
464
- }
465
- else {
466
- shadowRoot.innerHTML = `
467
- <div class="tabs-container" data-placement="${placement}">
468
- ${renderTabButtons(el, tabs, activeId)}
469
- <div class="panels-viewport" part="panels-container">
470
- <div class="panels-wrapper">
471
- <slot></slot>
472
- </div>
473
- </div>
474
- </div>
475
- `;
476
- requestAnimationFrame(() => {
477
- const buttons = shadowRoot.querySelector('.tab-buttons');
478
- if (buttons) {
479
- const buttonsHeight = buttons.offsetHeight;
480
- el.style.setProperty('--buttons-height', `${buttonsHeight}px`);
481
- }
482
- updateTransform(el, activeIndex);
483
- if (activeId) {
484
- updateMarker(el, activeId);
485
- }
486
- updateOverflow(el);
487
- });
488
- setupEventListeners(el, shadowRoot, tabs);
489
- updateAriaAttributes(el, shadowRoot, activeId || '');
490
- setupResizeObserver(el);
491
- if (activeId) {
492
- updatePanelInteraction(el, activeId);
493
- }
494
- const markerSlot = shadowRoot.querySelector('slot[name="marker"]');
495
- if (markerSlot) {
496
- const updateDefaultMarkerVisibility = () => {
497
- const defaultMarker = shadowRoot.querySelector('.default-marker');
498
- if (defaultMarker) {
499
- const hasCustom = markerSlot.assignedElements().length > 0;
500
- defaultMarker.style.display = hasCustom ? 'none' : '';
501
- }
502
- };
503
- markerSlot.addEventListener('slotchange', updateDefaultMarkerVisibility);
504
- updateDefaultMarkerVisibility();
505
- }
506
- }
430
+ const shadowRoot = el.shadowRoot;
431
+ if (!shadowRoot)
432
+ return;
433
+ const { width, height, placement, fixed } = getTabsAttributes(el);
434
+ const tabs = getChildTabs(el);
435
+ const activeId = getActiveTabId(el, tabs);
436
+ const activeIndex = activeId ? (findTabIndex(tabs, activeId) ?? 0) : 0;
437
+ tabs.forEach((tab) => {
438
+ const tabId = getTabId(tab);
439
+ if (!tabId)
440
+ return;
441
+ tab.setAttribute('role', 'tabpanel');
442
+ tab.setAttribute('aria-labelledby', `tab-${tabId}`);
443
+ tab.setAttribute('tabindex', '0');
444
+ });
445
+ const existingContainer = shadowRoot.querySelector('.tabs-container');
446
+ const existingButtons = shadowRoot.querySelector('.tab-buttons');
447
+ const existingStrip = shadowRoot.querySelector('.tab-strip');
448
+ const existingViewport = shadowRoot.querySelector('.panels-viewport');
449
+ ensureStyles(shadowRoot, { css: tabsStyles, id: 'ty-tabs' });
450
+ el.style.setProperty('--tabs-width', width.includes('%') ? '100%' : width);
451
+ el.style.setProperty('--tabs-height', height);
452
+ el.style.setProperty('--active-index', String(activeIndex));
453
+ if (existingContainer && existingButtons && existingStrip && existingViewport) {
454
+ existingContainer.setAttribute('data-placement', placement);
455
+ existingContainer.toggleAttribute('data-fixed', fixed);
456
+ const savedScrollLeft = existingStrip.scrollLeft;
457
+ existingButtons.querySelector('.tab-overflow-trigger')?.remove();
458
+ const allButtons = existingStrip.querySelectorAll('.tab-button');
459
+ allButtons.forEach(button => button.remove());
460
+ const buttonsHtml = renderButtonsOnly(el, tabs, activeId);
461
+ const tempDiv = document.createElement('div');
462
+ tempDiv.innerHTML = buttonsHtml;
463
+ Array.from(tempDiv.children).forEach(button => {
464
+ existingStrip.appendChild(button);
465
+ });
466
+ existingStrip.scrollLeft = savedScrollLeft;
467
+ setupEventListeners(el, shadowRoot, tabs);
468
+ updateAriaAttributes(el, shadowRoot, activeId || '');
469
+ requestAnimationFrame(() => {
470
+ const buttons = shadowRoot.querySelector('.tab-buttons');
471
+ if (buttons) {
472
+ const buttonsHeight = buttons.offsetHeight;
473
+ el.style.setProperty('--buttons-height', `${buttonsHeight}px`);
474
+ }
475
+ const current = currentActive(el);
476
+ updateTransform(el, current.index);
477
+ updateOverflow(el);
478
+ if (current.id) {
479
+ updateMarker(el, current.id);
480
+ scrollActiveIntoView(el, current.id, true);
481
+ }
482
+ });
483
+ if (activeId) {
484
+ updatePanelInteraction(el, activeId);
485
+ }
486
+ }
487
+ else {
488
+ pendingInitialSnap.add(el);
489
+ shadowRoot.innerHTML = `
490
+ <div class="tabs-container" data-placement="${placement}"${fixed ? ' data-fixed' : ''}>
491
+ ${renderTabButtons(el, tabs, activeId)}
492
+ <div class="panels-viewport" part="panels-container">
493
+ <div class="panels-wrapper">
494
+ <slot></slot>
495
+ </div>
496
+ </div>
497
+ </div>
498
+ `;
499
+ requestAnimationFrame(() => {
500
+ const buttons = shadowRoot.querySelector('.tab-buttons');
501
+ if (buttons) {
502
+ const buttonsHeight = buttons.offsetHeight;
503
+ el.style.setProperty('--buttons-height', `${buttonsHeight}px`);
504
+ }
505
+ const current = currentActive(el);
506
+ updateTransform(el, current.index);
507
+ updateOverflow(el);
508
+ if (current.id) {
509
+ updateMarker(el, current.id);
510
+ scrollActiveIntoView(el, current.id, false);
511
+ }
512
+ });
513
+ setupEventListeners(el, shadowRoot, tabs);
514
+ updateAriaAttributes(el, shadowRoot, activeId || '');
515
+ setupResizeObserver(el);
516
+ const strip = shadowRoot.querySelector('.tab-strip');
517
+ strip?.addEventListener('scroll', () => updateEdgeFades(strip), { passive: true });
518
+ if (activeId) {
519
+ updatePanelInteraction(el, activeId);
520
+ }
521
+ const markerSlot = shadowRoot.querySelector('slot[name="marker"]');
522
+ if (markerSlot) {
523
+ const updateDefaultMarkerVisibility = () => {
524
+ const defaultMarker = shadowRoot.querySelector('.default-marker');
525
+ if (defaultMarker) {
526
+ const hasCustom = markerSlot.assignedElements().length > 0;
527
+ defaultMarker.style.display = hasCustom ? 'none' : '';
528
+ }
529
+ };
530
+ markerSlot.addEventListener('slotchange', updateDefaultMarkerVisibility);
531
+ updateDefaultMarkerVisibility();
532
+ }
533
+ }
507
534
  }
508
535
  function cleanup(el) {
509
- cleanupEventListeners(el);
510
- cleanupResizeObserver(el);
536
+ cleanupEventListeners(el);
537
+ cleanupResizeObserver(el);
511
538
  }
512
539
  export class TyTabs extends HTMLElement {
513
- static get observedAttributes() {
514
- return ['width', 'height', 'active', 'placement'];
515
- }
516
- constructor() {
517
- super();
518
- this._childObserver = null;
519
- this._childRenderQueued = false;
520
- this.attachShadow({ mode: 'open' });
521
- }
522
- connectedCallback() {
523
- render(this);
524
- this._childObserver = new MutationObserver(() => {
525
- if (this._childRenderQueued)
526
- return;
527
- this._childRenderQueued = true;
528
- queueMicrotask(() => {
529
- this._childRenderQueued = false;
530
- if (this.isConnected)
531
- render(this);
532
- });
533
- });
534
- this._childObserver.observe(this, { childList: true });
535
- }
536
- disconnectedCallback() {
537
- this._childObserver?.disconnect();
538
- this._childObserver = null;
539
- cleanup(this);
540
- }
541
- attributeChangedCallback(name, oldValue, newValue) {
542
- if (name === 'active') {
543
- if (newValue) {
544
- updateActiveTabState(this, newValue, oldValue);
545
- }
546
- render(this);
547
- }
548
- else {
549
- render(this);
550
- }
551
- }
540
+ static get observedAttributes() {
541
+ return ['width', 'height', 'active', 'placement', 'fixed'];
542
+ }
543
+ constructor() {
544
+ super();
545
+ this._childObserver = null;
546
+ this._childRenderQueued = false;
547
+ this.attachShadow({ mode: 'open' });
548
+ }
549
+ connectedCallback() {
550
+ render(this);
551
+ this._childObserver = new MutationObserver(() => {
552
+ if (this._childRenderQueued)
553
+ return;
554
+ this._childRenderQueued = true;
555
+ queueMicrotask(() => {
556
+ this._childRenderQueued = false;
557
+ if (this.isConnected)
558
+ render(this);
559
+ });
560
+ });
561
+ this._childObserver.observe(this, { childList: true });
562
+ }
563
+ disconnectedCallback() {
564
+ this._childObserver?.disconnect();
565
+ this._childObserver = null;
566
+ cleanup(this);
567
+ }
568
+ attributeChangedCallback(name, oldValue, newValue) {
569
+ if (name === 'active') {
570
+ if (!newValue)
571
+ return;
572
+ if (!this.shadowRoot?.querySelector(`[data-tab-id='${newValue}']`)) {
573
+ render(this);
574
+ return;
575
+ }
576
+ updateActiveTabState(this, newValue, oldValue);
577
+ scrollActiveIntoView(this, newValue, true);
578
+ }
579
+ else {
580
+ render(this);
581
+ }
582
+ }
552
583
  }
553
584
  if (!customElements.get('ty-tabs')) {
554
- customElements.define('ty-tabs', TyTabs);
585
+ customElements.define('ty-tabs', TyTabs);
555
586
  }