Skip to content

Commit 68b29d9

Browse files
committed
fix(cdk/tree): tests
1 parent 7358786 commit 68b29d9

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
@@ -1247,6 +1247,7 @@ describe('CdkTree', () => {
12471247
fixture.destroy();
12481248

12491249
fixture = TestBed.createComponent(StaticNestedCdkTreeApp);
1250+
fixture.detectChanges();
12501251

12511252
component = fixture.componentInstance;
12521253
dataSource = component.dataSource as FakeDataSource;
@@ -1273,7 +1274,6 @@ describe('CdkTree', () => {
12731274
it('the tree does not have a tabindex when an element is active', () => {
12741275
// activate the second child by clicking on it
12751276
nodes[1].click();
1276-
fixture.detectChanges();
12771277

12781278
expect(treeElement.hasAttribute('tabindex')).toBeFalse();
12791279
});

src/cdk/tree/tree.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -633,15 +633,7 @@ export class CdkTree<T, K = T>
633633
}
634634
});
635635

636-
// Note: we only `detectChanges` from a top-level call, otherwise we risk overflowing
637-
// the call stack since this method is called recursively (see #29733.)
638-
// TODO: change to `this._changeDetectorRef.markForCheck()`,
639-
// or just switch this component to use signals.
640-
if (parentData) {
641-
this._changeDetectorRef.markForCheck();
642-
} else {
643-
this._changeDetectorRef.detectChanges();
644-
}
636+
this._changeDetectorRef.markForCheck();
645637
}
646638

647639
/**
@@ -1480,7 +1472,6 @@ export class CdkTreeNode<T, K = T> implements OnDestroy, OnInit, TreeKeyManagerI
14801472
/** Focuses this data node. Implemented for TreeKeyManagerItem. */
14811473
focus(): void {
14821474
this._tabindex.set(0);
1483-
this._changeDetectorRef.detectChanges();
14841475
if (this._shouldFocus) {
14851476
this._elementRef.nativeElement.focus();
14861477
}
@@ -1489,7 +1480,6 @@ export class CdkTreeNode<T, K = T> implements OnDestroy, OnInit, TreeKeyManagerI
14891480
/** Defocus this data node. */
14901481
unfocus(): void {
14911482
this._tabindex.set(-1);
1492-
this._changeDetectorRef.detectChanges();
14931483
}
14941484

14951485
/** Emits an activation event. Implemented for TreeKeyManagerItem. */
@@ -1517,7 +1507,6 @@ export class CdkTreeNode<T, K = T> implements OnDestroy, OnInit, TreeKeyManagerI
15171507
/** Makes the node focusable. Implemented for TreeKeyManagerItem. */
15181508
makeFocusable(): void {
15191509
this._tabindex.set(0);
1520-
this._changeDetectorRef.detectChanges();
15211510
}
15221511

15231512
_focusItem() {

0 commit comments

Comments
 (0)