Skip to content

Commit 85e6066

Browse files
committed
fix(aria/tree): only reset selected values if used in combobox
1 parent 1629175 commit 85e6066

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/aria/tree/tree.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {By} from '@angular/platform-browser';
55
import {Direction} from '@angular/cdk/bidi';
66
import {provideFakeDirectionality, runAccessibilityChecks} from '@angular/cdk/testing/private';
77
import {Tree, TreeItem, TreeItemGroup} from './tree';
8+
import {A} from '@angular/cdk/keycodes';
89

910
interface ModifierKeys {
1011
ctrlKey?: boolean;
@@ -1067,6 +1068,48 @@ describe('Tree', () => {
10671068
expect(berriesEl.getAttribute('aria-expanded')).toBe('true');
10681069
});
10691070

1071+
it('should not affect selected item when collapse', () => {
1072+
setupTestTree();
1073+
updateTree({
1074+
nodes: [
1075+
{
1076+
value: 'fruits',
1077+
label: 'Fruits',
1078+
children: [
1079+
{value: 'apple', label: 'Apple'},
1080+
{value: 'banana', label: 'Banana'},
1081+
{
1082+
value: 'berries',
1083+
label: 'Berries',
1084+
children: [
1085+
{value: 'strawberry', label: 'Strawberry'},
1086+
{value: 'blueberry', label: 'Blueberry'},
1087+
],
1088+
expanded: true,
1089+
},
1090+
],
1091+
expanded: true,
1092+
},
1093+
],
1094+
});
1095+
const blueberryEl = getTreeItemElementByValue('blueberry')!;
1096+
const berriesEl = getTreeItemElementByValue('berries')!;
1097+
const fruits = getTreeItemElementByValue('fruits')!;
1098+
1099+
click(blueberryEl);
1100+
expect(treeInstance.values()).toEqual(['blueberry']);
1101+
1102+
left();
1103+
left(); // collapse berries
1104+
expect(berriesEl.getAttribute('aria-expanded')).toBe('false');
1105+
expect(treeInstance.values()).toEqual(['blueberry']);
1106+
1107+
left();
1108+
left(); // collapse fruits
1109+
expect(fruits.getAttribute('aria-expanded')).toBe('false');
1110+
expect(treeInstance.values()).toEqual(['blueberry']);
1111+
});
1112+
10701113
describe('LTR', () => {
10711114
beforeEach(() => {
10721115
setupTestTree();

src/aria/tree/tree.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ export class Tree<V> {
208208
});
209209

210210
afterRenderEffect(() => {
211+
if (!(this._pattern instanceof ComboboxTreePattern)) return;
212+
211213
const items = inputs.allItems();
212214
const values = untracked(() => this.values());
213215

0 commit comments

Comments
 (0)