Skip to content

Commit e345efd

Browse files
committed
fix(accordion): defaulting to skip initial animation until first render
1 parent 90ebfba commit e345efd

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

core/src/components/accordion/accordion.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class Accordion implements ComponentInterface {
5555
* This prevents the accordion from animating when
5656
* it starts expanded or collapsed.
5757
*/
58-
private skipNextAnimation = false;
58+
private skipNextAnimation = true;
5959

6060
@Element() el?: HTMLElement;
6161

packages/react/test/base/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import KeepContentsMounted from './pages/overlay-components/KeepContentsMounted'
3737
import OverlayComponents from './pages/overlay-components/OverlayComponents';
3838
import OverlayHooks from './pages/overlay-hooks/OverlayHooks';
3939
import ReorderGroup from './pages/ReorderGroup';
40+
import AccordionGroup from './pages/AccordionGroup';
4041

4142
setupIonicReact();
4243

@@ -69,6 +70,7 @@ const App: React.FC = () => (
6970
<Route path="/icons" component={Icons} />
7071
<Route path="/inputs" component={Inputs} />
7172
<Route path="/reorder-group" component={ReorderGroup} />
73+
<Route path="/accordion-group" component={AccordionGroup} />
7274
</IonRouterOutlet>
7375
</IonReactRouter>
7476
</IonApp>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { IonHeader, IonTitle, IonToolbar, IonPage, IonContent, IonAccordionGroup, IonAccordion, IonItem, IonLabel } from '@ionic/react';
2+
import { useEffect, useRef } from 'react';
3+
4+
const AccordionGroup: React.FC = () => {
5+
const accordionGroup = useRef<null | HTMLIonAccordionGroupElement>(null);
6+
7+
useEffect(() => {
8+
if (!accordionGroup.current) {
9+
return;
10+
}
11+
12+
accordionGroup.current.value = ['first', 'third'];
13+
}, []);
14+
15+
return (
16+
<IonPage>
17+
<IonHeader>
18+
<IonToolbar>
19+
<IonTitle>Accordion Group</IonTitle>
20+
</IonToolbar>
21+
</IonHeader>
22+
<IonContent>
23+
<IonAccordionGroup ref={accordionGroup} multiple={true}>
24+
<IonAccordion value="first">
25+
<IonItem slot="header" color="light">
26+
<IonLabel>First Accordion</IonLabel>
27+
</IonItem>
28+
<div className="ion-padding" slot="content">
29+
First Content
30+
</div>
31+
</IonAccordion>
32+
<IonAccordion value="second">
33+
<IonItem slot="header" color="light">
34+
<IonLabel>Second Accordion</IonLabel>
35+
</IonItem>
36+
<div className="ion-padding" slot="content">
37+
Second Content
38+
</div>
39+
</IonAccordion>
40+
<IonAccordion value="third">
41+
<IonItem slot="header" color="light">
42+
<IonLabel>Third Accordion</IonLabel>
43+
</IonItem>
44+
<div className="ion-padding" slot="content">
45+
Third Content
46+
</div>
47+
</IonAccordion>
48+
</IonAccordionGroup>
49+
</IonContent>
50+
</IonPage>
51+
);
52+
};
53+
54+
export default AccordionGroup;

packages/react/test/base/src/pages/Main.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const Main: React.FC<MainProps> = () => {
2222
</IonHeader>
2323
<IonContent>
2424
<IonList>
25+
<IonItem routerLink="/accordion-group">
26+
<IonLabel>Accordion Group</IonLabel>
27+
</IonItem>
2528
<IonItem routerLink="/overlay-hooks">
2629
<IonLabel>Overlay Hooks</IonLabel>
2730
</IonItem>

0 commit comments

Comments
 (0)