@@ -12,7 +12,6 @@ import {
12
12
focusElementInGroup ,
13
13
FocusElementInGroupDestination ,
14
14
getElementDir ,
15
- slotChangeGetAssignedElements ,
16
15
} from "../../utils/dom" ;
17
16
import { createObserver } from "../../utils/observers" ;
18
17
import { Scale } from "../interfaces" ;
@@ -72,6 +71,8 @@ export class TabNav extends LitElement {
72
71
return filterDirectChildren < TabTitle [ "el" ] > ( this . el , "calcite-tab-title" ) ;
73
72
}
74
73
74
+ private makeFirstVisibleTabClosable = false ;
75
+
75
76
// #endregion
76
77
77
78
// #region State Properties
@@ -367,14 +368,21 @@ export class TabNav extends LitElement {
367
368
( event . currentTarget as HTMLDivElement ) . scrollBy ( scrollByX , 0 ) ;
368
369
}
369
370
370
- private onSlotChange ( event : Event ) : void {
371
+ private onSlotChange ( ) : void {
371
372
this . intersectionObserver ?. disconnect ( ) ;
372
373
373
- const slottedElements = slotChangeGetAssignedElements ( event , "calcite-tab-title" ) ;
374
- slottedElements . forEach ( ( child ) => {
374
+ const tabTitles = this . tabTitles ;
375
+ tabTitles . forEach ( ( child ) => {
375
376
this . intersectionObserver ?. observe ( child ) ;
376
377
} ) ;
377
- this . calciteInternalTabNavSlotChange . emit ( slottedElements ) ;
378
+ const visibleTabTitlesIndices = this . getVisibleTabTitlesIndices ( tabTitles ) ;
379
+ const totalVisibleTabTitles = visibleTabTitlesIndices . length ;
380
+ if ( totalVisibleTabTitles > 1 && this . makeFirstVisibleTabClosable ) {
381
+ tabTitles [ visibleTabTitlesIndices [ 0 ] ] . closable = true ;
382
+ this . makeFirstVisibleTabClosable = false ;
383
+ }
384
+
385
+ this . calciteInternalTabNavSlotChange . emit ( tabTitles ) ;
378
386
}
379
387
380
388
private storeTabTitleWrapperRef ( el : HTMLDivElement ) {
@@ -517,18 +525,23 @@ export class TabNav extends LitElement {
517
525
} ) ;
518
526
}
519
527
520
- private handleTabTitleClose ( closedTabTitleEl : TabTitle [ "el" ] ) : void {
521
- const { tabTitles } = this ;
522
- const selectionModified = closedTabTitleEl . selected ;
523
-
524
- const visibleTabTitlesIndices = tabTitles . reduce (
528
+ private getVisibleTabTitlesIndices ( tabTitles : TabTitle [ "el" ] [ ] ) : number [ ] {
529
+ return tabTitles . reduce (
525
530
( tabTitleIndices : number [ ] , tabTitle , index ) =>
526
531
! tabTitle . closed ? [ ...tabTitleIndices , index ] : tabTitleIndices ,
527
532
[ ] ,
528
533
) ;
534
+ }
535
+
536
+ private handleTabTitleClose ( closedTabTitleEl : TabTitle [ "el" ] ) : void {
537
+ const { tabTitles } = this ;
538
+ const selectionModified = closedTabTitleEl . selected ;
539
+
540
+ const visibleTabTitlesIndices = this . getVisibleTabTitlesIndices ( tabTitles ) ;
529
541
const totalVisibleTabTitles = visibleTabTitlesIndices . length ;
530
542
531
543
if ( totalVisibleTabTitles === 1 && tabTitles [ visibleTabTitlesIndices [ 0 ] ] . closable ) {
544
+ this . makeFirstVisibleTabClosable = true ;
532
545
tabTitles [ visibleTabTitlesIndices [ 0 ] ] . closable = false ;
533
546
this . selectedTabId = visibleTabTitlesIndices [ 0 ] ;
534
547
0 commit comments