Skip to content

Commit 90ebfba

Browse files
committed
fix(accordion): re-rendering after intitial load to reset animation skip state and allow animations on first interaction
1 parent cc125e6 commit 90ebfba

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

core/src/components/accordion/accordion.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ComponentInterface } from '@stencil/core';
2-
import { Component, Element, Host, Prop, State, Watch, h } from '@stencil/core';
2+
import { Component, Element, Host, Prop, State, Watch, forceUpdate, h } from '@stencil/core';
33
import { addEventListener, getElementRoot, raf, removeEventListener, transitionEndAsync } from '@utils/helpers';
44
import { chevronDown } from 'ionicons/icons';
55

@@ -132,7 +132,15 @@ export class Accordion implements ComponentInterface {
132132
}
133133

134134
componentDidRender() {
135-
this.skipNextAnimation = false;
135+
if (this.skipNextAnimation) {
136+
this.skipNextAnimation = false;
137+
/**
138+
* The initial render disables animations so framework-provided
139+
* values do not cause the accordion to animate. Force a repaint
140+
* so subsequent user interactions animate as expected.
141+
*/
142+
forceUpdate(this);
143+
}
136144
}
137145

138146
private setItemDefaults = () => {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ 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);
238237
});
239238

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

273272
expect(firstAccordion.classList.contains('accordion-expanded')).toEqual(true);
274273
expect(firstAccordion.classList.contains('accordion-expanding')).toEqual(false);
275-
expect(firstAccordion.classList.contains('accordion-animated')).toEqual(false);
276274
});
277275

278276
it('should animate when accordion is first opened by user', async () => {

0 commit comments

Comments
 (0)