Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Conversation

@oliversalzburg
Copy link
Contributor

@oliversalzburg oliversalzburg commented Jan 21, 2020

When an mdMenuBar contains a menu and that menu is opened, the menu bar will receives a CSS class that ultimately affects its z-order. When the menu is closed, the CSS class is supposed to be removed from the menu bar.

When the menu has multiple levels, the menu hierarchy can not be correctly resolved upon menu closure. This results in the CSS class not being removed from the menu bar.

I assumed that this failure is mostly due to the attempt to detect menu structure through DOM traversal, which will not work in this case as the menu hierarchy is not directly reflected in the DOM structure (menus are attached to the body instead).

Fixes #11235

PR Checklist

Please check that your PR fulfills the following requirements:

  • The commit message follows our guidelines
  • Tests for the changes have been added or this is not a bug fix / enhancement
  • Docs have been added, updated, or were not required

PR Type

What kind of change does this PR introduce?

[X] Bugfix
[ ] Enhancement
[ ] Documentation content changes
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Infrastructure changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #11235

What is the new behavior?

I store a reference to the original menu bar controller to establish the hierarchy when handling the menu closure. This way the CSS class is properly removed from the menu bar and Z order is restored.

Does this PR introduce a breaking change?

[ ] Yes
[X] No

@googlebot googlebot added the cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ label Jan 21, 2020
@Splaktar Splaktar self-assigned this Jan 21, 2020
@Splaktar Splaktar added this to the 1.1.22 milestone Jan 21, 2020
@Splaktar Splaktar added g3: sync P3: important Important issues that really should be fixed when possible. type: bug ui: CSS labels Jan 21, 2020
Copy link
Contributor

@Splaktar Splaktar left a comment

Choose a reason for hiding this comment

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

Thanks for this PR. I'm happy with the approach, but it would be great to get 1-2 basic tests written to verify this.

Oh and in the commit message and PR title, did you mean z-index?

@Splaktar Splaktar added the needs: unit tests This PR needs unit tests to cover the changes being proposed label Jan 21, 2020
@oliversalzburg
Copy link
Contributor Author

Thanks for the quick review! I'll get back to it later tonight.

Copy link
Contributor Author

@oliversalzburg oliversalzburg left a comment

Choose a reason for hiding this comment

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

I did mean z-index, but I thought I had to upper-case it. I will fix it in the next change.

I will look into the unit tests.

@oliversalzburg
Copy link
Contributor Author

I can't get ChromeHeadless to work in the DevContainer I'm using. I can't properly write the tests like this. I might try a couple of pushes and see what I get out of CircleCI, but I might have to temporarily downgrade some machine to Node 10 to finish this later.

@oliversalzburg oliversalzburg changed the title fix(menubar): Z-order not restored on menu close fix(menubar): z-order not restored on menu close Jan 21, 2020
@oliversalzburg
Copy link
Contributor Author

Alright, those were though to write, but I think I got something acceptable.

In the should close when clicking on a nested menu item test, I also wanted to spy on the close() of the nested menu controller, but I have no idea how to retrieve it. I opted to skip that check. If you feel like it should be added, please help me out with that controller reference.

In general, I didn't add tests specifically for the existence of the class, but focused on the general closing behavior that was already under test by existing tests. These tests included assertions for the removal of the md-has-open-menu class. So it seemed to make most sense to just extend this area of the test suite to cover more deeply nested menus.

@oliversalzburg oliversalzburg changed the title fix(menubar): z-order not restored on menu close fix(menubar): z-index not restored on menu close Jan 21, 2020
@Splaktar
Copy link
Contributor

I might have to temporarily downgrade some machine to Node 10 to finish this later.

I'm not sure if you're on Windows or not, but NVM is one of a few options for quickly switching your NodeJS installation. The most mature one is macOS, but there is a separate version for Windows as well (plus another option or two).

@oliversalzburg
Copy link
Contributor Author

Yeah, I worked with nvm/nvs/... in the past (and I'm on Windows using bash). It always ended up causing more problems than it solved.

I opted to create a quick Hyper-V Windows Development VM. Worked well enough. Thanks for the suggestion though :)

@Splaktar Splaktar removed the needs: unit tests This PR needs unit tests to cover the changes being proposed label Jan 22, 2020
Copy link
Contributor

@Splaktar Splaktar left a comment

Choose a reason for hiding this comment

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

LGTM

@Splaktar Splaktar added pr: lgtm This PR has been approved by the reviewer pr: merge ready This PR is ready for a caretaker to review labels Jan 22, 2020
@Splaktar Splaktar changed the title fix(menubar): z-index not restored on menu close fix(menu-bar): z-index not restored on menu close Jan 22, 2020
@oliversalzburg
Copy link
Contributor Author

Should I rewrite the commit message to use fix(menu-bar): as well?

@Splaktar
Copy link
Contributor

That would be helpful, thank you.

When an mdMenuBar contains a menu and that menu is opened, the menu bar will receives a CSS class that ultimately affects its z-index. When the menu is closed, the CSS class is supposed to be removed from the menu bar.

When the menu has multiple levels, the menu hierarchy can not be correctly resolved upon menu closure. This results in the CSS class not being removed from the menu bar.

I assumed that this failure is mostly due to the attempt to detect menu structure through DOM traversal, which will not work in this case as the menu hierarchy is not directly reflected in the DOM structure (menus are attached to the body instead).

Fixes #11235
@Splaktar Splaktar requested a review from jelbourn March 4, 2020 19:30
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@Splaktar Splaktar merged commit 4a4dde4 into angular:master Mar 6, 2020
@oliversalzburg oliversalzburg deleted the fix/menu-bar-z-order-on-menu-close branch March 6, 2020 13:43
@oliversalzburg oliversalzburg restored the fix/menu-bar-z-order-on-menu-close branch July 13, 2020 09:37
@oliversalzburg oliversalzburg deleted the fix/menu-bar-z-order-on-menu-close branch July 13, 2020 09:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ P3: important Important issues that really should be fixed when possible. pr: lgtm This PR has been approved by the reviewer pr: merge ready This PR is ready for a caretaker to review type: bug ui: CSS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

menuBar: failure to remove md-has-open-menu selector

4 participants