Skip to content

Commit 45ef5ae

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

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/aria/tree/tree.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,48 @@ describe('Tree', () => {
10671067
expect(berriesEl.getAttribute('aria-expanded')).toBe('true');
10681068
});
10691069

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