MCPcopy Create free account
hub / github.com/UI5/webcomponents / _setItemsForStrip

Method _setItemsForStrip

packages/main/src/TabContainer.ts:1001–1052  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

999 }
1000
1001 _setItemsForStrip() {
1002 const tabStrip = this._getTabStrip();
1003 let allItemsWidth = 0;
1004
1005 const itemsDomRefs = this.items.map(item => item.getDomRefInStrip()) as Array<TabInStrip | TabSeparatorInStrip>;
1006
1007 let allVisibleItemsWidth = 0;
1008
1009 const selectedTab = this._getRootTab(this._selectedTab);
1010 const containerWidth = this._getTabStrip().offsetWidth;
1011 const selectedTabDomRef = selectedTab?.getDomRefInStrip() as TabInStrip | undefined;
1012 const visibleItemsDomRefs = itemsDomRefs.filter(item => !item.hidden);
1013
1014 visibleItemsDomRefs.forEach(item => {
1015 allVisibleItemsWidth += this._getItemWidth(item);
1016 });
1017
1018 const changeTabPosition = visibleItemsDomRefs.length !== itemsDomRefs.length && this.isModeStartAndEnd && selectedTabDomRef && visibleItemsDomRefs.indexOf(selectedTabDomRef) !== -1 && allVisibleItemsWidth < containerWidth && this._getItemWidth(selectedTabDomRef) < containerWidth;
1019
1020 // make sure the overflows are hidden
1021 this._getStartOverflow().setAttribute("hidden", "");
1022 this._getEndOverflow().setAttribute("hidden", "");
1023
1024 let firstVisibleIndex;
1025
1026 if (changeTabPosition) {
1027 firstVisibleIndex = itemsDomRefs.indexOf(visibleItemsDomRefs[0]);
1028 }
1029
1030 // show all tabs
1031 for (let i = 0; i < itemsDomRefs.length; i++) {
1032 itemsDomRefs[i].removeAttribute("hidden");
1033 itemsDomRefs[i].removeAttribute("start-overflow");
1034 itemsDomRefs[i].removeAttribute("end-overflow");
1035 }
1036
1037 itemsDomRefs.forEach(item => {
1038 allItemsWidth += this._getItemWidth(item);
1039 });
1040
1041 const hasOverflow = tabStrip.offsetWidth < allItemsWidth;
1042 if (!hasOverflow) {
1043 return;
1044 }
1045
1046 if (this.isModeStartAndEnd) {
1047 this._updateStartAndEndOverflow(itemsDomRefs, firstVisibleIndex);
1048 this._updateOverflowCounters();
1049 } else {
1050 this._updateEndOverflow(itemsDomRefs);
1051 }
1052 }
1053
1054 _getRootTab(tab: Tab | undefined): Tab | undefined {
1055 while (tab?.hasAttribute("ui5-tab")) {

Callers 1

onAfterRenderingMethod · 0.95

Calls 9

_getTabStripMethod · 0.95
_getRootTabMethod · 0.95
_getItemWidthMethod · 0.95
_getStartOverflowMethod · 0.95
_getEndOverflowMethod · 0.95
_updateEndOverflowMethod · 0.95
getDomRefInStripMethod · 0.45

Tested by

no test coverage detected