File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -114,10 +114,12 @@ export const AccordionMixin = (superClass) =>
114
114
/** @private */
115
115
_updateItems ( items , opened ) {
116
116
if ( items ) {
117
+ this . __itemsSync = true ;
117
118
const itemToOpen = items [ opened ] ;
118
119
items . forEach ( ( item ) => {
119
120
item . opened = item === itemToOpen ;
120
121
} ) ;
122
+ this . __itemsSync = false ;
121
123
}
122
124
}
123
125
@@ -140,6 +142,11 @@ export const AccordionMixin = (superClass) =>
140
142
141
143
/** @private */
142
144
_updateOpened ( e ) {
145
+ // Item sync applies the current opened index to each item, in which
146
+ // case we don't need to update the opened index again.
147
+ if ( this . __itemsSync ) {
148
+ return ;
149
+ }
143
150
const target = this . _filterItems ( e . composedPath ( ) ) [ 0 ] ;
144
151
const idx = this . items . indexOf ( target ) ;
145
152
if ( e . detail . value ) {
Original file line number Diff line number Diff line change @@ -139,14 +139,22 @@ describe('vaadin-accordion', () => {
139
139
expect ( accordion . opened ) . to . equal ( 0 ) ;
140
140
} ) ;
141
141
142
- it ( 'should dispatch opened-changed event when opened changes' , async ( ) => {
142
+ it ( 'should dispatch single opened-changed event when opened changes' , async ( ) => {
143
143
const spy = sinon . spy ( ) ;
144
144
accordion . addEventListener ( 'opened-changed' , spy ) ;
145
145
getHeading ( 1 ) . click ( ) ;
146
146
await nextUpdate ( accordion ) ;
147
147
expect ( spy . calledOnce ) . to . be . true ;
148
148
} ) ;
149
149
150
+ it ( 'should dispatch single opened-changed event when changing opened index property' , async ( ) => {
151
+ const spy = sinon . spy ( ) ;
152
+ accordion . addEventListener ( 'opened-changed' , spy ) ;
153
+ accordion . opened = 1 ;
154
+ await nextUpdate ( accordion ) ;
155
+ expect ( spy ) . to . be . calledOnce ;
156
+ } ) ;
157
+
150
158
it ( 'should open panel when component in summary is clicked' , async ( ) => {
151
159
getHeading ( 2 ) . firstChild . click ( ) ;
152
160
await nextUpdate ( accordion ) ;
You can’t perform that action at this time.
0 commit comments