New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ignore
param in OnClickOutside
component doesn't work
#2398
Comments
ignore
params in OnClickOutside
component doesn't workignore
param in OnClickOutside
component doesn't work
It doesn't work because OnClickOutside component still lacks the options that It wouldn't work anyway even if you write it with <template>
<button ref="buttonElement" @click="isBarked = !isBarked">Woof!</button>
<div ref="modalElement">
<div v-if="isBarked">Bark</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
import { onClickOutside } from '@vueuse/core';
const modalElement = ref(null);
const buttonElement = ref(null);
const isBarked = ref(false);
onClickOutside(
modalElement,
(event) => {
isBarked.value = false
},
{ignore:[buttonElement]}
)
</script> If you want to ignore clicks on that button why don't you use your click handler like that: <template>
<button ref="buttonElement" @click="isBarked = !isBarked">Woof!</button>
<div ref="modalElement">
<div v-if="isBarked">Bark</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
import { onClickOutside } from '@vueuse/core';
const modalElement = ref(null);
const buttonElement = ref(null);
const isBarked = ref(false);
onClickOutside(
modalElement,
(event) => {
if(isBarked.value && event.target === buttonElement.value) {
event.stopPropagation() // prevent running @click
return // prevent setting isBarked.value = false
}
isBarked.value = false
},
//{ignore:[buttonElement]}
)
</script>
|
@sibbng It will not work for I've already handled that case by writing a custom check inside the component. The question is more about the reason to have the buggy |
Those changes are added in 9.3 and if you try it with 9.2 it still won't work. The purpose of |
It was actually a bug related to the inability to pass composable options to the component and was fixed here and released in |
Describe the bug
It's probably related to this change. Ignoring logic has been moved outside of the listener.
Reproduction
https://stackblitz.com/edit/vitejs-vite-x4kfzn/?file=src%2FApp.vue
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: