Skip to content

Commit e91c200

Browse files
authored
feat(ui5-tab-container): implement overflow-button slot (#2192)
1 parent d19fa5f commit e91c200

File tree

5 files changed

+66
-20
lines changed

5 files changed

+66
-20
lines changed

packages/main/src/Popover.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class Popover extends Popup {
257257

258258
isOpenerClicked(event) {
259259
const target = event.target;
260-
return target === this._opener || (target.getFocusDomRef && target.getFocusDomRef() === this._opener);
260+
return target === this._opener || (target.getFocusDomRef && target.getFocusDomRef() === this._opener) || event.composedPath().indexOf(this._opener) > -1;
261261
}
262262

263263
/**

packages/main/src/TabContainer.hbs

+15-8
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,22 @@
3232
<ui5-icon @click="{{_onHeaderForwardArrowClick}}" class="{{classes.headerForwardArrow}}" name="slim-arrow-right" tabindex="-1" accessible-name="{{nextIconACCName}}" show-tooltip></ui5-icon>
3333

3434
<!-- overflow button -->
35-
{{#if showOverflow}}
36-
<ui5-button
35+
{{#if shouldShowOverflow}}
36+
<div
37+
class="ui-tc__overflowButton"
3738
@click="{{_onOverflowButtonClick}}"
38-
class="{{classes.overflowButton}}"
39-
icon="{{overflowMenuIcon}}"
40-
design="Transparent"
41-
aria-label="{{overflowMenuTitle}}"
42-
aria-haspopup="true"
43-
></ui5-button>
39+
>
40+
{{#if overflowButton.length}}
41+
<slot name="overflowButton"></slot>
42+
{{else}}
43+
<ui5-button
44+
icon="{{overflowMenuIcon}}"
45+
design="Transparent"
46+
aria-label="{{overflowMenuTitle}}"
47+
aria-haspopup="true"
48+
></ui5-button>
49+
{{/if}}
50+
</div>
4451
{{/if}}
4552
</div>
4653

packages/main/src/TabContainer.js

+27-5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ const metadata = {
5757
individualSlots: true,
5858
listenFor: { include: ["*"] },
5959
},
60+
61+
/**
62+
* Defines the button which will open the overflow menu. If nothing is provided to this slot, the default button will be used.
63+
*
64+
* @type {HTMLElement[]}
65+
* @public
66+
* @slot
67+
* @since 1.0.0-rc.9
68+
*/
69+
overflowButton: {
70+
type: HTMLElement,
71+
},
6072
},
6173
properties: /** @lends sap.ui.webcomponents.main.TabContainer.prototype */ {
6274
/**
@@ -427,9 +439,19 @@ class TabContainer extends UI5Element {
427439
}
428440

429441
async _onOverflowButtonClick(event) {
442+
const button = this.overflowButton[0] || this.getDomRef().querySelector(".ui-tc__overflowButton > ui5-button");
443+
444+
if (event.target !== button) {
445+
return;
446+
}
447+
430448
this.responsivePopover = await this._respPopover();
431449
this.updateStaticAreaItemContentDensity();
432-
this.responsivePopover.open(this.getDomRef().querySelector(".ui-tc__overflowButton"));
450+
if (this.responsivePopover.opened) {
451+
this.responsivePopover.close();
452+
} else {
453+
this.responsivePopover.open(button);
454+
}
433455
}
434456

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

505+
get shouldShowOverflow() {
506+
return this.showOverflow && this._scrollable;
507+
}
508+
483509
get classes() {
484510
return {
485511
root: {
@@ -509,10 +535,6 @@ class TabContainer extends UI5Element {
509535
"ui5-tc__headerArrowRight": true,
510536
"ui5-tc__headerArrow--visible": this._scrollableForward,
511537
},
512-
overflowButton: {
513-
"ui-tc__overflowButton": true,
514-
"ui-tc__overflowButton--visible": this._scrollable,
515-
},
516538
content: {
517539
"ui5-tc__content": true,
518540
"ui5-tc__content--collapsed": this._contentCollapsed,

packages/main/src/themes/TabContainer.css

-5
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,10 @@
7272
}
7373

7474
.ui-tc__overflowButton {
75-
display: none;
7675
margin-left: auto;
7776
margin-right: 0.25rem;
7877
}
7978

80-
.ui-tc__overflowButton--visible {
81-
display: block;
82-
}
83-
8479
.ui5-tc-root.ui5-tc--textOnly .ui5-tc__content {
8580
height: calc(100% - var(--_ui5_tc_header_height_text_only)); /* the header height (text only tabs) */
8681
}

packages/main/test/pages/TabContainer.html

+23-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,29 @@ <h2>tabs-placement=Bottom</h2>
407407
<ui5-button>Button 3</ui5-button>
408408
</ui5-tab>
409409
</ui5-tabcontainer>
410-
</section>
410+
</section>
411+
412+
<section>
413+
<h2>Tab Container With Custom Menu Button</h2>
414+
<ui5-tabcontainer id="tabContainer-custom-icon" fixed collapsed show-overflow>
415+
<ui5-tab stable-dom-ref="products-ref" text="Products" additional-text="125">
416+
</ui5-tab>
417+
<ui5-tab-separator></ui5-tab-separator>
418+
<ui5-tab icon="sap-icon://menu2" text="Laptops" semantic-color="Positive" additional-text="25">
419+
</ui5-tab>
420+
<ui5-tab icon="sap-icon://menu" text="Monitors" selected semantic-color="Critical" additional-text="45">
421+
</ui5-tab>
422+
<ui5-tab icon="sap-icon://menu2" text="Keyboards" semantic-color="Negative" additional-text="15">
423+
</ui5-tab>
424+
<ui5-tab icon="sap-icon://menu2" disabled text="Disabled" semantic-color="Negative" additional-text="40">
425+
</ui5-tab>
426+
<ui5-tab icon="sap-icon://menu2" text="Neutral" semantic-color="Neutral" additional-text="40">
427+
</ui5-tab>
428+
<ui5-tab icon="sap-icon://menu2" text="Default" additional-text="40">
429+
</ui5-tab>
430+
<ui5-button slot="overflowButton" aria-label="Menu icon here" icon="menu" design="Transparent"></ui5-button>
431+
</ui5-tabcontainer>
432+
</section>
411433

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

0 commit comments

Comments
 (0)