Skip to content

Commit f617f22

Browse files
committed
fix(cdk/tree): tests
1 parent 0c8a01e commit f617f22

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
@@ -625,15 +625,7 @@ export class CdkTree<T, K = T>
625625
}
626626
});
627627

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

639631
/**
@@ -1473,7 +1465,6 @@ export class CdkTreeNode<T, K = T> implements OnDestroy, OnInit, TreeKeyManagerI
14731465
/** Focuses this data node. Implemented for TreeKeyManagerItem. */
14741466
focus(): void {
14751467
this._tabindex.set(0);
1476-
this._changeDetectorRef.detectChanges();
14771468
if (this._shouldFocus) {
14781469
this._elementRef.nativeElement.focus();
14791470
}
@@ -1482,7 +1473,6 @@ export class CdkTreeNode<T, K = T> implements OnDestroy, OnInit, TreeKeyManagerI
14821473
/** Defocus this data node. */
14831474
unfocus(): void {
14841475
this._tabindex.set(-1);
1485-
this._changeDetectorRef.detectChanges();
14861476
}
14871477

14881478
/** Emits an activation event. Implemented for TreeKeyManagerItem. */
@@ -1510,7 +1500,6 @@ export class CdkTreeNode<T, K = T> implements OnDestroy, OnInit, TreeKeyManagerI
15101500
/** Makes the node focusable. Implemented for TreeKeyManagerItem. */
15111501
makeFocusable(): void {
15121502
this._tabindex.set(0);
1513-
this._changeDetectorRef.detectChanges();
15141503
}
15151504

15161505
_focusItem() {

0 commit comments

Comments
 (0)