Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/ui/src/components/Accordion/AccordionContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Comment on lines +37 to +38
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid hard-coded maxHeight: 1000px; it can truncate content.

If panel content exceeds 1000px, the open state is clipped. Measure and animate to scrollHeight instead of a fixed cap.

Proposed fix
-import type { ComponentProps } from "react";
+import { useLayoutEffect, useRef, useState, type ComponentProps } from "react";
@@
 export function AccordionContent(props: AccordionContentProps) {
   const { isOpen } = useAccordionContext();
+  const contentRef = useRef<HTMLDivElement>(null);
+  const [maxHeight, setMaxHeight] = useState("0px");
+
+  useLayoutEffect(() => {
+    const el = contentRef.current;
+    if (!el) return;
+    setMaxHeight(isOpen ? `${el.scrollHeight}px` : "0px");
+  }, [isOpen, props.children]);
@@
     <div
+      ref={contentRef}
       className={twMerge(theme.base, className)}
       data-testid="flowbite-accordion-content"
       style={{
         overflow: "hidden",
-        maxHeight: isOpen ? "1000px" : "0",
+        maxHeight,
         transition: "max-height 0.3s ease-in-out",
       }}
       {...restProps}
     />
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/ui/src/components/Accordion/AccordionContent.tsx` around lines 37 -
38, The hard-coded maxHeight ("1000px") in AccordionContent causes clipping;
change AccordionContent to measure the panel element's scrollHeight via a ref
(e.g., contentRef) and set its style.maxHeight to isOpen ?
`${contentRef.current.scrollHeight}px` : "0" to animate to the actual content
height, and optionally clear maxHeight to "none" after the transition ends to
allow dynamic content resizing; update any useEffect or event handlers in
AccordionContent that currently toggle maxHeight to use this measured value and
listen for transitionend to reset if needed.

}}
{...restProps}
Comment on lines +35 to 40
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Preserve hidden semantics for collapsed panels.

Replacing hidden with only max-height animation can leave collapsed content reachable by assistive tech/focus until/unless explicitly hidden. Please keep animation and restore hidden semantics after collapse completes.

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
Verify each finding against the current code and only fix it if needed.

In `@packages/ui/src/components/Accordion/AccordionContent.tsx` around lines 35 -
40, AccordionContent currently animates collapse using maxHeight but doesn't set
the hidden semantics, leaving collapsed content reachable by assistive tech;
modify the AccordionContent component to manage a hidden boolean (or use the DOM
hidden attribute) alongside isOpen: when opening, remove hidden before starting
the maxHeight transition; when closing, start the transition then set
hidden=true in an onTransitionEnd handler (use a ref to the container and listen
for its transitionend) so the element is removed from accessibility tree after
the animation completes; update any places using isOpen/restProps and ensure the
element includes aria-hidden or the hidden attribute consistently.

/>
);
Expand Down
Loading