N
Nuxt8mo ago
$hins

weird behaviour when expanding component

I have this component
<template>
<div class="category-box" @click="toggleExpand">
<div class="header">
<span class="icon">{{ expanded ? '-' : '+' }}</span>
<span class="title">{{ title }}</span>
</div>
<div v-if="expanded" class="subcategories">
<ul>
<li v-for="(subcategory, index) in subcategories" :key="index">{{ subcategory }}</li>
</ul>
</div>
</div>
</template>

<script>
export default {
props: {
title: {
type: String,
required: true
},
subcategories: {
type: Array,
default: () => []
}
},
data() {
return {
expanded: false
};
},
methods: {
toggleExpand() {
this.expanded = !this.expanded;
}
}
};
</script>
<template>
<div class="category-box" @click="toggleExpand">
<div class="header">
<span class="icon">{{ expanded ? '-' : '+' }}</span>
<span class="title">{{ title }}</span>
</div>
<div v-if="expanded" class="subcategories">
<ul>
<li v-for="(subcategory, index) in subcategories" :key="index">{{ subcategory }}</li>
</ul>
</div>
</div>
</template>

<script>
export default {
props: {
title: {
type: String,
required: true
},
subcategories: {
type: Array,
default: () => []
}
},
data() {
return {
expanded: false
};
},
methods: {
toggleExpand() {
this.expanded = !this.expanded;
}
}
};
</script>
Used like this:
<template>
<div class="category-container">
<GeneralCategory
v-for="(category, index) in categories"
:key="index"
:title="category.title"
:subcategories="category.subcategories"
/>
</div>
</template>
<style lang="scss">
.category-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
</style>
<template>
<div class="category-container">
<GeneralCategory
v-for="(category, index) in categories"
:key="index"
:title="category.title"
:subcategories="category.subcategories"
/>
</div>
</template>
<style lang="scss">
.category-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
</style>
e.g. how it looks:
No description
4 Replies
$hins
$hinsOP8mo ago
The problem is, when I expand one, it does this ->
No description
$hins
$hinsOP8mo ago
e.g. it 'expands' everything in the same row..
FoxForGate
FoxForGate8mo ago
your problem is with css, I don't know exactly how to fix this, probably manipulating the display can fix this
$hins
$hinsOP8mo ago
yeah most likely, any ideas how lol
Want results from more Discord servers?
Add your server