Skip to content

Commit 004d5b6

Browse files
committed
set aria-level in ngOnInit, clean up
1 parent 23884ee commit 004d5b6

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

src/cdk/tree/tree.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ describe('CdkTree', () => {
596596
[`topping_3 - cheese_3 + base_3`]);
597597
});
598598

599-
fit('with correct aria-level', () => {
599+
it('with correct aria-level', () => {
600600
expect(getNodes(treeElement).every(node => {
601601
return node.getAttribute('aria-level') === '1';
602602
})).toBe(true);

src/cdk/tree/tree.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {FocusableOption} from '@angular/cdk/a11y';
99
import {CollectionViewer, DataSource, isDataSource} from '@angular/cdk/collections';
1010
import {
1111
AfterContentChecked,
12-
AfterViewInit,
1312
ChangeDetectionStrategy,
1413
ChangeDetectorRef,
1514
Component,
@@ -291,7 +290,7 @@ export class CdkTree<T> implements AfterContentChecked, CollectionViewer, OnDest
291290
}
292291
}
293292

294-
let uuid = 0;
293+
295294
/**
296295
* Tree node for CdkTree. It contains the data in the tree node.
297296
*/
@@ -304,7 +303,7 @@ let uuid = 0;
304303
'class': 'cdk-tree-node',
305304
},
306305
})
307-
export class CdkTreeNode<T> implements FocusableOption, OnDestroy, AfterViewInit {
306+
export class CdkTreeNode<T> implements FocusableOption, OnDestroy, OnInit {
308307
unique: number;
309308
/**
310309
* The most recently created `CdkTreeNode`. We save it in static variable so we can retrieve it
@@ -351,18 +350,14 @@ export class CdkTreeNode<T> implements FocusableOption, OnDestroy, AfterViewInit
351350
constructor(protected _elementRef: ElementRef<HTMLElement>,
352351
protected _tree: CdkTree<T>) {
353352
CdkTreeNode.mostRecentTreeNode = this as CdkTreeNode<T>;
354-
this.unique = uuid++;
355-
console.error(`constructor: node ${this.unique}`)
356353
}
357354

358-
ngAfterViewInit(): void {
355+
ngOnInit(): void {
359356
this._parentNodeAriaLevel = this._getParentNodeAriaLevel();
360-
console.error(`ngAfterViewInit: node ${this.unique} set aria-level to ${this.level + 1}`)
361357
this._elementRef.nativeElement.setAttribute('aria-level', String(this.level + 1));
362358
}
363359

364360
ngOnDestroy() {
365-
console.error(`ngOnDestroy: node ${this.unique}`)
366361
// If this is the last tree node being destroyed,
367362
// clear out the reference to avoid leaking memory.
368363
if (CdkTreeNode.mostRecentTreeNode === this) {

src/material/tree/node.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ export class MatNestedTreeNode<T> extends CdkNestedTreeNode<T> implements AfterC
126126
// This is a workaround for https://github.com/angular/angular/issues/23091
127127
// In aot mode, the lifecycle hooks from parent class are not called.
128128
// TODO(tinayuangao): Remove when the angular issue #23091 is fixed
129-
// ngAfterContentInit() {
130-
// super.ngAfterContentInit();
131-
// }
132-
//
133-
// ngOnDestroy() {
134-
// super.ngOnDestroy();
135-
// }
129+
ngAfterContentInit() {
130+
super.ngAfterContentInit();
131+
}
132+
133+
ngOnDestroy() {
134+
super.ngOnDestroy();
135+
}
136136

137137
static ngAcceptInputType_disabled: BooleanInput;
138138
}

src/material/tree/tree.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,11 @@ describe('MatTree', () => {
350350
[`topping_3 - cheese_3 + base_3`]);
351351
});
352352

353-
fit('with correct aria-level', () => {
353+
it('with correct aria-level', () => {
354354
expect(getNodes(treeElement).every(node => {
355355
return node.getAttribute('aria-level') === '1';
356356
})).toBe(true);
357357

358-
debugger;
359358
let data = underlyingDataSource.data;
360359
const child = underlyingDataSource.addChild(data[1]);
361360
underlyingDataSource.addChild(child);

0 commit comments

Comments
 (0)