Skip to content

POC: create custom tab #1492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 11 additions & 0 deletions packages/main/src/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ const metadata = {
},
properties: /** @lends sap.ui.webcomponents.main.Tab.prototype */ {

/**
* If set this HTML will be used to render the tab inside <code>ui5-tabcontainer</code>
* @private
* @type {String}
* @defaultvalue ""
* @since 1.0.0-rc.7
*/
customTabHtml: {
type: String,
},

/**
* The text to be displayed for the item.
* @type {string}
Expand Down
4 changes: 3 additions & 1 deletion packages/main/src/TabContainer.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
?disabled="{{this.disabled}}"
aria-labelledby="{{this.ariaLabelledBy}}"
>
{{#if this.isInline}}
{{#if this.isCustom}}
{{{ this.customHtml }}}
{{else if this.isInline}}
{{> inlineTab}}
{{else}}
{{> standardTab}}
Expand Down
16 changes: 16 additions & 0 deletions packages/main/src/TabContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ class TabContainer extends UI5Element {

return {
item,
isCustom: item.customTabHtml.length > 0,
customHtml: this.getHTML(item.customTabHtml),
isInline: this.tabLayout === TabLayout.Inline,
isMixedModeTab: !item.icon && this.mixedMode,
isTextOnlyTab: !item.icon && !this.mixedMode,
Expand All @@ -276,6 +278,20 @@ class TabContainer extends UI5Element {
}, this);
}

getHTML(htmlToCreate) {
const parser = this.constructor.getParser();
const doc = parser.parseFromString(htmlToCreate, "text/html");
return doc.body;
}

static getParser() {
if (!this.parser) {
this.parser = new DOMParser();
}

return this.parser;
}

onAfterRendering() {
this._scrollEnablement.scrollContainer = this._getHeaderScrollContainer();
this._updateScrolling();
Expand Down
13 changes: 9 additions & 4 deletions packages/main/test/pages/TabContainer.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ <h2>Tab Container</h2>
<ui5-tab text="Products" additional-text="125">
</ui5-tab>
<ui5-tab-separator></ui5-tab-separator>
<ui5-tab icon="sap-icon://menu2" text="Laptops" semantic-color="Positive" additional-text="25">
<ui5-tab id="custom-tab" icon="sap-icon://menu2" text="Laptops" semantic-color="Positive" additional-text="25">
</ui5-tab>
<ui5-tab icon="sap-icon://menu" text="Monitors" selected semantic-color="Critical" additional-text="45">
<ui5-tab id="custom-tab1" icon="sap-icon://menu" text="Monitors" selected semantic-color="Critical" additional-text="45">
</ui5-tab>
<ui5-tab icon="sap-icon://menu2" text="Keyboards" semantic-color="Negative" additional-text="15">
</ui5-tab>
Expand All @@ -73,7 +73,12 @@ <h2>Tab Container</h2>
</ui5-tabcontainer>
</section>

<section>
<script>
document.getElementById("custom-tab").customTabHtml = "<div>custom tab here</div>";
document.getElementById("custom-tab1").customTabHtml = "<div>another custom tab</div>";
</script>

<!-- <section>
<h2>Icon only</h2>
<ui5-tabcontainer show-overflow="true" id="tabContainerIconOnly">
<ui5-tab icon="sap-icon://card" selected>
Expand Down Expand Up @@ -367,6 +372,6 @@ <h3>TabContainer in Compact</h3>
result.innerHTML = event.detail.tab.text;
resultIdx.innerHTML = event.detail.tabIndex;
});
</script>
</script> -->
</body>
</html>