@@ -9,16 +9,24 @@ import '@umbraco-ui/uui-popover-container/lib';
9
9
import '@umbraco-ui/uui-symbol-more/lib' ;
10
10
11
11
import { UUITabElement } from './uui-tab.element' ;
12
+ import { UUIPopoverContainerElement } from '@umbraco-ui/uui-popover-container/lib' ;
12
13
13
14
/**
14
15
* @element uui-tab-group
15
16
* @slot - Default slot for the tab group
17
+ * @cssprop --uui-tab-group-dropdown-tab-text - Define the tab text color in the dropdown
18
+ * @cssprop --uui-tab-group-dropdown-tab-text-hover - Define the tab text hover color in the dropdown
19
+ * @cssprop --uui-tab-group-dropdown-tab-text-active - Define the tab text active color in the dropdown
20
+ * @cssprop --uui-tab-group-dropdown-background - Define the background color of the dropdown
16
21
*/
17
22
@defineElement ( 'uui-tab-group' )
18
23
export class UUITabGroupElement extends LitElement {
19
24
@query ( '#more-button' )
20
25
private _moreButtonElement ! : UUIButtonElement ;
21
26
27
+ @query ( '#popover-container' )
28
+ private _popoverContainerElement ! : UUIPopoverContainerElement ;
29
+
22
30
@queryAssignedElements ( {
23
31
flatten : true ,
24
32
selector : 'uui-tab, [uui-tab], [role=tab]' ,
@@ -44,7 +52,6 @@ export class UUITabGroupElement extends LitElement {
44
52
#hiddenTabElementsMap: Map < UUITabElement , UUITabElement > = new Map ( ) ;
45
53
46
54
#visibilityBreakpoints: number [ ] = [ ] ;
47
- #oldBreakpoint = 0 ;
48
55
49
56
#resizeObserver: ResizeObserver = new ResizeObserver (
50
57
this . #onResize. bind ( this )
@@ -114,31 +121,10 @@ export class UUITabGroupElement extends LitElement {
114
121
const buttonWidth = this . _moreButtonElement . offsetWidth ;
115
122
116
123
// Only update if the container is smaller than the last breakpoint
117
- if (
118
- this . #visibilityBreakpoints. slice ( - 1 ) [ 0 ] < containerWidth &&
119
- this . #hiddenTabElements. length === 0
120
- )
124
+ const lastBreakpoint = this . #visibilityBreakpoints. slice ( - 1 ) [ 0 ] ;
125
+ if ( lastBreakpoint < containerWidth && this . #hiddenTabElements. length === 0 )
121
126
return ;
122
127
123
- // Only update if the new breakpoint is different from the old one
124
- let newBreakpoint = Number . MAX_VALUE ;
125
-
126
- for ( let i = this . #visibilityBreakpoints. length - 1 ; i > - 1 ; i -- ) {
127
- const breakpoint = this . #visibilityBreakpoints[ i ] ;
128
- // Subtract the button width when we are not at the last breakpoint
129
- const containerWidthButtonWidth =
130
- containerWidth -
131
- ( i !== this . #visibilityBreakpoints. length - 1 ? buttonWidth : 0 ) ;
132
-
133
- if ( breakpoint < containerWidthButtonWidth ) {
134
- newBreakpoint = i ;
135
- break ;
136
- }
137
- }
138
-
139
- if ( newBreakpoint === this . #oldBreakpoint) return ;
140
- this . #oldBreakpoint = newBreakpoint ;
141
-
142
128
// Do the update
143
129
// Reset the hidden tabs
144
130
this . #hiddenTabElements. forEach ( el => {
@@ -183,22 +169,33 @@ export class UUITabGroupElement extends LitElement {
183
169
}
184
170
}
185
171
172
+ if ( this . #hiddenTabElements. length === 0 ) {
173
+ // close the popover
174
+ this . _popoverContainerElement . hidePopover ( ) ;
175
+ }
176
+
186
177
hasActiveTabInDropdown
187
178
? this . _moreButtonElement . classList . add ( 'active-inside' )
188
179
: this . _moreButtonElement . classList . remove ( 'active-inside' ) ;
189
180
190
181
this . requestUpdate ( ) ;
191
182
}
192
183
193
- #calculateBreakPoints( ) {
184
+ async #calculateBreakPoints( ) {
194
185
// Whenever a tab is added or removed, we need to recalculate the breakpoints
186
+
187
+ await this . updateComplete ; // Wait for the tabs to be rendered
195
188
let childrenWidth = 0 ;
196
189
197
190
for ( let i = 0 ; i < this . #tabElements. length ; i ++ ) {
191
+ this . #tabElements[ i ] . style . display = '' ;
198
192
childrenWidth += this . #tabElements[ i ] . offsetWidth ;
199
193
this . #visibilityBreakpoints[ i ] = childrenWidth ;
200
194
}
201
195
196
+ const tolerance = 2 ;
197
+ this . style . width = childrenWidth + tolerance + 'px' ;
198
+
202
199
this . #updateCollapsibleTabs( this . offsetWidth ) ;
203
200
}
204
201
@@ -225,7 +222,6 @@ export class UUITabGroupElement extends LitElement {
225
222
<uui- popover- container
226
223
id= "popover-container"
227
224
popover
228
- margin = "10"
229
225
placement = "bottom-end" >
230
226
<div id= "hidden-tabs-container" >
231
227
${ repeat ( this . #hiddenTabElements, el => html `${ el } ` ) }
@@ -238,11 +234,24 @@ export class UUITabGroupElement extends LitElement {
238
234
css `
239
235
: host {
240
236
display : flex;
241
- flex-wrap : wrap ;
237
+ flex-wrap : nowrap ;
242
238
color : var (--uui-tab-text );
243
- background : var (--uui-tab-background , none);
244
239
height : 100% ;
245
240
min-height : 48px ;
241
+ overflow : hidden;
242
+ text-wrap : nowrap;
243
+ }
244
+
245
+ # popover-container {
246
+ --uui-tab-text : var (--uui-tab-group-dropdown-tab-text , unset);
247
+ --uui-tab-text-hover : var (
248
+ --uui-tab-group-dropdown-tab-text-hover ,
249
+ unset
250
+ );
251
+ --uui-tab-text-active : var (
252
+ --uui-tab-group-dropdown-tab-text-active ,
253
+ unset
254
+ );
246
255
}
247
256
248
257
::slotted (* : not (: last-of-type )) {
@@ -257,7 +266,10 @@ export class UUITabGroupElement extends LitElement {
257
266
width : fit-content;
258
267
display : flex;
259
268
flex-direction : column;
260
- background : var (--uui-color-surface );
269
+ background-color : var (
270
+ --uui-tab-group-dropdown-background ,
271
+ var (--uui-color-surface )
272
+ );
261
273
border-radius : var (--uui-border-radius );
262
274
box-shadow : var (--uui-shadow-depth-3 );
263
275
overflow : hidden;
@@ -267,8 +279,12 @@ export class UUITabGroupElement extends LitElement {
267
279
}
268
280
269
281
# more-button {
270
- margin-left : auto;
271
282
position : relative;
283
+
284
+ --uui-button-contrast : var (--uui-tab-text );
285
+ --uui-button-contrast-hover : var (--uui-tab-text-hover );
286
+ --uui-button-background-color : transparent;
287
+ --uui-button-background-color-hover : transparent;
272
288
}
273
289
# more-button ::before {
274
290
content : '' ;
0 commit comments