1313 :aria-controls =" 'content-' + id"
1414 >
1515 {{ header }}
16- <svg
17- aria-hidden =" true"
18- focusable =" false"
19- class =" icon"
20- >
21- <use
22- v-if =" collapsed"
23- xlink:href =" #icon-chevron-down"
24- ></use >
25- <use
26- v-else
27- xlink:href =" #icon-chevron-up"
28- ></use >
29- </svg >
16+
17+ <muc-icon
18+ v-if =" collapsed"
19+ icon =" chevron-down"
20+ />
21+ <muc-icon
22+ v-else
23+ icon =" chevron-up"
24+ />
3025 </button >
3126 </h3 >
3227 <section
5247<script setup lang="ts">
5348import { onBeforeUnmount , onMounted , ref , watch } from " vue" ;
5449
50+ import { MucIcon } from " ../Icon" ;
51+
5552const { id, activeItems = [] } = defineProps <{
5653 /**
5754 * Id of accordion item.
@@ -107,7 +104,8 @@ watch(
107104 () => {
108105 if (! activeItems .includes (id ) && ! collapsed .value && section .value ) {
109106 collapsed .value = true ;
110- section .value .style .height = section .value .scrollHeight + " px" ;
107+ section .value .style .height =
108+ section .value .scrollHeight + calculateMargin () + " px" ;
111109 collapsing .value = true ;
112110 setTimeout (() => {
113111 if (section .value ) {
@@ -125,7 +123,8 @@ const toggleCollapsable = () => {
125123 if (section .value ) {
126124 collapsed .value = ! collapsed .value ;
127125 if (collapsed .value ) {
128- section .value .style .height = section .value .scrollHeight + " px" ;
126+ section .value .style .height =
127+ section .value .scrollHeight + calculateMargin () + " px" ;
129128 collapsing .value = true ;
130129 emit (" close" , id );
131130 setTimeout (() => {
@@ -146,6 +145,19 @@ const toggleCollapsable = () => {
146145 }
147146};
148147
148+ /**
149+ * Calculation of the margin of 1.5em to improve the animation
150+ */
151+ const calculateMargin = () => {
152+ if (section .value ) {
153+ const computedStyle = window .getComputedStyle (section .value );
154+ const fontSize = parseFloat (computedStyle .fontSize );
155+ return 1.5 * fontSize ;
156+ } else {
157+ return 0 ;
158+ }
159+ };
160+
149161/**
150162 * Handles the end of the collapsing transition.
151163 */
0 commit comments