Chip workflow issue on remove #728
Replies: 4 comments 1 reply
-
Could you share a stackblitz demo so we can easily replicate the problem? |
Beta Was this translation helpful? Give feedback.
-
@MarkVasile did you solve this? I'm having the same issue. |
Beta Was this translation helpful? Give feedback.
-
This problem is still active @MarkVasile did you solved this, I ended up creating my own component |
Beta Was this translation helpful? Give feedback.
-
Hello! I tried to replicate the issue, but didn't find any error. Could you please provide a minimal reproduction? <template>
<div class="card flex flex-wrap gap-12">
<div class="flex flex-col">
<p>Selected tags</p>
<div class="flex flex-col">
<Chip
v-for="tag in selectedTags"
:label="tag"
:key="tag"
removable
@remove="removeTag(tag)"
/>
</div>
</div>
<div class="flex flex-col">
<p>All tags</p>
<div class="flex flex-col">
<Chip
v-for="tag in tags"
:key="tag"
:label="tag"
@click="selectTag(tag)"
/>
</div>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
const tags = ref(['beer', 'coffee', 'water']);
const selectedTags = ref([]);
function selectTag(tag) {
const index = tags.value.indexOf(tag);
if (index !== -1) {
tags.value.splice(index, 1);
selectedTags.value.push(tag);
}
}
function removeTag(tag) {
const index = selectedTags.value.indexOf(tag);
if (index !== -1) {
selectedTags.value.splice(index, 1);
}
console.log(`Tag removed ${tag}. Model updated: `, selectedTags.value);
}
</script>
<style>
.p-chip {
cursor: pointer;
}
</style> |
Beta Was this translation helpful? Give feedback.
-
When assembling chips using the
chip
component, not thechips
aggregate, I ran into trouble trying to sync up the model upon removal of a chip.With the above, I tried to update the
selectedTags
upon removal, but even though the selectedTags containsthe right elements (verified with console.log), I see 2 chips removed instead of 1.
I've also tried leaving the
selectedTags
alone, hoping the library will update the model, but it doesn't, i.e. theselectedTags
stays intact after a chip removal.Is there a different (correct) way to use the chip component I'm not aware of?
Beta Was this translation helpful? Give feedback.
All reactions