Skip to content

Commit 4bdee89

Browse files
committed
fix(app-headless-cms): toggle overflow when accordion is expanded
(cherry picked from commit 18b604e)
1 parent a807d10 commit 4bdee89

File tree

1 file changed

+29
-17
lines changed
  • packages/app-headless-cms/src/admin/plugins/fieldRenderers

1 file changed

+29
-17
lines changed

packages/app-headless-cms/src/admin/plugins/fieldRenderers/Accordion.tsx

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { ReactElement, useCallback, useState } from "react";
22
import { css } from "emotion";
3+
import styled from "@emotion/styled";
34
import classNames from "classnames";
45
import { Typography } from "@webiny/ui/Typography";
56

@@ -69,23 +70,34 @@ const classes = {
6970
transform: "translateY(3px) rotate(90deg)"
7071
}
7172
}
72-
}),
73-
accordionItem: css({
74-
overflow: "hidden",
75-
transition: "max-height 0.3s cubic-bezier(1, 0, 1, 0)",
76-
height: "auto",
77-
maxHeight: "9999px",
78-
79-
"&.collapsed": {
80-
maxHeight: 0,
81-
transition: "max-height 0.35s cubic-bezier(0, 1, 0, 1)"
82-
},
83-
".accordion-content": {
84-
paddingBottom: 10
85-
}
8673
})
8774
};
8875

76+
const AccordionItem = styled.div`
77+
@keyframes show-overflow {
78+
to {
79+
overflow: visible;
80+
}
81+
}
82+
overflow: hidden;
83+
transition: max-height 0.35s cubic-bezier(0, 1, 0, 1);
84+
height: auto;
85+
max-height: 0;
86+
87+
&.expanded {
88+
max-height: 9999px;
89+
transition: max-height 0.3s cubic-bezier(1, 0, 1, 0);
90+
animation-name: show-overflow;
91+
animation-fill-mode: forwards;
92+
animation-duration: 20ms;
93+
animation-delay: 0.3s;
94+
}
95+
`;
96+
97+
const AccordionContent = styled.div`
98+
padding-bottom: 10;
99+
`;
100+
89101
interface AccordionProps {
90102
title: string;
91103
action?: ReactElement | null;
@@ -116,9 +128,9 @@ const Accordion = ({ title, children, action, icon, defaultValue = false }: Acco
116128
<div className={"icon-container"}>{icon}</div>
117129
</div>
118130
</div>
119-
<div className={classNames(classes.accordionItem, { collapsed: !isOpen })}>
120-
<div className="accordion-content">{children}</div>
121-
</div>
131+
<AccordionItem className={classNames({ expanded: isOpen })}>
132+
<AccordionContent>{children}</AccordionContent>
133+
</AccordionItem>
122134
</div>
123135
);
124136
};

0 commit comments

Comments
 (0)