Skip to content

fix: reset menu-bar-item attributes to initial state when returned to the menu bar - #5610

Merged
web-padawan merged 4 commits into
mainfrom
4692-menubar-item-content-is-clipped-on-resize
Feb 28, 2023
Merged

web-padawan merged 4 commits into
mainfrom
4692-menubar-item-content-is-clipped-on-resize

Conversation

@bwajtr

@bwajtr bwajtr commented Feb 27, 2023 •

Copy link
Copy Markdown
Contributor

Description

Note that even though the original issue says that the issue is reproducible only with flow, it's not so. It's purely a web-component problem and can be reproduced without flow by using the "component" property when defining menu items:

{
        text: 'Share',
        component: 'div',
        children: [{ text: 'Twitter' }, { text: 'Facebook' }],
      }

The reason why the menu items with submenus are clipped after the steps described in vaadin/flow-components#4692 is, that the given items show the "angle right" symbol to the right of them. Here I mangled with the paddings to reveal the "angle right" symbol:
image

The angle symbol is displayed because of the rule defined at vaadin-context-menu-item-styles.js:13

:host([aria-haspopup='true'])::after {
    font-family: lumo-icons;
    font-size: var(--lumo-icon-size-xs);
    content: var(--lumo-icons-angle-right);
    color: var(--lumo-tertiary-text-color);
  }

Why this happens

As mentioned above, when you define menu items with the "component" property, then the "component" is wrapped with vaadin-menu-bar-item before it's placed inside vaadin-menu-bar-button. Initially, this vaadin-menu-bar-item has the following attributes:

<vaadin-menu-bar-item aria-selected="false">Share</vaadin-menu-bar-item>

This item has only aria-selected attribute and the attributes do not change even when you click on it, hide it and reveal it by resizing the menu bar etc.
The problem is that when you do the steps described in vaadin/flow-components#4692, then the vaadin-menu-bar-item is reused and is moved to the context menu. When it's moved there, it gets bunch of additional attributes:

<vaadin-menu-bar-item aria-selected="false" aria-haspopup="true" aria-expanded="false" tabindex="-1">Share</vaadin-menu-bar-item>

... and these attributes are not removed when the item is moved back to the menu bar, under vaadin-menu-bar-button. One of the is aria-haspopup="true", which then causes the above CSS rule to kick in and the angle right is displayed.

Why it was not reproducible in Vaadin 23

In Vaadin 23, the menu bar's structure was different and composed of vaadin-context-menu-item. In Vaadin 24 it was replaced by vaadin-menu-bar-item and also the CSS rule for angle right specification was different. In Vaadin 23 the angle right was displayed only when .vaadin-menu-item CSS class was present on the menu item. This CSS class was added to the item when moved to the context menu and then removed from the item when it was moved back to the vaadin-menu-bar-button

Fixes vaadin/flow-components#4692

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/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.

…rned from "overflow" sub-menu back to the menu bar
…storing the button to rollback to the exact initial state of the item
@bwajtr
bwajtr requested review from vursen and web-padawan February 27, 2023 16:44
@bwajtr bwajtr changed the title 4692 menubar item content is clipped on resize fix: reset vaadin-menu-bar-item attributes to initial state when returned to the menu bar Feb 28, 2023
@bwajtr bwajtr changed the title fix: reset vaadin-menu-bar-item attributes to initial state when returned to the menu bar fix: reset menu-bar-item attributes to initial state when returned to the menu bar Feb 28, 2023

@web-padawan web-padawan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The actual fix looks good to me. Consider adding unit tests instead of snapshot tests though.

We mostly use snapshot tests to cover granular states e.g. disabled, readonly and such.
This definitely needs to be clarified in our development guide and onboarding materials.

As a rule of thumb, when fixing a bug, let's add a test that fails if you revert the code change.

@bwajtr
bwajtr marked this pull request as ready for review February 28, 2023 09:49
@bwajtr
bwajtr requested a review from web-padawan February 28, 2023 09:52

@web-padawan web-padawan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall LGTM, just a few small suggestions on improving tests.

Comment thread packages/menu-bar/test/menu-bar.test.js Resolved
Comment thread packages/menu-bar/test/menu-bar.test.js Resolved
Comment thread packages/menu-bar/test/menu-bar.test.js Resolved
Comment thread packages/menu-bar/test/menu-bar.test.js Resolved
@bwajtr
bwajtr requested a review from web-padawan February 28, 2023 11:54
@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 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@web-padawan web-padawan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks! 🥇

@web-padawan
web-padawan merged commit 1b29380 into main Feb 28, 2023
@web-padawan
web-padawan deleted the 4692-menubar-item-content-is-clipped-on-resize branch February 28, 2023 12:25
bwajtr added a commit that referenced this pull request Feb 28, 2023
…#5617)

Co-authored-by: Břetislav Wajtr <bretislav@vaadin.com>
bwajtr added a commit that referenced this pull request Feb 28, 2023
… (CP: 23.3) (#5618)


---------

Co-authored-by: Bretislav Wajtr <bretislav@vaadin.com>
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 item content is clipped on resize

4 participants