Skip to content

fix: re-generate items on the hidden or disabled property change - #3027

Merged
vursen merged 5 commits into
masterfrom
fix/menu-bar/disabled-and-hidden-properties
Apr 19, 2022
Merged

vursen merged 5 commits into
masterfrom
fix/menu-bar/disabled-and-hidden-properties

Conversation

@vursen

@vursen vursen commented Apr 15, 2022 •

Copy link
Copy Markdown
Contributor

Description

This PR adds a MutationObserver to the menu bar connector that watches for the hidden and disabled attributes and triggers re-generating the menu bar items if an attribute change occurs.

It solves the issue where changing the visibility or disabled state of a menu item wouldn't be applied if an ancestor of the menu bar was hidden at the same time.

Fixes #2134

Depends on #3025

Type of change

  • Bugfix

Checklist

  • I have read the contribution guide: https://vaadin.com/docs-beta/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

@vursen
vursen force-pushed the fix/menu-bar/disabled-and-hidden-properties branch from ff195ad to 8543589 Compare April 15, 2022 12:57
@vursen vursen changed the title fix: re-generate items on hidden or disabled property change fix: re-generate items on the hidden or disabled property change Apr 15, 2022
}

const observer = new MutationObserver((records) => {
const hasChangedAttributes = records.some((entry) => {

@vursen vursen Apr 18, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

note: I had to add this check because the context-menu has a logic where it ensures the disabled attribute, and if it is already present on the item element, it ends up re-assigned which triggers the Mutation Observer here (reference)

@vursen

vursen commented Apr 18, 2022 •

Copy link
Copy Markdown
Contributor Author

Fixing the current issue also revealed another one that I don't have a good workaround for: if you add a new menu item while an ancestor of the menu bar is hidden, the new item won't be properly attached to the DOM. In order to make it work, you will need to cause the menu bar to re-render manually after the ancestor becomes visible.

There is no reliable way to pick up on that in the connector as well as no Flow API that would allow detecting the visibility change of an ancestor of a component. As long as there is no API, we cannot fix that issue, so I would go with creating a ticket but not considering it in the scope of the current PR.

@vursen
vursen marked this pull request as ready for review April 19, 2022 06:44
@vursen
vursen requested a review from sissbruecker April 19, 2022 06:44
Base automatically changed from refactor/context-menu/connector to master April 19, 2022 13:25
@vursen
vursen force-pushed the fix/menu-bar/disabled-and-hidden-properties branch from f57d419 to ec4e173 Compare April 19, 2022 13:56
@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 11 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@vursen
vursen merged commit dd24bd6 into master Apr 19, 2022
@vursen
vursen deleted the fix/menu-bar/disabled-and-hidden-properties branch April 19, 2022 14:17
vursen added a commit that referenced this pull request Apr 20, 2022
…) (#3032)

Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 23.1.0.alpha3 and is also targeting the upcoming stable 23.1.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MenuBar - MenuItem enabled state change does not apply properly when not visible

3 participants