Skip to content
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

feat(ui5-shellbar): API improvements #421

Merged
merged 2 commits into from
May 22, 2019
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
30 changes: 28 additions & 2 deletions packages/main/src/ShellBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,20 @@ class ShellBar extends UI5Element {
this._isInitialRendering = true;
this._focussedItem = null;

// marks if preventDefault() is called in item's press handler
this._defaultItemPressPrevented = false;

const that = this;

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

popover.close();
if (!this._defaultItemPressPrevented) {
popover.close();
}

this._defaultItemPressPrevented = false;
},
};

Expand Down Expand Up @@ -480,6 +487,19 @@ class ShellBar extends UI5Element {
}
}

/**
* Closes the overflow area.
* Useful to manually close the overflow after having suppressed automatic closing with preventDefault() of ShellbarItem's press event
* @public
*/
closeOverflow() {
const popover = this.shadowRoot.querySelector(".sapWCShellBarOverflowPopover");

if (popover) {
popover.close();
}
}

_handleBarBreakpoints() {
const width = this.getBoundingClientRect().width;
const breakpoints = ShellBar.FIORI_3_BREAKPOINTS;
Expand Down Expand Up @@ -679,7 +699,13 @@ class ShellBar extends UI5Element {
this._itemNav.currentIndex = elementIndex;

if (refItemId) {
this.items.filter(item => item.shadowRoot.querySelector(`#${refItemId}`))[0].fireEvent("press");
const shellbarItem = this.items.filter(item => {
return item.shadowRoot.querySelector(`#${refItemId}`);
})[0];

const prevented = !shellbarItem.fireEvent("press", { targetRef: event.target }, true);

this._defaultItemPressPrevented = prevented;
}
}

Expand Down
7 changes: 6 additions & 1 deletion packages/main/src/ShellBarItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ const metadata = {
* Fired, when the item is pressed.
*
* @event
* @param {HTMLElement} targetRef dom ref of the clicked element
* @public
*/
press: {},
press: {
detail: {
targetRef: { type: HTMLElement },
},
},
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@
</ui5-list>
</ui5-popover>

<ui5-popover id="custom-item-popover" hide-header placement-type="Bottom">
<ui5-list separators="None">
<ui5-li id="custom-item-1" type="Active">Custom Popover Item 1</ui5-li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type="Active" is by default,

<ui5-li type="Active">Custom Popover Item 2</ui5-li>
</ui5-list>
</ui5-popover>

<ui5-input id="press-input" style="margin-top: 2rem; width: 240px;">

</ui5-input>
Expand Down Expand Up @@ -190,7 +197,9 @@

["disc", "call"].forEach(function(id) {
window[id].addEventListener("ui5-press", function(event) {
event.preventDefault();
window["press-input"].value = event.target.id;
window["custom-item-popover"].openBy(event.detail.targetRef);
});
});
</script>
Expand Down