@@ -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 ( ) ;
60
64
@@ -64,8 +68,11 @@ export class MatMenuItem extends _MatMenuItemMixinBase
64
68
/** Whether the menu item acts as a trigger for a sub-menu. */
65
69
_triggersSubmenu : boolean = false ;
66
70
67
- constructor ( private _elementRef : ElementRef ) {
71
+ constructor ( private _elementRef : ElementRef , @ Inject ( DOCUMENT ) document ?: any ) {
68
72
super ( ) ;
73
+
74
+ // TODO: make the document a required param when doing breaking changes.
75
+ this . _document = document ;
69
76
}
70
77
71
78
/** Focuses the menu item. */
@@ -105,6 +112,7 @@ export class MatMenuItem extends _MatMenuItemMixinBase
105
112
/** Gets the label to be used when determining whether the option should be focused. */
106
113
getLabel ( ) : string {
107
114
const element : HTMLElement = this . _elementRef . nativeElement ;
115
+ const textNodeType = this . _document ? this . _document . TEXT_NODE : 3 ;
108
116
let output = '' ;
109
117
110
118
if ( element . childNodes ) {
@@ -114,7 +122,7 @@ export class MatMenuItem extends _MatMenuItemMixinBase
114
122
// We skip anything that's not a text node to prevent the text from
115
123
// being thrown off by something like an icon.
116
124
for ( let i = 0 ; i < length ; i ++ ) {
117
- if ( element . childNodes [ i ] . nodeType === Node . TEXT_NODE ) {
125
+ if ( element . childNodes [ i ] . nodeType === textNodeType ) {
118
126
output += element . childNodes [ i ] . textContent ;
119
127
}
120
128
}
0 commit comments