@homebound/beam 2.210.1 → 2.210.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Accordion.js +10 -0
- package/package.json +1 -1
|
@@ -26,6 +26,16 @@ function Accordion(props) {
|
|
|
26
26
|
// When content is removed, simply set the height back to 0
|
|
27
27
|
setContentHeight(expanded && contentRef.current ? `${contentRef.current.scrollHeight}px` : "0");
|
|
28
28
|
}, [expanded]);
|
|
29
|
+
// Using a resizing observer to check if the content of the accordion changes (i.e. lazy loaded image, auto-sizing textarea, etc..),
|
|
30
|
+
// If it does change, then we need to update the container's height accordingly. Only update the height if the accordion is expanded.
|
|
31
|
+
// Note - This may result in two `setContentHeight` calls when the accordion opens: (1) via the above `useEffect` and (2) in `onResize`
|
|
32
|
+
// Both `setContentHeight` calls _should_ set the same value, so no unnecessary re-renders would be triggered, making this a harmless additional set call.
|
|
33
|
+
const onResize = (0, react_1.useCallback)(() => {
|
|
34
|
+
if (contentRef.current && expanded) {
|
|
35
|
+
setContentHeight(`${contentRef.current.scrollHeight}px`);
|
|
36
|
+
}
|
|
37
|
+
}, [expanded, setContentHeight]);
|
|
38
|
+
(0, utils_1.useResizeObserver)({ ref: contentRef, onResize });
|
|
29
39
|
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({}, testIds.container, { css: {
|
|
30
40
|
...Css_1.Css.bGray300.if(topBorder).bt.if(bottomBorder).bb.$,
|
|
31
41
|
...(size ? Css_1.Css.wPx(accordionSizes[size]).$ : {}),
|