@@ -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 < MatMenuItem > ( ) ;
6064
@@ -66,8 +70,10 @@ export class MatMenuItem extends _MatMenuItemMixinBase
6670
6771 constructor (
6872 private _elementRef : ElementRef ,
69- // TODO(crisbeto): switch to a required param when doing breaking changes.
73+ @ Inject ( DOCUMENT ) document ?: any ,
7074 private _focusMonitor ?: FocusMonitor ) {
75+
76+ // @deletion -target 6.0.0 make `_focusMonitor` and `document` required params.
7177 super ( ) ;
7278
7379 if ( _focusMonitor ) {
@@ -76,6 +82,8 @@ export class MatMenuItem extends _MatMenuItemMixinBase
7682 // mouse or touch interaction.
7783 _focusMonitor . monitor ( this . _getHostElement ( ) , false ) ;
7884 }
85+
86+ this . _document = document ;
7987 }
8088
8189 /** Focuses the menu item. */
@@ -123,6 +131,7 @@ export class MatMenuItem extends _MatMenuItemMixinBase
123131 /** Gets the label to be used when determining whether the option should be focused. */
124132 getLabel ( ) : string {
125133 const element : HTMLElement = this . _elementRef . nativeElement ;
134+ const textNodeType = this . _document ? this . _document . TEXT_NODE : 3 ;
126135 let output = '' ;
127136
128137 if ( element . childNodes ) {
@@ -132,7 +141,7 @@ export class MatMenuItem extends _MatMenuItemMixinBase
132141 // We skip anything that's not a text node to prevent the text from
133142 // being thrown off by something like an icon.
134143 for ( let i = 0 ; i < length ; i ++ ) {
135- if ( element . childNodes [ i ] . nodeType === Node . TEXT_NODE ) {
144+ if ( element . childNodes [ i ] . nodeType === textNodeType ) {
136145 output += element . childNodes [ i ] . textContent ;
137146 }
138147 }
0 commit comments