-
Couldn't load subscription status.
- Fork 13.4k
fix(accordion-group): skip initial animation #30729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
58c2a8a
fix(accordion): skip initial animation
ShaneK 761d06f
fix(accordion-group): fixing animation in react
ShaneK 1a1dcda
Merge branch 'main' of github.com:ionic-team/ionic-framework into FW-...
ShaneK 2095f2f
fix(accordion): animating open if the first opening is done by the user
ShaneK 63f32a5
fix(accordion-group): skipping initial arrow animation
ShaneK cc125e6
chore(accordion): adding comment explaining when we want to skip the ...
ShaneK 90ebfba
fix(accordion): re-rendering after intitial load to reset animation s...
ShaneK e345efd
fix(accordion): defaulting to skip initial animation until first render
ShaneK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { newSpecPage } from '@stencil/core/testing'; | ||
|
|
||
| import type { AccordionGroupChangeEventDetail } from '../../accordion-group/accordion-group-interface'; | ||
| import { AccordionGroup } from '../../accordion-group/accordion-group'; | ||
| import { Item } from '../../item/item'; | ||
| import { Accordion } from '../accordion'; | ||
|
|
@@ -200,6 +201,108 @@ it('should set default values if not provided', async () => { | |
| expect(accordion.classList.contains('accordion-collapsed')).toEqual(false); | ||
| }); | ||
|
|
||
| it('should not animate when initial value is set before load', async () => { | ||
| const page = await newSpecPage({ | ||
| components: [Item, Accordion, AccordionGroup], | ||
| }); | ||
|
|
||
| const accordionGroup = page.doc.createElement('ion-accordion-group'); | ||
| accordionGroup.innerHTML = ` | ||
| <ion-accordion value="first"> | ||
| <ion-item slot="header">Label</ion-item> | ||
| <div slot="content">Content</div> | ||
| </ion-accordion> | ||
| <ion-accordion value="second"> | ||
| <ion-item slot="header">Label</ion-item> | ||
| <div slot="content">Content</div> | ||
| </ion-accordion> | ||
| `; | ||
|
|
||
| const details: AccordionGroupChangeEventDetail[] = []; | ||
| accordionGroup.addEventListener('ionValueChange', (event: CustomEvent<AccordionGroupChangeEventDetail>) => { | ||
| details.push(event.detail); | ||
| }); | ||
|
|
||
| accordionGroup.value = 'first'; | ||
| page.body.appendChild(accordionGroup); | ||
|
|
||
| await page.waitForChanges(); | ||
|
|
||
| expect(details[0]?.initial).toBe(true); | ||
|
|
||
| const firstAccordion = accordionGroup.querySelector('ion-accordion[value="first"]')!; | ||
|
|
||
| expect(firstAccordion.classList.contains('accordion-expanded')).toEqual(true); | ||
| expect(firstAccordion.classList.contains('accordion-expanding')).toEqual(false); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| }); | ||
|
|
||
| it('should not animate when initial value is set after load', async () => { | ||
| const page = await newSpecPage({ | ||
| components: [Item, Accordion, AccordionGroup], | ||
| }); | ||
|
|
||
| const accordionGroup = page.doc.createElement('ion-accordion-group'); | ||
| accordionGroup.innerHTML = ` | ||
| <ion-accordion value="first"> | ||
| <ion-item slot="header">Label</ion-item> | ||
| <div slot="content">Content</div> | ||
| </ion-accordion> | ||
| <ion-accordion value="second"> | ||
| <ion-item slot="header">Label</ion-item> | ||
| <div slot="content">Content</div> | ||
| </ion-accordion> | ||
| `; | ||
|
|
||
| const details: AccordionGroupChangeEventDetail[] = []; | ||
| accordionGroup.addEventListener('ionValueChange', (event: CustomEvent<AccordionGroupChangeEventDetail>) => { | ||
| details.push(event.detail); | ||
| }); | ||
|
|
||
| page.body.appendChild(accordionGroup); | ||
| await page.waitForChanges(); | ||
|
|
||
| accordionGroup.value = 'first'; | ||
| await page.waitForChanges(); | ||
|
|
||
| const firstDetail = details.find((detail) => detail.value === 'first'); | ||
| expect(firstDetail?.initial).toBe(true); | ||
|
|
||
| const firstAccordion = accordionGroup.querySelector('ion-accordion[value="first"]')!; | ||
|
|
||
| expect(firstAccordion.classList.contains('accordion-expanded')).toEqual(true); | ||
| expect(firstAccordion.classList.contains('accordion-expanding')).toEqual(false); | ||
| }); | ||
|
|
||
| it('should animate when accordion is first opened by user', async () => { | ||
| const page = await newSpecPage({ | ||
| components: [Item, Accordion, AccordionGroup], | ||
| html: ` | ||
| <ion-accordion-group> | ||
| <ion-accordion value="first"> | ||
| <ion-item slot="header">Label</ion-item> | ||
| <div slot="content">Content</div> | ||
| </ion-accordion> | ||
| </ion-accordion-group> | ||
| `, | ||
| }); | ||
|
|
||
| const accordionGroup = page.body.querySelector('ion-accordion-group')!; | ||
|
|
||
| const details: AccordionGroupChangeEventDetail[] = []; | ||
| accordionGroup.addEventListener('ionValueChange', (event: CustomEvent<AccordionGroupChangeEventDetail>) => { | ||
| details.push(event.detail); | ||
| }); | ||
|
|
||
| await accordionGroup.requestAccordionToggle('first', true); | ||
| await page.waitForChanges(); | ||
|
|
||
| const lastDetail = details[details.length - 1]; | ||
| expect(lastDetail?.initial).toBe(false); | ||
|
|
||
| const firstAccordion = accordionGroup.querySelector('ion-accordion[value="first"]')!; | ||
| expect(firstAccordion.classList.contains('accordion-animated')).toEqual(true); | ||
| }); | ||
|
|
||
| // Verifies fix for https://github.com/ionic-team/ionic-framework/issues/27047 | ||
| it('should not have animated class when animated="false"', async () => { | ||
| const page = await newSpecPage({ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { IonHeader, IonTitle, IonToolbar, IonPage, IonContent, IonAccordionGroup, IonAccordion, IonItem, IonLabel } from '@ionic/react'; | ||
| import { useEffect, useRef } from 'react'; | ||
|
|
||
| const AccordionGroup: React.FC = () => { | ||
| const accordionGroup = useRef<null | HTMLIonAccordionGroupElement>(null); | ||
|
|
||
| useEffect(() => { | ||
| if (!accordionGroup.current) { | ||
| return; | ||
| } | ||
|
|
||
| accordionGroup.current.value = ['first', 'third']; | ||
| }, []); | ||
|
|
||
| return ( | ||
| <IonPage> | ||
| <IonHeader> | ||
| <IonToolbar> | ||
| <IonTitle>Accordion Group</IonTitle> | ||
| </IonToolbar> | ||
| </IonHeader> | ||
| <IonContent> | ||
| <IonAccordionGroup ref={accordionGroup} multiple={true}> | ||
| <IonAccordion value="first"> | ||
| <IonItem slot="header" color="light"> | ||
| <IonLabel>First Accordion</IonLabel> | ||
| </IonItem> | ||
| <div className="ion-padding" slot="content"> | ||
| First Content | ||
| </div> | ||
| </IonAccordion> | ||
| <IonAccordion value="second"> | ||
| <IonItem slot="header" color="light"> | ||
| <IonLabel>Second Accordion</IonLabel> | ||
| </IonItem> | ||
| <div className="ion-padding" slot="content"> | ||
| Second Content | ||
| </div> | ||
| </IonAccordion> | ||
| <IonAccordion value="third"> | ||
| <IonItem slot="header" color="light"> | ||
| <IonLabel>Third Accordion</IonLabel> | ||
| </IonItem> | ||
| <div className="ion-padding" slot="content"> | ||
| Third Content | ||
| </div> | ||
| </IonAccordion> | ||
| </IonAccordionGroup> | ||
| </IonContent> | ||
| </IonPage> | ||
| ); | ||
| }; | ||
|
|
||
| export default AccordionGroup; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.