File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff 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 ( ) ;
Original file line number Diff line number Diff line change @@ -209,6 +209,8 @@ export class Tree<V> {
209209 } ) ;
210210
211211 afterRenderEffect ( ( ) => {
212+ if ( ! ( this . _pattern instanceof ComboboxTreePattern ) ) return ;
213+
212214 const items = inputs . allItems ( ) ;
213215 const values = untracked ( ( ) => this . values ( ) ) ;
214216
You can’t perform that action at this time.
0 commit comments