@homebound/beam 2.208.0 → 2.208.1

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.
@@ -12,11 +12,19 @@ function Accordion(props) {
12
12
  const { title, children, size, disabled = false, defaultExpanded = false, topBorder = true, bottomBorder = false, index, setExpandedIndex, } = props;
13
13
  const testIds = (0, utils_2.useTestIds)(props, "accordion");
14
14
  const id = (0, utils_1.useId)();
15
- const [expanded, setExpanded] = (0, react_1.useState)(defaultExpanded);
15
+ const [expanded, setExpanded] = (0, react_1.useState)(defaultExpanded && !disabled);
16
16
  const { isFocusVisible, focusProps } = (0, react_aria_1.useFocusRing)();
17
+ const contentRef = (0, react_1.useRef)(null);
18
+ const [contentHeight, setContentHeight] = (0, react_1.useState)(0);
17
19
  (0, react_1.useEffect)(() => {
18
- setExpanded(defaultExpanded);
19
- }, [defaultExpanded]);
20
+ setExpanded(defaultExpanded && !disabled);
21
+ }, [defaultExpanded, disabled]);
22
+ (0, react_1.useEffect)(() => {
23
+ // When the `expanded` value changes - If true, it means the Accordion's content has been rendered, Otherwise, it's been hidden
24
+ // Then when the content is displayed, the calculate its height so we can give this value to the container to animate height smoothly.
25
+ // When content is removed, simply set the height back to 0
26
+ setContentHeight(expanded && contentRef.current ? contentRef.current.scrollHeight : 0);
27
+ }, [expanded]);
20
28
  return ((0, jsx_runtime_1.jsxs)("div", Object.assign({}, testIds.container, { css: {
21
29
  ...Css_1.Css.bGray300.if(topBorder).bt.if(bottomBorder).bb.$,
22
30
  ...(size ? Css_1.Css.wPx(accordionSizes[size]).$ : {}),
@@ -31,13 +39,7 @@ function Accordion(props) {
31
39
  } }, { children: [(0, jsx_runtime_1.jsx)("span", { children: title }, void 0), (0, jsx_runtime_1.jsx)("span", Object.assign({ css: {
32
40
  transition: "transform 250ms linear",
33
41
  transform: expanded ? "rotate(180deg)" : "rotate(0deg)",
34
- } }, { children: (0, jsx_runtime_1.jsx)(Icon_1.Icon, { icon: "chevronDown" }, void 0) }), void 0)] }), void 0), (0, jsx_runtime_1.jsx)("div", Object.assign({}, testIds.details, { id: id, "aria-hidden": !expanded, css: {
35
- // Use max-height for grow/shrink animation (remove close animation for AccordionList to avoid delays)
36
- ...Css_1.Css.overflowHidden
37
- .maxhPx(1000)
38
- .add("transition", `max-height ${expanded || !index ? "250ms" : "0"} ease-in-out`).$,
39
- ...(!expanded || disabled ? Css_1.Css.maxh0.$ : {}),
40
- } }, { children: (0, jsx_runtime_1.jsx)("div", Object.assign({ css: Css_1.Css.px2.pb2.pt1.$ }, { children: children }), void 0) }), void 0)] }), void 0));
42
+ } }, { children: (0, jsx_runtime_1.jsx)(Icon_1.Icon, { icon: "chevronDown" }, void 0) }), void 0)] }), void 0), (0, jsx_runtime_1.jsx)("div", Object.assign({}, testIds.details, { id: id, "aria-hidden": !expanded, css: Css_1.Css.overflowHidden.hPx(contentHeight).add("transition", "height 250ms ease-in-out").$ }, { children: expanded && ((0, jsx_runtime_1.jsx)("div", Object.assign({ css: Css_1.Css.px2.pb2.pt1.$, ref: contentRef }, testIds.content, { children: children }), void 0)) }), void 0)] }), void 0));
41
43
  }
42
44
  exports.Accordion = Accordion;
43
45
  const accordionSizes = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.208.0",
3
+ "version": "2.208.1",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",