Skip to content

Commit

Permalink
feat(OnboardingChecklist): resize observer
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinsawicki committed Aug 5, 2024
1 parent d3600f5 commit 777c1d6
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,21 @@ export const CheckListItem: React.FC<ICheckListItem> = ({
const [size, setSize] = React.useState(0);

React.useEffect(() => {
if (
descriptionRef.current &&
size !== descriptionRef.current.offsetHeight
) {
setSize(descriptionRef.current.offsetHeight);
const hasIOSupport = !!window.ResizeObserver;

if (descriptionRef.current && hasIOSupport) {
const resizeObserver = new ResizeObserver(() => {
if (
descriptionRef.current &&
size !== descriptionRef.current.offsetHeight
) {
setSize(descriptionRef.current.offsetHeight);
}
});

resizeObserver.observe(descriptionRef.current);

return () => resizeObserver.disconnect();
}
}, [descriptionRef]);

Expand Down Expand Up @@ -69,7 +79,7 @@ export const CheckListItem: React.FC<ICheckListItem> = ({
className={styles[`${baseClass}__content__inner`]}
style={{ maxHeight: isActive ? size : 0 }}
>
<span ref={descriptionRef}>
<div ref={descriptionRef}>
<Text
size="lg"
className={styles[`${baseClass}__content__inner__description`]}
Expand Down Expand Up @@ -98,7 +108,7 @@ export const CheckListItem: React.FC<ICheckListItem> = ({
</Button>
)}
</div>
</span>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 777c1d6

Please sign in to comment.