Skip to content

Commit 980388d

Browse files
committed
minor fixes
1 parent ad9a601 commit 980388d

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/cdk/tree/nested-node.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export class CdkNestedTreeNode<T> extends CdkTreeNode<T> implements AfterContent
6363
super(_elementRef, _tree);
6464
// The classes are directly added here instead of in the host property because classes on
6565
// the host property are not inherited with View Engine.
66-
this._elementRef.nativeElement.classList.add('cdk-tree-node', 'cdk-nested-tree-node');
66+
this._elementRef.nativeElement.classList.add('cdk-tree-node');
67+
this._elementRef.nativeElement.classList.add('cdk-nested-tree-node');
6768
}
6869

6970
ngAfterContentInit() {

src/cdk/tree/tree.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
getTreeMultipleDefaultNodeDefsError,
4949
getTreeNoValidDataSourceError
5050
} from './tree-errors';
51+
import {coerceNumberProperty} from '@angular/cdk/coercion/number-property';
5152

5253
/**
5354
* CDK tree component that connects with a data source to retrieve data of type `T` and renders
@@ -357,7 +358,7 @@ export class CdkTreeNode<T> implements FocusableOption, OnDestroy, OnInit {
357358

358359
ngOnInit(): void {
359360
this._parentNodeAriaLevel = getParentNodeAriaLevel(this._elementRef.nativeElement);
360-
this._elementRef.nativeElement.setAttribute('aria-level', String(this.level + 1));
361+
this._elementRef.nativeElement.setAttribute('aria-level', `${this.level + 1}`);
361362
}
362363

363364
ngOnDestroy() {
@@ -398,14 +399,14 @@ function getParentNodeAriaLevel(nodeElement: HTMLElement): number {
398399
return -1;
399400
}
400401
} else if (parent.classList.contains('cdk-nested-tree-node')) {
401-
return Number(parent.getAttribute('aria-level')!);
402+
return coerceNumberProperty(parent.getAttribute('aria-level')!);
402403
} else {
403404
// The ancestor element is the cdk-tree itself
404405
return 0;
405406
}
406407
}
407408

408409
function isNodeElement(element: HTMLElement) {
409-
const classList = element?.classList;
410+
const classList = element.classList;
410411
return !(classList?.contains('cdk-nested-tree-node') || classList?.contains('cdk-tree'));
411412
}

src/material/tree/tree.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import {MatTreeNodeOutlet} from './outlet';
2828
// to be set in the host because:
2929
// if it is set as a @HostBinding it is not set by the time the tree nodes try to read the
3030
// class from it.
31-
// the ElementRef is not available in the constructor so the class can't be applied directly.
31+
// the ElementRef is not available in the constructor so the class can't be applied directly
32+
// without a breaking constructor change.
3233
'class': 'mat-tree cdk-tree',
3334
'role': 'tree',
3435
},

0 commit comments

Comments
 (0)