-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
feat(menu): add nested menu functionality #5493
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
942768b
feat(menu): add nested menu functionality
crisbeto 64c0830
refactor: address feedback
crisbeto ae2042f
chore: test failure on smaller screens
crisbeto 0701085
fix: close entire menu chain if menu item is clicked
crisbeto f98ee42
chore: make isSubmenu optional
crisbeto a8b7647
chore: also direction
crisbeto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,10 @@ | |
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Component, ElementRef, ChangeDetectionStrategy} from '@angular/core'; | ||
import {Component, ElementRef, OnDestroy, ChangeDetectionStrategy} from '@angular/core'; | ||
import {Focusable} from '../core/a11y/focus-key-manager'; | ||
import {CanDisable, mixinDisabled} from '../core/common-behaviors/disabled'; | ||
import {Subject} from 'rxjs/Subject'; | ||
|
||
// Boilerplate for applying mixins to MdMenuItem. | ||
/** @docs-private */ | ||
|
@@ -26,16 +27,23 @@ export const _MdMenuItemMixinBase = mixinDisabled(MdMenuItemBase); | |
host: { | ||
'role': 'menuitem', | ||
'class': 'mat-menu-item', | ||
'[class.mat-menu-item-highlighted]': '_highlighted', | ||
'[attr.tabindex]': '_getTabIndex()', | ||
'[attr.aria-disabled]': 'disabled.toString()', | ||
'[attr.disabled]': 'disabled || null', | ||
'(click)': '_checkDisabled($event)', | ||
'(mouseenter)': '_emitHoverEvent()', | ||
}, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
templateUrl: 'menu-item.html', | ||
exportAs: 'mdMenuItem', | ||
}) | ||
export class MdMenuItem extends _MdMenuItemMixinBase implements Focusable, CanDisable { | ||
export class MdMenuItem extends _MdMenuItemMixinBase implements Focusable, CanDisable, OnDestroy { | ||
/** Stream that emits when the menu item is hovered. */ | ||
hover: Subject<MdMenuItem> = new Subject(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this meant to be an internal api? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is mainly to facilitate the nested menu, but I can see it being useful in other cases as well. |
||
|
||
/** Whether the menu item is highlighted. */ | ||
_highlighted: boolean = false; | ||
|
||
constructor(private _elementRef: ElementRef) { | ||
super(); | ||
|
@@ -46,6 +54,10 @@ export class MdMenuItem extends _MdMenuItemMixinBase implements Focusable, CanDi | |
this._getHostElement().focus(); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.hover.complete(); | ||
} | ||
|
||
/** Used to set the `tabindex`. */ | ||
_getTabIndex(): string { | ||
return this.disabled ? '-1' : '0'; | ||
|
@@ -63,5 +75,13 @@ export class MdMenuItem extends _MdMenuItemMixinBase implements Focusable, CanDi | |
event.stopPropagation(); | ||
} | ||
} | ||
|
||
/** Emits to the hover stream. */ | ||
_emitHoverEvent() { | ||
if (!this.disabled) { | ||
this.hover.next(this); | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Make this a function to avoid the compiled getter boilerplate?