1
1
import { autoUpdate , computePosition , flip , offset , shift } from '@floating-ui/dom'
2
2
import { onClickOutside } from '@vueuse/core'
3
3
import type { PropType } from 'vue'
4
- import { Teleport , computed , defineComponent , onBeforeUnmount , onMounted , ref , watch } from 'vue'
4
+ import { Teleport , computed , defineComponent , onBeforeUnmount , onMounted , ref } from 'vue'
5
5
import { isObject } from '@/utils/helpers'
6
6
import { ABaseInput , useBaseInputProp } from '@/components/base-input'
7
7
@@ -103,15 +103,6 @@ export const ASelect = defineComponent({
103
103
)
104
104
105
105
// !SECTION
106
-
107
- // 👉 watch: modelValue
108
- watch (
109
- ( ) => props . modelValue ,
110
- ( ) => {
111
- isOptionsVisible . value = false
112
- } ,
113
- )
114
-
115
106
// TODO: You can use it as utility in another components
116
107
// TODO: Add some style to indicate currently selected item
117
108
const handleInputClick = ( ) => {
@@ -128,6 +119,10 @@ export const ASelect = defineComponent({
128
119
emit ( 'input' , value )
129
120
emit ( 'update:modelValue' , value )
130
121
}
122
+ const closeOptions = ( event : MouseEvent ) => {
123
+ if ( event . target !== refFloating . value )
124
+ isOptionsVisible . value = false
125
+ }
131
126
132
127
// 👉 Value
133
128
const selectedValue = computed ( ( ) => {
@@ -157,6 +152,7 @@ export const ASelect = defineComponent({
157
152
</ ABaseInput >
158
153
< Teleport to = "body" >
159
154
< ul
155
+ onClick = { closeOptions }
160
156
v-show = { isOptionsVisible . value }
161
157
ref = { refFloating }
162
158
class = { [ 'a-select-options-container absolute bg-[hsl(var(--a-layer))]' , props . optionsWrapperClasses ] } >
0 commit comments