@@ -13,6 +13,7 @@ import {
1313 ElementRef ,
1414 OnDestroy ,
1515 ViewEncapsulation ,
16+ Inject ,
1617} from '@angular/core' ;
1718import {
1819 CanDisable ,
@@ -21,6 +22,7 @@ import {
2122 mixinDisableRipple
2223} from '@angular/material/core' ;
2324import { Subject } from 'rxjs/Subject' ;
25+ import { DOCUMENT } from '@angular/common' ;
2426
2527// Boilerplate for applying mixins to MatMenuItem.
2628/** @docs -private */
@@ -55,6 +57,8 @@ export const _MatMenuItemMixinBase = mixinDisableRipple(mixinDisabled(MatMenuIte
5557export class MatMenuItem extends _MatMenuItemMixinBase
5658 implements FocusableOption , CanDisable , CanDisableRipple , OnDestroy {
5759
60+ private _document : Document ;
61+
5862 /** Stream that emits when the menu item is hovered. */
5963 _hovered : Subject < MatMenuItem > = new Subject ( ) ;
6064
@@ -64,8 +68,11 @@ export class MatMenuItem extends _MatMenuItemMixinBase
6468 /** Whether the menu item acts as a trigger for a sub-menu. */
6569 _triggersSubmenu : boolean = false ;
6670
67- constructor ( private _elementRef : ElementRef ) {
71+ constructor ( private _elementRef : ElementRef , @ Inject ( DOCUMENT ) document ?: any ) {
6872 super ( ) ;
73+
74+ // TODO: make the document a required param when doing breaking changes.
75+ this . _document = document ;
6976 }
7077
7178 /** Focuses the menu item. */
@@ -105,6 +112,7 @@ export class MatMenuItem extends _MatMenuItemMixinBase
105112 /** Gets the label to be used when determining whether the option should be focused. */
106113 getLabel ( ) : string {
107114 const element : HTMLElement = this . _elementRef . nativeElement ;
115+ const textNodeType = this . _document ? this . _document . TEXT_NODE : 3 ;
108116 let output = '' ;
109117
110118 if ( element . childNodes ) {
@@ -114,7 +122,7 @@ export class MatMenuItem extends _MatMenuItemMixinBase
114122 // We skip anything that's not a text node to prevent the text from
115123 // being thrown off by something like an icon.
116124 for ( let i = 0 ; i < length ; i ++ ) {
117- if ( element . childNodes [ i ] . nodeType === Node . TEXT_NODE ) {
125+ if ( element . childNodes [ i ] . nodeType === textNodeType ) {
118126 output += element . childNodes [ i ] . textContent ;
119127 }
120128 }
0 commit comments