@@ -13,6 +13,7 @@ import {
13
13
ElementRef ,
14
14
OnDestroy ,
15
15
ViewEncapsulation ,
16
+ Inject ,
16
17
} from '@angular/core' ;
17
18
import {
18
19
CanDisable ,
@@ -21,6 +22,7 @@ import {
21
22
mixinDisableRipple
22
23
} from '@angular/material/core' ;
23
24
import { Subject } from 'rxjs/Subject' ;
25
+ import { DOCUMENT } from '@angular/common' ;
24
26
25
27
// Boilerplate for applying mixins to MatMenuItem.
26
28
/** @docs -private */
@@ -55,6 +57,8 @@ export const _MatMenuItemMixinBase = mixinDisableRipple(mixinDisabled(MatMenuIte
55
57
export class MatMenuItem extends _MatMenuItemMixinBase
56
58
implements FocusableOption , CanDisable , CanDisableRipple , OnDestroy {
57
59
60
+ private _document : Document ;
61
+
58
62
/** Stream that emits when the menu item is hovered. */
59
63
_hovered : Subject < MatMenuItem > = new Subject < MatMenuItem > ( ) ;
60
64
@@ -66,8 +70,10 @@ export class MatMenuItem extends _MatMenuItemMixinBase
66
70
67
71
constructor (
68
72
private _elementRef : ElementRef ,
69
- // TODO(crisbeto): switch to a required param when doing breaking changes.
73
+ @ Inject ( DOCUMENT ) document ?: any ,
70
74
private _focusMonitor ?: FocusMonitor ) {
75
+
76
+ // @deletion -target 6.0.0 make `_focusMonitor` and `document` required params.
71
77
super ( ) ;
72
78
73
79
if ( _focusMonitor ) {
@@ -76,6 +82,8 @@ export class MatMenuItem extends _MatMenuItemMixinBase
76
82
// mouse or touch interaction.
77
83
_focusMonitor . monitor ( this . _getHostElement ( ) , false ) ;
78
84
}
85
+
86
+ this . _document = document ;
79
87
}
80
88
81
89
/** Focuses the menu item. */
@@ -123,6 +131,7 @@ export class MatMenuItem extends _MatMenuItemMixinBase
123
131
/** Gets the label to be used when determining whether the option should be focused. */
124
132
getLabel ( ) : string {
125
133
const element : HTMLElement = this . _elementRef . nativeElement ;
134
+ const textNodeType = this . _document ? this . _document . TEXT_NODE : 3 ;
126
135
let output = '' ;
127
136
128
137
if ( element . childNodes ) {
@@ -132,7 +141,7 @@ export class MatMenuItem extends _MatMenuItemMixinBase
132
141
// We skip anything that's not a text node to prevent the text from
133
142
// being thrown off by something like an icon.
134
143
for ( let i = 0 ; i < length ; i ++ ) {
135
- if ( element . childNodes [ i ] . nodeType === Node . TEXT_NODE ) {
144
+ if ( element . childNodes [ i ] . nodeType === textNodeType ) {
136
145
output += element . childNodes [ i ] . textContent ;
137
146
}
138
147
}
0 commit comments