<template>
- <div :class="{ 'active': showDropdown, 'share-select': true }">
+ <div :class="{ 'active': showDropdown, 'share-select': true }" ref="quickShareDropdown">
<span class="trigger-text" @click="toggleDropdown">
{{ selectedOption }}
<DropdownIcon :size="15" />
},
mounted() {
this.initializeComponent()
+ window.addEventListener('click', this.handleClickOutside);
},
+ beforeDestroy() {
+ // Remove the global click event listener to prevent memory leaks
+ window.removeEventListener('click', this.handleClickOutside);
+ },
methods: {
toggleDropdown() {
this.showDropdown = !this.showDropdown
initializeComponent() {
this.selectedOption = this.preSelectedOption
},
+ handleClickOutside(event) {
+ const dropdownElement = this.$refs.quickShareDropdown;
+
+ if (dropdownElement && !dropdownElement.contains(event.target)) {
+ this.showDropdown = false;
+ }
+ },
},
}