Skip to content

Selected node style #32

Answered by bcakmakoglu
Dimonka2 asked this question in Q&A
Discussion options

You must be logged in to vote

You can pass classes (or styles) to nodes as a property/option.

const elements = ref<Elements>([
  { id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 }, class: 'some-class', style: { color: 'red' } },
])

You can change the styles whenever you want (if you want to keep reactivity on your initial elements, don't map over them but use a forEach loop to change properties)

<script setup lang="ts">
const elements = ref([...])
const toggleClasses = () => {
   elements.value.forEach(el => {
     if (el.selected) el.class = 'some-selected-class'
  }
}
</script>
<template>
  <VueFlow v-model="elements">
    <button @click="toggleClasses">Toggle classes</button>
  </VueFlow>
</template

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by bcakmakoglu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants