Skip to content

Commit 4ff7dcb

Browse files
committed
fix(cdk/tree): tests
1 parent dad96b3 commit 4ff7dcb

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

src/cdk/a11y/key-manager/tree-key-manager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@ export class TreeKeyManager<T extends TreeKeyManagerItem> implements TreeKeyMana
298298
if (newIndex > -1 && newIndex !== this._activeItemIndex) {
299299
this._activeItemIndex = newIndex;
300300
this._typeahead?.setCurrentSelectedItemIndex(newIndex);
301+
} else if (newIndex === -1) {
302+
// if there's no new matching element, then we reset the state of this
303+
// key manager
304+
this._activeItem = null;
305+
this._activeItemIndex = -1;
306+
this._hasInitialFocused = false;
301307
}
302308
}
303309

src/cdk/tree/tree.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,7 @@ describe('CdkTree', () => {
12251225
fixture.destroy();
12261226

12271227
fixture = TestBed.createComponent(StaticNestedCdkTreeApp);
1228+
fixture.detectChanges();
12281229

12291230
component = fixture.componentInstance;
12301231
dataSource = component.dataSource as FakeDataSource;
@@ -1251,7 +1252,6 @@ describe('CdkTree', () => {
12511252
it('the tree does not have a tabindex when an element is active', () => {
12521253
// activate the second child by clicking on it
12531254
nodes[1].click();
1254-
fixture.detectChanges();
12551255

12561256
expect(treeElement.hasAttribute('tabindex')).toBeFalse();
12571257
});

src/cdk/tree/tree.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -624,15 +624,7 @@ export class CdkTree<T, K = T>
624624
}
625625
});
626626

627-
// Note: we only `detectChanges` from a top-level call, otherwise we risk overflowing
628-
// the call stack since this method is called recursively (see #29733.)
629-
// TODO: change to `this._changeDetectorRef.markForCheck()`,
630-
// or just switch this component to use signals.
631-
if (parentData) {
632-
this._changeDetectorRef.markForCheck();
633-
} else {
634-
this._changeDetectorRef.detectChanges();
635-
}
627+
this._changeDetectorRef.markForCheck();
636628
}
637629

638630
/**
@@ -1461,7 +1453,6 @@ export class CdkTreeNode<T, K = T> implements OnDestroy, OnInit, TreeKeyManagerI
14611453
/** Focuses this data node. Implemented for TreeKeyManagerItem. */
14621454
focus(): void {
14631455
this._tabindex.set(0);
1464-
this._changeDetectorRef.detectChanges();
14651456
if (this._shouldFocus) {
14661457
this._elementRef.nativeElement.focus();
14671458
}
@@ -1470,7 +1461,6 @@ export class CdkTreeNode<T, K = T> implements OnDestroy, OnInit, TreeKeyManagerI
14701461
/** Defocus this data node. */
14711462
unfocus(): void {
14721463
this._tabindex.set(-1);
1473-
this._changeDetectorRef.detectChanges();
14741464
}
14751465

14761466
/** Emits an activation event. Implemented for TreeKeyManagerItem. */
@@ -1498,7 +1488,6 @@ export class CdkTreeNode<T, K = T> implements OnDestroy, OnInit, TreeKeyManagerI
14981488
/** Makes the node focusable. Implemented for TreeKeyManagerItem. */
14991489
makeFocusable(): void {
15001490
this._tabindex.set(0);
1501-
this._changeDetectorRef.detectChanges();
15021491
}
15031492

15041493
_focusItem() {

0 commit comments

Comments
 (0)