@homebound/beam 2.210.0 → 2.210.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.
@@ -15,7 +15,8 @@ function Accordion(props) {
15
15
  const [expanded, setExpanded] = (0, react_1.useState)(defaultExpanded && !disabled);
16
16
  const { isFocusVisible, focusProps } = (0, react_aria_1.useFocusRing)();
17
17
  const contentRef = (0, react_1.useRef)(null);
18
- const [contentHeight, setContentHeight] = (0, react_1.useState)(0);
18
+ // On initial render, if the accordion is expanded, then set `height` to auto to avoid unnecessary animation on render.
19
+ const [contentHeight, setContentHeight] = (0, react_1.useState)(expanded ? "auto" : "0");
19
20
  (0, react_1.useEffect)(() => {
20
21
  setExpanded(defaultExpanded && !disabled);
21
22
  }, [defaultExpanded, disabled]);
@@ -23,7 +24,7 @@ function Accordion(props) {
23
24
  // When the `expanded` value changes - If true, it means the Accordion's content has been rendered, Otherwise, it's been hidden
24
25
  // Then when the content is displayed, the calculate its height so we can give this value to the container to animate height smoothly.
25
26
  // When content is removed, simply set the height back to 0
26
- setContentHeight(expanded && contentRef.current ? contentRef.current.scrollHeight : 0);
27
+ setContentHeight(expanded && contentRef.current ? `${contentRef.current.scrollHeight}px` : "0");
27
28
  }, [expanded]);
28
29
  return ((0, jsx_runtime_1.jsxs)("div", Object.assign({}, testIds.container, { css: {
29
30
  ...Css_1.Css.bGray300.if(topBorder).bt.if(bottomBorder).bb.$,
@@ -39,7 +40,7 @@ function Accordion(props) {
39
40
  } }, { children: [(0, jsx_runtime_1.jsx)("span", { children: title }, void 0), (0, jsx_runtime_1.jsx)("span", Object.assign({ css: {
40
41
  transition: "transform 250ms linear",
41
42
  transform: expanded ? "rotate(180deg)" : "rotate(0deg)",
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));
43
+ } }, { 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.h(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));
43
44
  }
44
45
  exports.Accordion = Accordion;
45
46
  const accordionSizes = {
@@ -8,7 +8,7 @@ const __1 = require("..");
8
8
  const Accordion_1 = require("./Accordion");
9
9
  function AccordionList(props) {
10
10
  const { accordions, size, allowMultipleExpanded = true } = props;
11
- const [expandedIndex, setExpandedIndex] = (0, react_2.useState)();
11
+ const [expandedIndex, setExpandedIndex] = (0, react_2.useState)(accordions.findIndex((a) => a.defaultExpanded));
12
12
  const tid = (0, __1.useTestIds)(props, "accordionList");
13
13
  return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: accordions.map((accordionProps, index, arr) => ((0, react_1.createElement)(Accordion_1.Accordion, { ...accordionProps, ...tid, key: index, size: size, bottomBorder: index === arr.length - 1, defaultExpanded: !allowMultipleExpanded && expandedIndex === index, index: index, setExpandedIndex: setExpandedIndex }))) }, void 0));
14
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.210.0",
3
+ "version": "2.210.1",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",