Skip to content

Commit 6fbd60b

Browse files
authored
fix(accordion): improved reliability of accordion animations (#23531)
resolves #23504
1 parent 9a60dd0 commit 6fbd60b

File tree

1 file changed

+17
-30
lines changed

1 file changed

+17
-30
lines changed

core/src/components/accordion/accordion.tsx

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -208,26 +208,19 @@ export class Accordion implements ComponentInterface {
208208
}
209209

210210
if (this.shouldAnimate()) {
211-
this.state = AccordionState.Expanding;
211+
raf(() => {
212+
this.state = AccordionState.Expanding;
212213

213-
this.currentRaf = raf(async () => {
214-
const contentHeight = contentElWrapper.offsetHeight;
215-
const waitForTransition = transitionEndAsync(contentEl, 2000);
216-
contentEl.style.setProperty('max-height', `${contentHeight}px`);
217-
218-
/**
219-
* Force a repaint. We can't use an raf
220-
* here as it could cause the collapse animation
221-
* to get out of sync with the other
222-
* accordion's expand animation.
223-
*/
224-
// tslint:disable-next-line
225-
void contentEl.offsetHeight;
214+
this.currentRaf = raf(async () => {
215+
const contentHeight = contentElWrapper.offsetHeight;
216+
const waitForTransition = transitionEndAsync(contentEl, 2000);
217+
contentEl.style.setProperty('max-height', `${contentHeight}px`);
226218

227-
await waitForTransition;
219+
await waitForTransition;
228220

229-
this.state = AccordionState.Expanded;
230-
contentEl.style.removeProperty('max-height');
221+
this.state = AccordionState.Expanded;
222+
contentEl.style.removeProperty('max-height');
223+
});
231224
});
232225
} else {
233226
this.state = AccordionState.Expanded;
@@ -254,22 +247,16 @@ export class Accordion implements ComponentInterface {
254247
const contentHeight = contentEl.offsetHeight;
255248
contentEl.style.setProperty('max-height', `${contentHeight}px`);
256249

257-
/**
258-
* Force a repaint. We can't use an raf
259-
* here as it could cause the collapse animation
260-
* to get out of sync with the other
261-
* accordion's expand animation.
262-
*/
263-
// tslint:disable-next-line
264-
void contentEl.offsetHeight;
250+
raf(async () => {
251+
const waitForTransition = transitionEndAsync(contentEl, 2000);
265252

266-
const waitForTransition = transitionEndAsync(contentEl, 2000);
267-
this.state = AccordionState.Collapsing;
253+
this.state = AccordionState.Collapsing;
268254

269-
await waitForTransition;
255+
await waitForTransition;
270256

271-
this.state = AccordionState.Collapsed;
272-
contentEl.style.removeProperty('max-height');
257+
this.state = AccordionState.Collapsed;
258+
contentEl.style.removeProperty('max-height');
259+
});
273260
});
274261
} else {
275262
this.state = AccordionState.Collapsed;

0 commit comments

Comments
 (0)