Skip to content

Commit 63f32a5

Browse files
committed
fix(accordion-group): skipping initial arrow animation
1 parent 2095f2f commit 63f32a5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

core/src/components/accordion/accordion.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class Accordion implements ComponentInterface {
4848
private headerEl: HTMLDivElement | undefined;
4949

5050
private currentRaf: number | undefined;
51+
private skipNextAnimation = false;
5152

5253
@Element() el?: HTMLElement;
5354

@@ -295,6 +296,10 @@ export class Accordion implements ComponentInterface {
295296
* of what is set in the config.
296297
*/
297298
private shouldAnimate = () => {
299+
if (this.skipNextAnimation) {
300+
return false;
301+
}
302+
298303
if (typeof (window as any) === 'undefined') {
299304
return false;
300305
}
@@ -316,6 +321,14 @@ export class Accordion implements ComponentInterface {
316321
return true;
317322
};
318323

324+
private disableAnimationTemporarily() {
325+
this.skipNextAnimation = true;
326+
}
327+
328+
componentDidRender() {
329+
this.skipNextAnimation = false;
330+
}
331+
319332
private updateState = async (initialUpdate = false) => {
320333
const accordionGroup = this.accordionGroupEl;
321334
const accordionValue = this.value;
@@ -327,6 +340,11 @@ export class Accordion implements ComponentInterface {
327340
const value = accordionGroup.value;
328341

329342
const shouldExpand = Array.isArray(value) ? value.includes(accordionValue) : value === accordionValue;
343+
const shouldDisableAnimation = initialUpdate && shouldExpand;
344+
345+
if (shouldDisableAnimation) {
346+
this.disableAnimationTemporarily();
347+
}
330348

331349
if (shouldExpand) {
332350
this.expandAccordion(initialUpdate);

core/src/components/accordion/test/accordion.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ it('should not animate when initial value is set before load', async () => {
234234

235235
expect(firstAccordion.classList.contains('accordion-expanded')).toEqual(true);
236236
expect(firstAccordion.classList.contains('accordion-expanding')).toEqual(false);
237+
expect(firstAccordion.classList.contains('accordion-animated')).toEqual(false);
237238
});
238239

239240
it('should not animate when initial value is set after load', async () => {
@@ -271,6 +272,7 @@ it('should not animate when initial value is set after load', async () => {
271272

272273
expect(firstAccordion.classList.contains('accordion-expanded')).toEqual(true);
273274
expect(firstAccordion.classList.contains('accordion-expanding')).toEqual(false);
275+
expect(firstAccordion.classList.contains('accordion-animated')).toEqual(false);
274276
});
275277

276278
it('should animate when accordion is first opened by user', async () => {
@@ -298,6 +300,9 @@ it('should animate when accordion is first opened by user', async () => {
298300

299301
const lastDetail = details[details.length - 1];
300302
expect(lastDetail?.initial).toBe(false);
303+
304+
const firstAccordion = accordionGroup.querySelector('ion-accordion[value="first"]')!;
305+
expect(firstAccordion.classList.contains('accordion-animated')).toEqual(true);
301306
});
302307

303308
// Verifies fix for https://github.com/ionic-team/ionic-framework/issues/27047

0 commit comments

Comments
 (0)