@@ -419,7 +419,10 @@ class TabContainer extends UI5Element {
419419
420420 if ( ! this . shadowRoot ! . contains ( document . activeElement ) ) {
421421 const focusStart = this . _getRootTab ( this . _selectedTab ) ;
422- this . _itemNavigation . setCurrentItem ( focusStart ) ;
422+
423+ if ( focusStart ) {
424+ this . _itemNavigation . setCurrentItem ( focusStart ) ;
425+ }
423426 }
424427
425428 if ( this . responsivePopover ?. opened ) {
@@ -776,7 +779,7 @@ class TabContainer extends UI5Element {
776779 await renderFinished ( ) ;
777780
778781 const selectedTopLevel = this . _getRootTab ( this . _selectedTab ) ;
779- selectedTopLevel . getTabInStripDomRef ( ) ! . focus ( ) ;
782+ selectedTopLevel ? .getTabInStripDomRef ( ) ! . focus ( ) ;
780783 }
781784
782785 /**
@@ -988,13 +991,13 @@ class TabContainer extends UI5Element {
988991 }
989992 }
990993
991- _getRootTab ( tab : Tab ) {
992- while ( tab . hasAttribute ( "ui5-tab" ) ) {
993- if ( tab . parentElement ! . hasAttribute ( "ui5-tabcontainer" ) ) {
994+ _getRootTab ( tab : Tab | undefined ) : Tab | undefined {
995+ while ( tab ? .hasAttribute ( "ui5-tab" ) ) {
996+ if ( tab . parentElement ? .hasAttribute ( "ui5-tabcontainer" ) ) {
994997 break ;
995998 }
996999
997- tab = tab . parentElement as Tab ;
1000+ tab = ( tab . parentElement ?? undefined ) as Tab | undefined ;
9981001 }
9991002
10001003 return tab ;
@@ -1004,7 +1007,7 @@ class TabContainer extends UI5Element {
10041007 // show end overflow
10051008 this . _getEndOverflow ( ) . removeAttribute ( "hidden" ) ;
10061009 const selectedTab = this . _getRootTab ( this . _selectedTab ) ;
1007- const selectedTabDomRef = selectedTab . getTabInStripDomRef ( ) ! ;
1010+ const selectedTabDomRef = selectedTab ? .getTabInStripDomRef ( ) as ITab | undefined ;
10081011 const containerWidth = this . _getTabStrip ( ) . offsetWidth ;
10091012
10101013 const selectedItemIndexAndWidth = this . _getSelectedItemIndexAndWidth ( itemsDomRefs , selectedTabDomRef ) ;
@@ -1021,7 +1024,7 @@ class TabContainer extends UI5Element {
10211024 _updateStartAndEndOverflow ( itemsDomRefs : Array < ITab > ) {
10221025 let containerWidth = this . _getTabStrip ( ) . offsetWidth ;
10231026 const selectedTab = this . _getRootTab ( this . _selectedTab ) ;
1024- const selectedTabDomRef = selectedTab . getTabInStripDomRef ( ) ! ;
1027+ const selectedTabDomRef = selectedTab ? .getTabInStripDomRef ( ) as ITab | undefined ;
10251028 const selectedItemIndexAndWidth = this . _getSelectedItemIndexAndWidth ( itemsDomRefs , selectedTabDomRef ) ;
10261029 const hasStartOverflow = this . _hasStartOverflow ( containerWidth , itemsDomRefs , selectedItemIndexAndWidth ) ;
10271030 const hasEndOverflow = this . _hasEndOverflow ( containerWidth , itemsDomRefs , selectedItemIndexAndWidth ) ;
@@ -1140,7 +1143,14 @@ class TabContainer extends UI5Element {
11401143 return itemDomRef . offsetWidth + margins ;
11411144 }
11421145
1143- _getSelectedItemIndexAndWidth ( itemsDomRefs : Array < ITab > , selectedTabDomRef : ITab ) {
1146+ _getSelectedItemIndexAndWidth ( itemsDomRefs : Array < ITab > , selectedTabDomRef : ITab | undefined ) {
1147+ if ( ! selectedTabDomRef ) {
1148+ return {
1149+ index : 0 ,
1150+ width : 0 ,
1151+ } ;
1152+ }
1153+
11441154 let index = itemsDomRefs . indexOf ( selectedTabDomRef ) ;
11451155 let width = selectedTabDomRef . offsetWidth ;
11461156 let selectedSeparator ;
0 commit comments