Skip to content

Commit

Permalink
feat(ui5-tab-container): implement overflow-button slot (#2192)
Browse files Browse the repository at this point in the history
  • Loading branch information
fifoosid committed Sep 14, 2020
1 parent 11ba79f commit 647ae84
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/main/src/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class Popover extends Popup {

isOpenerClicked(event) {
const target = event.target;
return target === this._opener || (target.getFocusDomRef && target.getFocusDomRef() === this._opener);
return target === this._opener || (target.getFocusDomRef && target.getFocusDomRef() === this._opener) || event.composedPath().indexOf(this._opener) > -1;
}

/**
Expand Down
23 changes: 15 additions & 8 deletions packages/main/src/TabContainer.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,22 @@
<ui5-icon @click="{{_onHeaderForwardArrowClick}}" class="{{classes.headerForwardArrow}}" name="slim-arrow-right" tabindex="-1" accessible-name="{{nextIconACCName}}" show-tooltip></ui5-icon>

<!-- overflow button -->
{{#if showOverflow}}
<ui5-button
{{#if shouldShowOverflow}}
<div
class="ui-tc__overflowButton"
@click="{{_onOverflowButtonClick}}"
class="{{classes.overflowButton}}"
icon="{{overflowMenuIcon}}"
design="Transparent"
aria-label="{{overflowMenuTitle}}"
aria-haspopup="true"
></ui5-button>
>
{{#if overflowButton.length}}
<slot name="overflowButton"></slot>
{{else}}
<ui5-button
icon="{{overflowMenuIcon}}"
design="Transparent"
aria-label="{{overflowMenuTitle}}"
aria-haspopup="true"
></ui5-button>
{{/if}}
</div>
{{/if}}
</div>

Expand Down
32 changes: 27 additions & 5 deletions packages/main/src/TabContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ const metadata = {
individualSlots: true,
listenFor: { include: ["*"] },
},

/**
* Defines the button which will open the overflow menu. If nothing is provided to this slot, the default button will be used.
*
* @type {HTMLElement[]}
* @public
* @slot
* @since 1.0.0-rc.9
*/
overflowButton: {
type: HTMLElement,
},
},
properties: /** @lends sap.ui.webcomponents.main.TabContainer.prototype */ {
/**
Expand Down Expand Up @@ -427,9 +439,19 @@ class TabContainer extends UI5Element {
}

async _onOverflowButtonClick(event) {
const button = this.overflowButton[0] || this.getDomRef().querySelector(".ui-tc__overflowButton > ui5-button");

if (event.target !== button) {
return;
}

this.responsivePopover = await this._respPopover();
this.updateStaticAreaItemContentDensity();
this.responsivePopover.open(this.getDomRef().querySelector(".ui-tc__overflowButton"));
if (this.responsivePopover.opened) {
this.responsivePopover.close();
} else {
this.responsivePopover.open(button);
}
}

_onHeaderBackArrowClick() {
Expand Down Expand Up @@ -480,6 +502,10 @@ class TabContainer extends UI5Element {
return staticAreaItem.querySelector(`#${this._id}-overflowMenu`);
}

get shouldShowOverflow() {
return this.showOverflow && this._scrollable;
}

get classes() {
return {
root: {
Expand Down Expand Up @@ -509,10 +535,6 @@ class TabContainer extends UI5Element {
"ui5-tc__headerArrowRight": true,
"ui5-tc__headerArrow--visible": this._scrollableForward,
},
overflowButton: {
"ui-tc__overflowButton": true,
"ui-tc__overflowButton--visible": this._scrollable,
},
content: {
"ui5-tc__content": true,
"ui5-tc__content--collapsed": this._contentCollapsed,
Expand Down
5 changes: 0 additions & 5 deletions packages/main/src/themes/TabContainer.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,10 @@
}

.ui-tc__overflowButton {
display: none;
margin-left: auto;
margin-right: 0.25rem;
}

.ui-tc__overflowButton--visible {
display: block;
}

.ui5-tc-root.ui5-tc--textOnly .ui5-tc__content {
height: calc(100% - var(--_ui5_tc_header_height_text_only)); /* the header height (text only tabs) */
}
Expand Down
24 changes: 23 additions & 1 deletion packages/main/test/pages/TabContainer.html
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,29 @@ <h2>tabs-placement=Bottom</h2>
<ui5-button>Button 3</ui5-button>
</ui5-tab>
</ui5-tabcontainer>
</section>
</section>

<section>
<h2>Tab Container With Custom Menu Button</h2>
<ui5-tabcontainer id="tabContainer-custom-icon" fixed collapsed show-overflow>
<ui5-tab stable-dom-ref="products-ref" 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>
<ui5-tab 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>
<ui5-tab icon="sap-icon://menu2" disabled text="Disabled" semantic-color="Negative" additional-text="40">
</ui5-tab>
<ui5-tab icon="sap-icon://menu2" text="Neutral" semantic-color="Neutral" additional-text="40">
</ui5-tab>
<ui5-tab icon="sap-icon://menu2" text="Default" additional-text="40">
</ui5-tab>
<ui5-button slot="overflowButton" aria-label="Menu icon here" icon="menu" design="Transparent"></ui5-button>
</ui5-tabcontainer>
</section>

<script>
document.getElementById("tabContainer1").addEventListener("ui5-tabSelect", function (event) {
Expand Down

0 comments on commit 647ae84

Please sign in to comment.