Skip to content

Commit 004a943

Browse files
authored
Revert "fix(material/tree): aria-expanded attribute should not appear in the leaf node (#29096)" (#29272)
This reverts commit 43b8dcb.
1 parent 607da66 commit 004a943

File tree

4 files changed

+33
-38
lines changed

4 files changed

+33
-38
lines changed

src/cdk/tree/tree.spec.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,20 @@ describe('CdkTree', () => {
145145
let data = dataSource.data;
146146
dataSource.addChild(data[2]);
147147
fixture.detectChanges();
148-
let ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
149-
expect(ariaExpandedStates).toEqual([null, null, 'false', null]);
148+
expect(
149+
getNodes(treeElement).every(node => {
150+
return node.getAttribute('aria-expanded') === 'false';
151+
}),
152+
).toBe(true);
150153

151154
component.treeControl.expandAll();
152155
fixture.detectChanges();
153156

154-
ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
155-
expect(ariaExpandedStates).toEqual([null, null, 'true', null]);
157+
expect(
158+
getNodes(treeElement).every(node => {
159+
return node.getAttribute('aria-expanded') === 'true';
160+
}),
161+
).toBe(true);
156162
});
157163

158164
it('with the right data', () => {
@@ -799,8 +805,11 @@ describe('CdkTree', () => {
799805
});
800806

801807
it('with the right aria-expanded attrs', () => {
802-
let ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
803-
expect(ariaExpandedStates).toEqual([null, null, null]);
808+
expect(
809+
getNodes(treeElement).every(node => {
810+
return node.getAttribute('aria-expanded') === 'false';
811+
}),
812+
).toBe(true);
804813

805814
component.toggleRecursively = false;
806815
fixture.changeDetectorRef.markForCheck();
@@ -813,7 +822,7 @@ describe('CdkTree', () => {
813822
fixture.detectChanges();
814823

815824
const ariaExpanded = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
816-
expect(ariaExpanded).toEqual([null, 'true', 'false', null]);
825+
expect(ariaExpanded).toEqual(['false', 'true', 'false', 'false']);
817826
});
818827

819828
it('should expand/collapse the node multiple times', () => {
@@ -877,7 +886,6 @@ describe('CdkTree', () => {
877886
});
878887

879888
it('should expand/collapse the node recursively', () => {
880-
fixture.changeDetectorRef.markForCheck();
881889
let data = dataSource.data;
882890
const child = dataSource.addChild(data[1], false);
883891
dataSource.addChild(child, false);

src/cdk/tree/tree.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export class CdkTree<T, K = T> implements AfterContentChecked, CollectionViewer,
324324
exportAs: 'cdkTreeNode',
325325
host: {
326326
'class': 'cdk-tree-node',
327-
'[attr.aria-expanded]': 'isLeafNode ? null : isExpanded',
327+
'[attr.aria-expanded]': 'isExpanded',
328328
},
329329
standalone: true,
330330
})
@@ -375,26 +375,6 @@ export class CdkTreeNode<T, K = T> implements FocusableOption, OnDestroy, OnInit
375375
return this._tree.treeControl.isExpanded(this._data);
376376
}
377377

378-
/* If leaf node, return true to not assign aria-expanded attribute */
379-
get isLeafNode(): boolean {
380-
// If flat tree node data returns false for expandable property, it's a leaf node
381-
if (
382-
this._tree.treeControl.isExpandable !== undefined &&
383-
!this._tree.treeControl.isExpandable(this._data)
384-
) {
385-
return true;
386-
387-
// If nested tree node data returns 0 descendants, it's a leaf node
388-
} else if (
389-
this._tree.treeControl.isExpandable === undefined &&
390-
this._tree.treeControl.getDescendants(this._data).length === 0
391-
) {
392-
return true;
393-
}
394-
395-
return false;
396-
}
397-
398378
get level(): number {
399379
// If the treeControl has a getLevel method, use it to get the level. Otherwise read the
400380
// aria-level off the parent node and use it as the level for this node (note aria-level is

src/material/tree/tree.spec.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,20 @@ describe('MatTree', () => {
7878
const data = underlyingDataSource.data;
7979
underlyingDataSource.addChild(data[2]);
8080
fixture.detectChanges();
81-
let ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
82-
expect(ariaExpandedStates).toEqual([null, null, 'false']);
81+
expect(
82+
getNodes(treeElement).every(node => {
83+
return node.getAttribute('aria-expanded') === 'false';
84+
}),
85+
).toBe(true);
8386

8487
component.treeControl.expandAll();
8588
fixture.detectChanges();
8689

87-
ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
88-
expect(ariaExpandedStates).toEqual([null, null, 'true', null]);
90+
expect(
91+
getNodes(treeElement).every(node => {
92+
return node.getAttribute('aria-expanded') === 'true';
93+
}),
94+
).toBe(true);
8995
});
9096

9197
it('with the right data', () => {
@@ -464,8 +470,11 @@ describe('MatTree', () => {
464470
});
465471

466472
it('with the right aria-expanded attrs', () => {
467-
let ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
468-
expect(ariaExpandedStates).toEqual([null, null, null]);
473+
expect(
474+
getNodes(treeElement).every(node => {
475+
return node.getAttribute('aria-expanded') === 'false';
476+
}),
477+
).toBe(true);
469478

470479
component.toggleRecursively = false;
471480
const data = underlyingDataSource.data;
@@ -477,7 +486,7 @@ describe('MatTree', () => {
477486
fixture.detectChanges();
478487

479488
const ariaExpanded = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
480-
expect(ariaExpanded).toEqual([null, 'true', 'false', null]);
489+
expect(ariaExpanded).toEqual(['false', 'true', 'false', 'false']);
481490
});
482491

483492
it('should expand/collapse the node', () => {

tools/public_api_guard/cdk/tree.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ export class CdkTreeNode<T, K = T> implements FocusableOption, OnDestroy, OnInit
127127
// (undocumented)
128128
get isExpanded(): boolean;
129129
// (undocumented)
130-
get isLeafNode(): boolean;
131-
// (undocumented)
132130
get level(): number;
133131
static mostRecentTreeNode: CdkTreeNode<any> | null;
134132
// (undocumented)

0 commit comments

Comments
 (0)