Replies: 3 comments 5 replies
-
I believe this is something you would have to deal with yourself in this specific case. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hey! Find a solution for this? @aslauris |
Beta Was this translation helpful? Give feedback.
4 replies
-
Haven't got a solution yet? Here is a workaround for you. The CSS variable --radix-accordion-content-height doesn't get updated when the elements inside AccordionContent changes. import * as Accordion from '@radix-ui/react-accordion';
export const Content = ({ children}: { children: ReactNode }) => {
const ref = useRef(null);
const contentRef = useRef(null);
// Radix Accordion doesnt update height when children updates.
// We need to manualy add a resize observer on children of the Content component
// to update the CSS variable height of the content.
useEffect(() => {
const content = contentRef.current;
if (!ref.current || !content) return;
const resizeObserver = new ResizeObserver(() => {
const currentHeight = ref.current.clientHeight;
content.style.cssText = `--radix-accordion-content-height: ${currentHeight}px;`;
});
resizeObserver.observe(ref.current);
return () => resizeObserver.disconnect(); // clean up
}, []);
return (
<Accordion.Content ref={contentRef}>
<div ref={ref}>{children}</div>
</Accordion.Content>
);
}; |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've got a dynamic form inside
<Accordion.Content />
where new rows/items could be added. However,<Accordion.Content />
height is not updated after new DOM elements are added resulting in new rows being invisible. Is there any way to force accordion content height re-calculation or any other workaround to this? Many thanks!Beta Was this translation helpful? Give feedback.
All reactions