@@ -2,6 +2,10 @@ import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
2
2
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js" ;
3
3
import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js" ;
4
4
import ScrollEnablement from "@ui5/webcomponents-base/dist/delegate/ScrollEnablement.js" ;
5
+ import slideDown from "@ui5/webcomponents-base/dist/animations/slideDown.js" ;
6
+ import slideUp from "@ui5/webcomponents-base/dist/animations/slideUp.js" ;
7
+ import AnimationMode from "@ui5/webcomponents-base/dist/types/AnimationMode.js" ;
8
+ import { getAnimationMode } from "@ui5/webcomponents-base/dist/config/AnimationMode.js" ;
5
9
import ItemNavigation from "@ui5/webcomponents-base/dist/delegate/ItemNavigation.js" ;
6
10
import { isSpace , isEnter } from "@ui5/webcomponents-base/dist/Keys.js" ;
7
11
import { getRTL } from "@ui5/webcomponents-base/dist/config/RTL.js" ;
@@ -151,6 +155,16 @@ const metadata = {
151
155
type : Boolean ,
152
156
noAttribute : true ,
153
157
} ,
158
+
159
+ _animationRunning : {
160
+ type : Boolean ,
161
+ noAttribute : true ,
162
+ } ,
163
+
164
+ _contentCollapsed : {
165
+ type : Boolean ,
166
+ noAttribute : true ,
167
+ } ,
154
168
} ,
155
169
events : /** @lends sap.ui.webcomponents.main.TabContainer.prototype */ {
156
170
@@ -268,6 +282,10 @@ class TabContainer extends UI5Element {
268
282
} ;
269
283
item . _itemSelectCallback = this . _onItemSelect . bind ( this ) ;
270
284
} ) ;
285
+
286
+ if ( ! this . _animationRunning ) {
287
+ this . _contentCollapsed = this . collapsed ;
288
+ }
271
289
}
272
290
273
291
onAfterRendering ( ) {
@@ -353,15 +371,51 @@ class TabContainer extends UI5Element {
353
371
}
354
372
} , this ) ;
355
373
356
- // update collapsed state
357
- if ( ! this . fixed ) {
358
- if ( selectedTab === this . _selectedTab ) {
359
- this . collapsed = ! this . collapsed ;
360
- } else {
361
- this . collapsed = false ;
362
- }
374
+ if ( this . fixed ) {
375
+ this . selectTab ( selectedTab , selectedTabIndex ) ;
376
+ return ;
377
+ }
378
+
379
+ if ( ! this . animate ) {
380
+ this . toggle ( selectedTab ) ;
381
+ this . selectTab ( selectedTab , selectedTabIndex ) ;
382
+ return ;
383
+ }
384
+
385
+ this . toggleAnimated ( selectedTab ) ;
386
+ this . selectTab ( selectedTab , selectedTabIndex ) ;
387
+ }
388
+
389
+ async toggleAnimated ( selectedTab ) {
390
+ const content = this . shadowRoot . querySelector ( ".ui5-tc__content" ) ;
391
+ let animationPromise = null ;
392
+
393
+ this . _animationRunning = true ;
394
+
395
+ if ( selectedTab === this . _selectedTab ) {
396
+ // click on already selected tab - animate both directions
397
+ this . collapsed = ! this . collapsed ;
398
+ animationPromise = this . collapsed ? this . slideContentUp ( content ) : this . slideContentDown ( content ) ;
399
+ } else {
400
+ // click on new tab - animate if the content is currently collapsed
401
+ animationPromise = this . collapsed ? this . slideContentDown ( content ) : Promise . resolve ( ) ;
402
+ this . collapsed = false ;
403
+ }
404
+
405
+ await animationPromise ;
406
+ this . _contentCollapsed = this . collapsed ;
407
+ this . _animationRunning = false ;
408
+ }
409
+
410
+ toggle ( selectedTab ) {
411
+ if ( selectedTab === this . _selectedTab ) {
412
+ this . collapsed = ! this . collapsed ;
413
+ } else {
414
+ this . collapsed = false ;
363
415
}
416
+ }
364
417
418
+ selectTab ( selectedTab , selectedTabIndex ) {
365
419
// select the tab
366
420
this . _selectedTab = selectedTab ;
367
421
this . fireEvent ( "tabSelect" , {
@@ -370,6 +424,14 @@ class TabContainer extends UI5Element {
370
424
} ) ;
371
425
}
372
426
427
+ slideContentDown ( element ) {
428
+ return slideDown ( { element } ) . promise ( ) ;
429
+ }
430
+
431
+ slideContentUp ( element ) {
432
+ return slideUp ( { element } ) . promise ( ) ;
433
+ }
434
+
373
435
async _onOverflowButtonClick ( event ) {
374
436
this . responsivePopover = await this . _respPopover ( ) ;
375
437
this . updateStaticAreaItemContentDensity ( ) ;
@@ -454,7 +516,7 @@ class TabContainer extends UI5Element {
454
516
} ,
455
517
content : {
456
518
"ui5-tc__content" : true ,
457
- "ui5-tc__content--collapsed" : this . collapsed ,
519
+ "ui5-tc__content--collapsed" : this . _contentCollapsed ,
458
520
} ,
459
521
} ;
460
522
}
@@ -491,6 +553,10 @@ class TabContainer extends UI5Element {
491
553
return getRTL ( ) ? "rtl" : undefined ;
492
554
}
493
555
556
+ get animate ( ) {
557
+ return getAnimationMode ( ) !== AnimationMode . None ;
558
+ }
559
+
494
560
static async onDefine ( ) {
495
561
await Promise . all ( [
496
562
Button . define ( ) ,
0 commit comments