Skip to content

Conversation

@ShaneK
Copy link
Member

@ShaneK ShaneK commented Oct 16, 2025

Issue number: resolves #30613


What is the current behavior?

Currently, when you load an accordion group, the initially selected accordion animates open. This is an unexpected change caused by upgrading Stencil to >= 4.21.0, which changed the way component lifecycles got triggered.

What is the new behavior?

With this change, we're waiting for the accordion in the accordion group to render and telling it if the update it's going through is the initial update or not. This allows it to decide to animate properly.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Current dev build:

8.7.8-dev.11761840817.1bede576

@ShaneK ShaneK requested a review from a team as a code owner October 16, 2025 12:11
@ShaneK ShaneK requested a review from thetaPC October 16, 2025 12:11
@vercel
Copy link

vercel bot commented Oct 16, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
ionic-framework Ready Ready Preview Comment Oct 30, 2025 4:38pm

@github-actions github-actions bot added the package: core @ionic/core package label Oct 16, 2025
@aeharding
Copy link
Contributor

@ShaneK Thanks for fixing this!

It looks great in the main react use examples, but I did find the following case where it doesn't animate initially. It used to work before but maybe I'm not doing things right I just wanted to let you know :P

https://stackblitz.com/edit/dbaxphvw-jt3durvs?file=src%2Fmain.tsx

@ShaneK
Copy link
Member Author

ShaneK commented Oct 20, 2025

@aeharding

@ShaneK Thanks for fixing this!

It looks great in the main react use examples, but I did find the following case where it doesn't animate initially. It used to work before but maybe I'm not doing things right I just wanted to let you know :P

https://stackblitz.com/edit/dbaxphvw-jt3durvs?file=src%2Fmain.tsx

Excellent catch, new dev build should address this.

8.7.8-dev.11760975768.12095f2f

@aeharding
Copy link
Contributor

Thanks works great!

const firstAccordion = accordionGroup.querySelector('ion-accordion[value="first"]')!;

expect(firstAccordion.classList.contains('accordion-expanded')).toEqual(true);
expect(firstAccordion.classList.contains('accordion-expanding')).toEqual(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize that spec tests capture these kinds of classes. I would have expected it to be false all the time since expect would run after the animation ended. I'll have to keep this in mind for future tests. Thanks!

Copy link
Contributor

@thetaPC thetaPC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still seeing the arrows animate in the React app. Angular app is working well with the dev build, no animation on the accordions including the arrows.

@ShaneK
Copy link
Member Author

ShaneK commented Oct 21, 2025

@thetaPC

I'm still seeing the arrows animate in the React app. Angular app is working well with the dev build, no animation on the accordions including the arrows.

Okay, I think I've got it! New dev build:

8.7.8-dev.11761061696.163f32a5

Copy link
Contributor

@thetaPC thetaPC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, minor request

Copy link
Contributor

@thetaPC thetaPC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@brandyscarney brandyscarney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found an issue with expanded accordions on the basic test. They do not animate on collapse:

accordion-branch.mov

…kip state and allow animations on first interaction
@ShaneK
Copy link
Member Author

ShaneK commented Oct 22, 2025

I found an issue with expanded accordions on the basic test. They do not animate on collapse:
[...]

New dev build:

8.7.8-dev.11761141403.190ebfba

@github-actions github-actions bot added the package: react @ionic/react package label Oct 28, 2025
… forceUpdate to try to prevent race conditions
Copy link
Member

@brandyscarney brandyscarney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nits but overall it looks good! Great update.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we revert the changes to this file since it doesn't do anything?

Comment on lines +48 to +52
const value = accordionGroup.value;
const accordionValue = this.value;
const shouldExpand = Array.isArray(value) ? value.includes(accordionValue) : value === accordionValue;
const isExpanded = this.state === AccordionState.Expanded || this.state === AccordionState.Expanding;
const stateWillChange = shouldExpand !== isExpanded;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It might make more sense to clarify which value belongs to the group, since I'd expect value to refer to the current component:

Suggested change
const value = accordionGroup.value;
const accordionValue = this.value;
const shouldExpand = Array.isArray(value) ? value.includes(accordionValue) : value === accordionValue;
const isExpanded = this.state === AccordionState.Expanded || this.state === AccordionState.Expanding;
const stateWillChange = shouldExpand !== isExpanded;
const groupValue = accordionGroup.value;
const value = this.value;
const shouldExpand = Array.isArray(groupValue) ? groupValue.includes(value) : groupValue === value;
const isExpanded = this.state === AccordionState.Expanded || this.state === AccordionState.Expanding;
const stateWillChange = shouldExpand !== isExpanded;

* This prevents the initial undefined value from the group's componentDidLoad
* from being treated as the first real update.
*/
if (value !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (value !== undefined) {
if (groupValue !== undefined) {

See above

Copy link
Contributor

@thetaPC thetaPC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with minor suggestion

export class Accordion implements ComponentInterface {
private accordionGroupEl?: HTMLIonAccordionGroupElement | null;
private updateListener = () => this.updateState(false);
private updateListener = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to take this opportunity to change the name to something a bit more descriptive. I'll leave it up to you though if the change needs to be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package package: react @ionic/react package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: ion-accordion plays animation on initial state update when using Angular property binding

5 participants