-
-
Notifications
You must be signed in to change notification settings - Fork 496
feat: add smooth animation to Accordion component #1661
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,11 @@ export function AccordionContent(props: AccordionContentProps) { | |
| <div | ||
| className={twMerge(theme.base, className)} | ||
| data-testid="flowbite-accordion-content" | ||
| hidden={!isOpen} | ||
| style={{ | ||
| overflow: "hidden", | ||
| maxHeight: isOpen ? "1000px" : "0", | ||
| transition: "max-height 0.3s ease-in-out", | ||
| }} | ||
| {...restProps} | ||
|
Comment on lines
+35
to
40
Contributor
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. Preserve hidden semantics for collapsed panels. Replacing Proposed fix-import type { ComponentProps } from "react";
+import { useEffect, useState, type ComponentProps } from "react";
@@
export function AccordionContent(props: AccordionContentProps) {
const { isOpen } = useAccordionContext();
+ const [isHidden, setIsHidden] = useState(!isOpen);
+
+ useEffect(() => {
+ if (isOpen) setIsHidden(false);
+ }, [isOpen]);
@@
<div
className={twMerge(theme.base, className)}
data-testid="flowbite-accordion-content"
+ hidden={isHidden}
+ aria-hidden={!isOpen}
+ onTransitionEnd={() => {
+ if (!isOpen) setIsHidden(true);
+ }}
style={{
overflow: "hidden",
maxHeight: isOpen ? "1000px" : "0",
transition: "max-height 0.3s ease-in-out",
}}
{...restProps}
/>🤖 Prompt for AI Agents |
||
| /> | ||
| ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid hard-coded
maxHeight: 1000px; it can truncate content.If panel content exceeds 1000px, the open state is clipped. Measure and animate to
scrollHeightinstead of a fixed cap.Proposed fix
🤖 Prompt for AI Agents