Преглед на файлове

stop event propagation on close text button

axolotle преди 3 години
родител
ревизия
4ed63fe58d
променени са 1 файла, в които са добавени 14 реда и са изтрити 2 реда
  1. 14 2
      src/components/text/TextCard.vue

+ 14 - 2
src/components/text/TextCard.vue

@@ -5,7 +5,7 @@
         <template v-if="children">
           <b-nav-item
             v-for="child in text.children" :key="child.id"
-            @click="$emit('open', text.id, child.id)"
+            @click="onChildOpen($event, text.id, child.id)"
             :active="children.includes(child.id)"
           >
             {{ child.id }}
@@ -13,7 +13,7 @@
         </template>
 
         <b-nav-item>
-          <b-button-close @click="$emit('close', text.id)" />
+          <b-button-close @click="onSelfClose($event, text.id)" />
         </b-nav-item>
       </b-nav>
     </template>
@@ -54,6 +54,18 @@ export default {
 
   props: {
     children: { type: Array, default: null }
+  },
+
+  methods: {
+    onChildOpen (_, id, childId) {
+      this.$emit('open', id, childId)
+    },
+
+    onSelfClose (e, id) {
+      // stop the click event propagation to avoid other listeners to interact with a soon to be deleted element.
+      e.stopPropagation()
+      this.$emit('close', id)
+    }
   }
 }
 </script>