I am trying to close dropdown click in v-select input and clickaway. My code below and I am using vuejs v3 composition api, nuxtjs, vue-select ^4.0.0-beta.6. Can figure out working way.
<li id="delivery_select">
<span class="subtitle">Location</span>
<v-select ref="mySelect" v-model="selectedDelivery" :options="deliveries"
@mousedown="handleClick"
></v-select>
</li>
const handleClick = (event) => {
// Check if the click event originated from the v-select input element or its dropdown
const isClickedWithinDropdown = event.target.closest('.vs__dropdown-menu')
const isClickedOnInput = event.target.closest('.vs__search')
if (!isClickedWithinDropdown && !isClickedOnInput) {
// Close the dropdown if it's open
console.log('clicked!')
if (selectedDelivery.value && selectedDelivery.value.menuIsVisible) {
console.log('clicked!!!')
selectedDelivery.value.closeMenu()
}
}
}
watchEffect(() => {
return () => {
if (selectedDelivery.value && selectedDelivery.value.menuIsVisible) {
selectedDelivery.value.closeMenu()
}
}
})