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

fix(ui5-shellbar): fix menuItems cloning #1457

Merged
merged 4 commits into from
Apr 9, 2020
Merged

fix(ui5-shellbar): fix menuItems cloning #1457

merged 4 commits into from
Apr 9, 2020

Conversation

ilhan007
Copy link
Member

@ilhan007 ilhan007 commented Apr 9, 2020

We used to just copy the text of the menuItems within the Light DOM of the ui5-shellbar, and not only the attributes of those items are missing, but also we don't update the internal items whenever the original ones change. For example: if the textContent change - it is not applied to the internal one. Adding a mutation observer keeps everything in sync. Currently we can not just forward the outside slot to the List, that is inside a Popover, that is in the static area.

Fixes: #1442

Copy link
Contributor

@vladitasev vladitasev left a comment

Choose a reason for hiding this comment

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

I think it's much better. The only thing that will not work will be if the developer compares the event target of the menu item click event with references of the original items. I don't know if this is a realistic use case, but we can always do this later. This will not invalidate any of the code, proposed with this change, as we always need the ovserver. Good job!

}
this._updateClonedMenuItems();
this.updateStaticAreaItemContentDensity();
this.menuPopover.openBy(this.shadowRoot.querySelector(".ui5-shellbar-menu-button"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it intended that this line is outside of the if? So we always open the popup even though it's empty?

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, this is by mistake when I extracted the code to _updateClonedMenuItems

@@ -641,6 +642,7 @@ class ShellBar extends UI5Element {
}

onExitDOM() {
this.menuItemsObserver.disconnect();
Copy link
Contributor

Choose a reason for hiding this comment

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

If you disconnect it here (f.e. the dev called removeChild(shellbar), are we sure _observeMenuItems() will be called again again upon re-inserting into the DOM? I would guess so, but just to make sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should work, I read this in the DOCS:
disconnect() stops the MutationObserver instance from receiving further notifications until and unless observe() is called again

@@ -819,6 +821,34 @@ class ShellBar extends UI5Element {
}
}

_updateClonedMenuItems() {
if (!this.menuItems.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If there are no more items, shouldn't we let it delete all clones too (so the next line should always run)?

Copy link
Member Author

@ilhan007 ilhan007 Apr 9, 2020

Choose a reason for hiding this comment

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

yes, I should just remove the return I think, then the array with clones will be empty and the forEach just wont run.

Copy link
Collaborator

@MarcusNotheis MarcusNotheis left a comment

Choose a reason for hiding this comment

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

Works as expected.

@ilhan007 ilhan007 merged commit f4d2547 into master Apr 9, 2020
@ilhan007 ilhan007 deleted the fix-shellbar branch April 9, 2020 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ui5-shellbar: menuItems don't accept data attributes
3 participants