File tree Expand file tree Collapse file tree 4 files changed +14
-13
lines changed Expand file tree Collapse file tree 4 files changed +14
-13
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,11 @@ describe('AriaDescriber', () => {
107
107
expectMessages ( [ 'My Message' ] ) ;
108
108
expectMessage ( component . element1 , 'My Message' ) ;
109
109
} ) ;
110
+
111
+ it ( 'should not throw when attempting to describe a non-element node' , ( ) => {
112
+ const node : any = document . createComment ( 'Not an element node' ) ;
113
+ expect ( ( ) => ariaDescriber . describe ( node , 'This looks like an element' ) ) . not . toThrow ( ) ;
114
+ } ) ;
110
115
} ) ;
111
116
112
117
function getMessagesContainer ( ) {
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ export class AriaDescriber {
60
60
* message element.
61
61
*/
62
62
describe ( hostElement : Element , message : string ) {
63
- if ( ! message . trim ( ) ) {
63
+ if ( hostElement . nodeType !== this . _document . ELEMENT_NODE || ! message . trim ( ) ) {
64
64
return ;
65
65
}
66
66
@@ -75,7 +75,7 @@ export class AriaDescriber {
75
75
76
76
/** Removes the host element's aria-describedby reference to the message element. */
77
77
removeDescription ( hostElement : Element , message : string ) {
78
- if ( ! message . trim ( ) ) {
78
+ if ( hostElement . nodeType !== this . _document . ELEMENT_NODE || ! message . trim ( ) ) {
79
79
return ;
80
80
}
81
81
Original file line number Diff line number Diff line change @@ -21,12 +21,6 @@ import {take} from 'rxjs/operators/take';
21
21
import { InteractivityChecker } from './interactivity-checker' ;
22
22
import { DOCUMENT } from '@angular/common' ;
23
23
24
- /**
25
- * Node type of element nodes. Used instead of Node.ELEMENT_NODE
26
- * which is unsupported in Universal.
27
- * @docs -private
28
- */
29
- const ELEMENT_NODE_TYPE = 1 ;
30
24
31
25
/**
32
26
* Class that allows for trapping focus within a DOM element.
@@ -229,7 +223,7 @@ export class FocusTrap {
229
223
let children = root . children || root . childNodes ;
230
224
231
225
for ( let i = 0 ; i < children . length ; i ++ ) {
232
- let tabbableChild = children [ i ] . nodeType === ELEMENT_NODE_TYPE ?
226
+ let tabbableChild = children [ i ] . nodeType === this . _document . ELEMENT_NODE ?
233
227
this . _getFirstTabbableElement ( children [ i ] as HTMLElement ) :
234
228
null ;
235
229
@@ -251,7 +245,7 @@ export class FocusTrap {
251
245
let children = root . children || root . childNodes ;
252
246
253
247
for ( let i = children . length - 1 ; i >= 0 ; i -- ) {
254
- let tabbableChild = children [ i ] . nodeType === ELEMENT_NODE_TYPE ?
248
+ let tabbableChild = children [ i ] . nodeType === this . _document . ELEMENT_NODE ?
255
249
this . _getLastTabbableElement ( children [ i ] as HTMLElement ) :
256
250
null ;
257
251
Original file line number Diff line number Diff line change @@ -78,6 +78,8 @@ class SvgIconConfig {
78
78
*/
79
79
@Injectable ( )
80
80
export class MatIconRegistry {
81
+ private _document : Document ;
82
+
81
83
/**
82
84
* URLs and cached SVG elements for individual icons. Keys are of the format "[namespace]:[icon]".
83
85
*/
@@ -108,8 +110,9 @@ export class MatIconRegistry {
108
110
constructor (
109
111
@Optional ( ) private _httpClient : HttpClient ,
110
112
private _sanitizer : DomSanitizer ,
111
- @Optional ( ) @Inject ( DOCUMENT ) private _document ?: any ) {
113
+ @Optional ( ) @Inject ( DOCUMENT ) document ?: any ) {
112
114
// TODO(crisbeto): make _document required next major release.
115
+ this . _document = document ;
113
116
}
114
117
115
118
/**
@@ -438,8 +441,7 @@ export class MatIconRegistry {
438
441
let svg = this . _svgElementFromString ( '<svg></svg>' ) ;
439
442
440
443
for ( let i = 0 ; i < element . childNodes . length ; i ++ ) {
441
- // Note: 1 corresponds to `Node.ELEMENT_NODE` which we can't use in Universal.
442
- if ( element . childNodes [ i ] . nodeType === 1 ) {
444
+ if ( element . childNodes [ i ] . nodeType === this . _document . ELEMENT_NODE ) {
443
445
svg . appendChild ( element . childNodes [ i ] . cloneNode ( true ) ) ;
444
446
}
445
447
}
You can’t perform that action at this time.
0 commit comments