Skip to content

Commit d71aca4

Browse files
🐛 fix: Fix accordion animation
1 parent 4adc236 commit d71aca4

File tree

3 files changed

+6
-22
lines changed

3 files changed

+6
-22
lines changed

src/Accordion/AccordionItem.tsx

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { AnimatePresence, LazyMotion, m } from 'framer-motion';
3+
import { LazyMotion, m } from 'framer-motion';
44
import { KeyboardEvent, memo, useCallback, useMemo } from 'react';
55
import { Flexbox } from 'react-layout-kit';
66

@@ -125,7 +125,7 @@ const AccordionItem = memo<AccordionItemProps>(
125125
() => ({
126126
animate: isOpen ? 'enter' : 'exit',
127127
exit: 'exit',
128-
initial: 'exit',
128+
initial: false,
129129
variants: {
130130
enter: {
131131
height: 'auto',
@@ -151,7 +151,7 @@ const AccordionItem = memo<AccordionItemProps>(
151151

152152
// Render content
153153
const contentElement = useMemo(() => {
154-
if (disableAnimation) {
154+
if (disableAnimation || !keepContentMounted) {
155155
if (keepContentMounted) {
156156
return (
157157
<div
@@ -180,7 +180,7 @@ const AccordionItem = memo<AccordionItemProps>(
180180
);
181181
}
182182

183-
return keepContentMounted ? (
183+
return (
184184
<LazyMotion features={loadFeatures}>
185185
<m.div {...motionProps} style={{ overflow: 'hidden' }}>
186186
<div
@@ -192,22 +192,6 @@ const AccordionItem = memo<AccordionItemProps>(
192192
</div>
193193
</m.div>
194194
</LazyMotion>
195-
) : (
196-
<AnimatePresence initial={false}>
197-
{isOpen && (
198-
<LazyMotion features={loadFeatures}>
199-
<m.div {...motionProps} style={{ overflow: 'hidden' }}>
200-
<div
201-
className={cx('accordion-content', styles.content, classNames?.content)}
202-
role="region"
203-
style={customStyles?.content}
204-
>
205-
<div className={styles.contentInner}>{children}</div>
206-
</div>
207-
</m.div>
208-
</LazyMotion>
209-
)}
210-
</AnimatePresence>
211195
);
212196
}, [
213197
disableAnimation,

src/Accordion/demos/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default () => {
3333
},
3434
keepContentMounted: {
3535
label: 'Keep Content Mounted',
36-
value: false,
36+
value: true,
3737
},
3838
showDivider: {
3939
label: 'Show Divider',

src/Accordion/type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export interface AccordionProps
110110
indicatorPlacement?: 'end' | 'start';
111111
/**
112112
* Keep content mounted when collapsed
113-
* @default false
113+
* @default true
114114
*/
115115
keepContentMounted?: boolean;
116116
/**

0 commit comments

Comments
 (0)