Skip to content

Commit 8e1b1f1

Browse files
✨ Add prop to skip Accordion animation
Allows skipping the accordion animation via a new prop. This is useful for scenarios where the animation is not desired, such as when the component is initially rendered in a hidden state.
1 parent 59a3486 commit 8e1b1f1

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

packages/core/src/components/accordion/Accordion.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ export type AccordionProps = {
130130
* Whether the icon should be rotating.
131131
*/
132132
shouldRotateIcon?: boolean;
133+
/**
134+
* Whether the animation should be skipped.
135+
* If 'isDefaultOpen' is true the initial animation will be skipped even this prop is false
136+
*/
137+
shouldSkipAnimation?: boolean;
133138
/**
134139
* Title of the Accordion displayed in the head
135140
*/
@@ -175,6 +180,7 @@ const Accordion: FC<AccordionProps> = ({
175180
titleElement,
176181
onTitleInputChange,
177182
titleInputProps,
183+
shouldSkipAnimation: shouldSkipAnimationProp = false,
178184
titleColor,
179185
onBodyAnimationComplete,
180186
}) => {
@@ -205,14 +211,8 @@ const Accordion: FC<AccordionProps> = ({
205211

206212
const initialRenderSkipRef = useInitialRenderRef(true);
207213

208-
const shouldSkipAnimation = initialRenderSkipRef.current && isDefaultOpen;
209-
210-
console.debug('TEST', {
211-
shouldSkipAnimation,
212-
isDefaultOpen,
213-
skipRef: initialRenderSkipRef.current,
214-
initialRef: isInitialRenderRef.current,
215-
});
214+
const shouldSkipAnimation =
215+
shouldSkipAnimationProp ?? (initialRenderSkipRef.current && isDefaultOpen);
216216

217217
const isOpenRef = useRef(isOpen);
218218
const onCloseRef = useRef(onClose);

0 commit comments

Comments
 (0)