Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions packages/main/src/TabContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,17 +378,20 @@ class TabContainer extends UI5Element {
}

onBeforeRendering() {
// update selected tab
this._allItemsAndSubItems = this._getAllSubItems(this.items);
if (this._allItemsAndSubItems.length) {
const selectedTabs = this._allItemsAndSubItems.filter(tab => tab.selected);
if (selectedTabs.length) {
this._selectedTab = selectedTabs[0];
} else {
this._selectedTab = this._allItemsAndSubItems[0];
this._selectedTab._selected = true;
}
if (!this._allItemsAndSubItems.length) {
return;
}

// update selected tab
const selectedTabs = this._allItemsAndSubItems.filter(tab => tab.selected);
if (selectedTabs.length) {
this._selectedTab = selectedTabs[0];
} else {
this._selectedTab = this._allItemsAndSubItems[0];
this._selectedTab._selected = true;
}

this._setItemsPrivateProperties(this.items);

if (!this._animationRunning) {
Expand All @@ -401,6 +404,10 @@ class TabContainer extends UI5Element {
}

onAfterRendering() {
if (!this.items.length) {
return;
}

this._setItemsForStrip();

if (!this.shadowRoot.contains(document.activeElement)) {
Expand Down
7 changes: 6 additions & 1 deletion packages/main/test/pages/TabContainer.html
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,11 @@ <h2>Text only Start And End Overflow Custom Overflow Buttons</h2>
<ui5-button id="selectLast">Select Last Tab</ui5-button>
<ui5-button id="selectNested">Select a Nested Tab</ui5-button>
</section>
<section>
<ui5-title>Empty Tab Container</ui5-title>
<ui5-tabcontainer id="tabContainerEmpty">
</ui5-tabcontainer>
</section>
</section>

<script>
Expand Down Expand Up @@ -794,7 +799,7 @@ <h2>Text only Start And End Overflow Custom Overflow Buttons</h2>
walk(tab.subTabs, callback);
}});
};

function getTabSelectorCallback(target) {
return (tab) => tab.selected = tab === target;
}
Expand Down
8 changes: 6 additions & 2 deletions packages/main/test/specs/TabContainer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ describe("TabContainer general interaction", () => {
assert.strictEqual(selectedFilter.id, selectedTab.id, "The IDs of the ui5-tab and the rendered tab matches.");
});

it("tests empty tab container", async () => {
assert.ok(await browser.$("#tabContainerEmpty").isDisplayed(), "Empty tab container is rendered.");
});

it("tests tabSelect event", async () => {
const item = await browser.$("#tabContainer1").shadow$(".ui5-tab-strip-item:nth-child(3)");
const result = await browser.$("#result");
Expand Down Expand Up @@ -46,7 +50,7 @@ describe("TabContainer general interaction", () => {
// Assert
assert.ok(await selectedTab.hasClass("ui5-tab-strip-item--selected"), "previously selected tab is still selected");
assert.notOk(await newTab.hasClass("ui5-tab-strip-item--selected"), "clicked tab is not selected");

// Clean-up
await cbPrevent.click();
});
Expand Down Expand Up @@ -229,7 +233,7 @@ describe("TabContainer general interaction", () => {
// Setup
const getTabInStripDomRef = tab => tab.getTabInStripDomRef();
const getElementInBrowser = el => document.querySelector(el);

const tabContainer = await browser.$("#tcSmall");
await tabContainer.scrollIntoView();

Expand Down