Skip to content

Commit f46802b

Browse files
committed
fix(accordion): trying to prevent animation based on interaction rather than render
1 parent f84c484 commit f46802b

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

core/src/components/accordion/accordion.tsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ export class Accordion implements ComponentInterface {
4141
private accordionGroupEl?: HTMLIonAccordionGroupElement | null;
4242
private updateListener = (ev: CustomEvent<AccordionGroupChangeEventDetail>) => {
4343
const initialUpdate = ev.detail?.initial ?? false;
44+
/**
45+
* If this is not an initial update (meaning it's from a user interaction
46+
* or programmatic call after load), mark that we've had an interaction.
47+
* This enables animations for this and future updates.
48+
*/
49+
if (!initialUpdate) {
50+
this.hasInteracted = true;
51+
}
4452
this.updateState(initialUpdate);
4553
};
4654
private contentEl: HTMLDivElement | undefined;
@@ -55,12 +63,12 @@ export class Accordion implements ComponentInterface {
5563
@State() isNext = false;
5664
@State() isPrevious = false;
5765
/**
58-
* Tracks whether the component has completed its initial render.
59-
* Animations are disabled until after the first render completes.
60-
* This prevents the accordion from animating when it starts
61-
* expanded or collapsed on initial load.
66+
* Tracks whether a user-initiated interaction has occurred.
67+
* Animations are disabled until the first interaction happens.
68+
* This prevents the accordion from animating when it's programmatically
69+
* set to an expanded or collapsed state on initial load.
6270
*/
63-
@State() hasRendered = false;
71+
@State() hasInteracted = false;
6472

6573
/**
6674
* The value of the accordion. Defaults to an autogenerated
@@ -130,17 +138,6 @@ export class Accordion implements ComponentInterface {
130138
});
131139
}
132140

133-
componentDidRender() {
134-
/**
135-
* After the first render completes, mark that we've rendered.
136-
* Setting this state property triggers a re-render, at which point
137-
* animations will be enabled. This ensures animations are disabled
138-
* only for the initial render, avoiding unwanted animations on load.
139-
*/
140-
if (!this.hasRendered) {
141-
this.hasRendered = true;
142-
}
143-
}
144141

145142
private setItemDefaults = () => {
146143
const ionItem = this.getSlottedHeaderIonItem();
@@ -315,11 +312,11 @@ export class Accordion implements ComponentInterface {
315312
*/
316313
private shouldAnimate = () => {
317314
/**
318-
* Don't animate until after the first render cycle completes.
315+
* Don't animate until after the first user interaction.
319316
* This prevents animations on initial load when accordions
320-
* start in an expanded or collapsed state.
317+
* start in an expanded or collapsed state programmatically.
321318
*/
322-
if (!this.hasRendered) {
319+
if (!this.hasInteracted) {
323320
return false;
324321
}
325322

@@ -418,6 +415,12 @@ export class Accordion implements ComponentInterface {
418415

419416
if (disabled || readonly) return;
420417

418+
/**
419+
* Mark that the user has interacted with the accordion.
420+
* This enables animations for all future state changes.
421+
*/
422+
this.hasInteracted = true;
423+
421424
if (accordionGroupEl) {
422425
/**
423426
* Because the accordion group may or may

0 commit comments

Comments
 (0)