Skip to content

Commit 2fa828d

Browse files
committed
👌 review feedback
1 parent 673847b commit 2fa828d

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

src/components/Accordion/MucAccordion.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
<div class="container">
44
<div class="m-component__grid">
55
<div class="m-component__column">
6-
<div class="m-component__head">
6+
<div
7+
v-if="header"
8+
class="m-component__head"
9+
>
710
<h2 class="m-component__heading">{{ header }}</h2>
811
<p class="m-component__summary"></p>
912
</div>
@@ -41,7 +44,7 @@ const {
4144
/**
4245
* Heading of accordion
4346
*/
44-
header: string;
47+
header?: string;
4548
/**
4649
* Multiple MucAccordionItems can be active at the same time
4750
*/

src/components/Accordion/MucAccordionItem.vue

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,15 @@
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
@@ -52,6 +47,8 @@
5247
<script setup lang="ts">
5348
import { onBeforeUnmount, onMounted, ref, watch } from "vue";
5449
50+
import { MucIcon } from "../Icon";
51+
5552
const { 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

Comments
 (0)