Skip to content

Commit e0ff36d

Browse files
authored
feat(ui5-shellbar): API improvements (#421)
* feat(ui5-shellbar): API improvements - adds a targetRef parameter to press event of shellbar-item - adds a support for preventDefault() of press event of shellbar-item - provides a public method #closeOverflow to the shellbar component FIXES: #419
1 parent 60611c4 commit e0ff36d

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

packages/main/src/ShellBar.js

+28-2
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,20 @@ class ShellBar extends UI5Element {
352352
this._isInitialRendering = true;
353353
this._focussedItem = null;
354354

355+
// marks if preventDefault() is called in item's press handler
356+
this._defaultItemPressPrevented = false;
357+
355358
const that = this;
356359

357360
this._actionList = {
358361
itemPress: event => {
359362
const popover = this.shadowRoot.querySelector(".sapWCShellBarOverflowPopover");
360363

361-
popover.close();
364+
if (!this._defaultItemPressPrevented) {
365+
popover.close();
366+
}
367+
368+
this._defaultItemPressPrevented = false;
362369
},
363370
};
364371

@@ -480,6 +487,19 @@ class ShellBar extends UI5Element {
480487
}
481488
}
482489

490+
/**
491+
* Closes the overflow area.
492+
* Useful to manually close the overflow after having suppressed automatic closing with preventDefault() of ShellbarItem's press event
493+
* @public
494+
*/
495+
closeOverflow() {
496+
const popover = this.shadowRoot.querySelector(".sapWCShellBarOverflowPopover");
497+
498+
if (popover) {
499+
popover.close();
500+
}
501+
}
502+
483503
_handleBarBreakpoints() {
484504
const width = this.getBoundingClientRect().width;
485505
const breakpoints = ShellBar.FIORI_3_BREAKPOINTS;
@@ -679,7 +699,13 @@ class ShellBar extends UI5Element {
679699
this._itemNav.currentIndex = elementIndex;
680700

681701
if (refItemId) {
682-
this.items.filter(item => item.shadowRoot.querySelector(`#${refItemId}`))[0].fireEvent("press");
702+
const shellbarItem = this.items.filter(item => {
703+
return item.shadowRoot.querySelector(`#${refItemId}`);
704+
})[0];
705+
706+
const prevented = !shellbarItem.fireEvent("press", { targetRef: event.target }, true);
707+
708+
this._defaultItemPressPrevented = prevented;
683709
}
684710
}
685711

packages/main/src/ShellBarItem.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ const metadata = {
4242
* Fired, when the item is pressed.
4343
*
4444
* @event
45+
* @param {HTMLElement} targetRef dom ref of the clicked element
4546
* @public
4647
*/
47-
press: {},
48+
press: {
49+
detail: {
50+
targetRef: { type: HTMLElement },
51+
},
52+
},
4853
},
4954
};
5055

packages/main/test/sap/ui/webcomponents/main/pages/ShellBar.html

+9
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@
158158
</ui5-list>
159159
</ui5-popover>
160160

161+
<ui5-popover id="custom-item-popover" hide-header placement-type="Bottom">
162+
<ui5-list separators="None">
163+
<ui5-li id="custom-item-1" type="Active">Custom Popover Item 1</ui5-li>
164+
<ui5-li type="Active">Custom Popover Item 2</ui5-li>
165+
</ui5-list>
166+
</ui5-popover>
167+
161168
<ui5-input id="press-input" style="margin-top: 2rem; width: 240px;">
162169

163170
</ui5-input>
@@ -190,7 +197,9 @@
190197

191198
["disc", "call"].forEach(function(id) {
192199
window[id].addEventListener("ui5-press", function(event) {
200+
event.preventDefault();
193201
window["press-input"].value = event.target.id;
202+
window["custom-item-popover"].openBy(event.detail.targetRef);
194203
});
195204
});
196205
</script>

0 commit comments

Comments
 (0)