|
1 | 1 | import type { ComputedRef, HTMLAttributes, Ref } from 'vue';
|
2 |
| -import { onBeforeUnmount, watchEffect, watch, ref, computed } from 'vue'; |
| 2 | +import { onBeforeUnmount, onMounted, watch, ref, computed } from 'vue'; |
3 | 3 | import type { FocusEventHandler } from '../../_util/EventInterface';
|
4 | 4 | import KeyCode from '../../_util/KeyCode';
|
5 | 5 | import { addGlobalMousedownEvent, getTargetFromEvent } from '../utils/uiUtil';
|
@@ -148,30 +148,26 @@ export default function usePickerInput({
|
148 | 148 | });
|
149 | 149 | const globalMousedownEvent = ref();
|
150 | 150 | // Global click handler
|
151 |
| - watchEffect( |
152 |
| - () => |
153 |
| - globalMousedownEvent.value && |
154 |
| - globalMousedownEvent.value()( |
155 |
| - (globalMousedownEvent.value = addGlobalMousedownEvent((e: MouseEvent) => { |
156 |
| - const target = getTargetFromEvent(e); |
157 |
| - |
158 |
| - if (open) { |
159 |
| - const clickedOutside = isClickOutside(target); |
160 |
| - |
161 |
| - if (!clickedOutside) { |
162 |
| - preventBlurRef.value = true; |
163 |
| - |
164 |
| - // Always set back in case `onBlur` prevented by user |
165 |
| - raf(() => { |
166 |
| - preventBlurRef.value = false; |
167 |
| - }); |
168 |
| - } else if (!focused.value || clickedOutside) { |
169 |
| - triggerOpen(false); |
170 |
| - } |
171 |
| - } |
172 |
| - })), |
173 |
| - ), |
174 |
| - ); |
| 151 | + onMounted(() => { |
| 152 | + globalMousedownEvent.value = addGlobalMousedownEvent((e: MouseEvent) => { |
| 153 | + const target = getTargetFromEvent(e); |
| 154 | + |
| 155 | + if (open.value) { |
| 156 | + const clickedOutside = isClickOutside(target); |
| 157 | + |
| 158 | + if (!clickedOutside) { |
| 159 | + preventBlurRef.value = true; |
| 160 | + |
| 161 | + // Always set back in case `onBlur` prevented by user |
| 162 | + raf(() => { |
| 163 | + preventBlurRef.value = false; |
| 164 | + }); |
| 165 | + } else if (!focused.value || clickedOutside) { |
| 166 | + triggerOpen(false); |
| 167 | + } |
| 168 | + } |
| 169 | + }); |
| 170 | + }); |
175 | 171 | onBeforeUnmount(() => {
|
176 | 172 | globalMousedownEvent.value && globalMousedownEvent.value();
|
177 | 173 | });
|
|
0 commit comments