-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(menu): unable to open same sub-menu from different triggers and not picking up indirect descendant items #10132
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(menu): unable to open same sub-menu from different triggers and not picking up indirect descendant items #10132
Conversation
a18d631
to
a7a2ae6
Compare
if (newIndex > -1 && newIndex !== this._activeItemIndex) { | ||
this._activeItemIndex = newIndex; | ||
constructor(private _items: QueryList<T> | T[]) { | ||
if (_items instanceof QueryList) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment that explains why items can be either a QueryList
or an array?
* Registers a menu item with the menu. | ||
* @docs-private | ||
*/ | ||
addItem(item: MatMenuItem) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does needing to call these methods constitute a breaking change for people implementing their own menu panel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. We never required the items
(the QueryList
we used before to collected the items) as a part of the MatMenuPanel
and we didn't support custom menu panels for nested menus either.
@@ -294,6 +300,30 @@ export class MatMenu implements OnInit, AfterContentInit, MatMenuPanel, OnDestro | |||
} | |||
} | |||
|
|||
/** | |||
* Registers a menu item with the menu. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expand to talk about why this registration is necessary?
src/lib/menu/menu-trigger.ts
Outdated
@@ -140,6 +143,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy { | |||
@Optional() @Self() private _menuItemInstance: MatMenuItem, | |||
@Optional() private _dir: Directionality, | |||
// TODO(crisbeto): make the _focusMonitor required when doing breaking changes. | |||
// @deletion-target 6.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is deletion target the right tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what we've been using in other places to mark that a parameter should become required. deletion-target
might not be the best naming for it though.
src/lib/menu/menu-trigger.ts
Outdated
// Since we might have multiple competing triggers for the same menu (e.g. a sub-menu | ||
// with different data and triggers), we have to delay it by a tick to ensure that | ||
// it won't be closed immediately after it is opened. | ||
.pipe(filter(active => active === this._menuItemInstance), delay(0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this delay trigger multiple change detections if you quickly hover over multiple menu items?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're triggering change detections anyway, because we have a mouseenter
listener on each menu item.
a7a2ae6
to
8643ddd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed the feedback @jelbourn.
* Registers a menu item with the menu. | ||
* @docs-private | ||
*/ | ||
addItem(item: MatMenuItem) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. We never required the items
(the QueryList
we used before to collected the items) as a part of the MatMenuPanel
and we didn't support custom menu panels for nested menus either.
src/lib/menu/menu-trigger.ts
Outdated
@@ -140,6 +143,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy { | |||
@Optional() @Self() private _menuItemInstance: MatMenuItem, | |||
@Optional() private _dir: Directionality, | |||
// TODO(crisbeto): make the _focusMonitor required when doing breaking changes. | |||
// @deletion-target 6.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what we've been using in other places to mark that a parameter should become required. deletion-target
might not be the best naming for it though.
src/lib/menu/menu-trigger.ts
Outdated
// Since we might have multiple competing triggers for the same menu (e.g. a sub-menu | ||
// with different data and triggers), we have to delay it by a tick to ensure that | ||
// it won't be closed immediately after it is opened. | ||
.pipe(filter(active => active === this._menuItemInstance), delay(0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're triggering change detections anyway, because we have a mouseenter
listener on each menu item.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Just needs rebase |
b0b7139
to
d798784
Compare
d798784
to
c2a6a5d
Compare
c2a6a5d
to
dd5c23c
Compare
3f40dbc
to
087ac4d
Compare
087ac4d
to
0df86e8
Compare
0df86e8
to
9b32c13
Compare
9b32c13
to
2c33108
Compare
642bd06
to
e71f2de
Compare
@crisbeto Looks like this has a couple lint errors. |
…ot picking up indirect descendant items * Reworks the relationship between the menu items and the menu panel to allow for the items to be indirect descendants of the menu, while also allowing for `mat-menu` instances to be declared inside of other `mat-menu` instances without having the root `mat-menu` pick up all of the descendant items. * Adds the ability to pass in an array to the `ListKeyManager`, in addition to a `QueryList`. * Fixes not being able to re-use the same sub-menu between multiple sub-menu triggers. Fixes angular#9969. Fixes angular#9987.
e71f2de
to
9657ebe
Compare
Fixed @josephperrott. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
mat-menu
instances to be declared inside of othermat-menu
instances without having the rootmat-menu
pick up all of the descendant items.ListKeyManager
, in addition to aQueryList
.Fixes #9969.
Fixes #9987.