Reputation: 3086
I'm using Vuetify and I have v-data-table
. When I click on row v-dialog
must open. Also I have v-switch
inside rows in my v-data-table
. My problem comes when I click on the v-switch
it switches, but also propagates and opens my v-dialog
.
In my codepen I have three examples of v-switch click events.
@click.native.stop
. Here I deal with propagation successfully, but click event is not only in the v-switch, but it covers the whole container (colored in red in example) @change
. Here switch event is activated only on v-switch toggle, but when I click on the v-switch the v-dialog opens too. So with @change
it doesn't work properly too.@change.stop
, but without desired result, its same as my second try.My question is - Is there a way to stop the propagation (with no side effects as in my first example) and when I click on v-switch to toggle only the switch , but not and the v-dialog behind?
Upvotes: 5
Views: 6567
Reputation: 3086
My workaround is to use @click.native.stop
to stop propagation and @change
for event
<v-switch
v-model="item.isActive"
@click.native.stop
@change="toggleActive(item)">
</v-switch>
Upvotes: 4
Reputation: 90188
Just add @click.native.stop
to your <v-switch>
.
See it working: https://codepen.io/andrei-gheorghiu/pen/RwWPONL
Note: To limit the area in which the click is captured, you have to change .v-input--switch
s display
value to inline-block
:
.v-input--switch {
display: inline-block;
}
And you don't actually need to stop more than click
, as the dialog only opens on click. As you can see, you can use Tab + Space to toggle the switch and the modal is not opening.
Upvotes: 7