@@ -80,19 +80,20 @@ import {
80
80
type ComponentPublicInstance ,
81
81
computed ,
82
82
type CSSProperties ,
83
+ type MaybeRef ,
83
84
nextTick ,
84
85
onBeforeUnmount ,
85
86
onMounted ,
86
87
readonly ,
87
88
ref ,
88
89
toRef ,
90
+ unref ,
89
91
type VNode ,
90
92
watch ,
91
93
watchEffect ,
92
94
} from ' vue'
93
95
import {useBooleanish , useId } from ' ../composables'
94
96
import type {Booleanish , BPopoverPlacement , ClassValue , ColorVariant } from ' ../types'
95
-
96
97
defineOptions ({
97
98
inheritAttrs: false ,
98
99
})
@@ -101,20 +102,12 @@ const props = withDefaults(
101
102
defineProps <{
102
103
modelValue? : Booleanish
103
104
container? : string | ComponentPublicInstance <HTMLElement > | HTMLElement | undefined
104
- target? :
105
- | (() => HTMLElement | VNode )
106
- | string
107
- | ComponentPublicInstance <HTMLElement >
108
- | HTMLSpanElement
109
- | HTMLElement
110
- | null
111
- reference ?:
112
- | (() => HTMLElement | VNode )
113
- | string
114
- | ComponentPublicInstance <HTMLElement >
115
- | HTMLSpanElement
116
- | HTMLElement
117
- | null
105
+ target? : MaybeRef <
106
+ string | ComponentPublicInstance <HTMLElement > | HTMLSpanElement | HTMLElement | null
107
+ >
108
+ reference? : MaybeRef <
109
+ string | ComponentPublicInstance <HTMLElement > | HTMLSpanElement | HTMLElement | null
110
+ >
118
111
content? : string
119
112
id? : string
120
113
title? : string
@@ -231,39 +224,6 @@ const arrow = ref<HTMLElement | null>(null)
231
224
const trigger = ref <HTMLElement | null >(null )
232
225
const placeholder = ref <HTMLElement | null >(null )
233
226
234
- const cleanElementProp = (
235
- target :
236
- | (() => HTMLElement | VNode )
237
- | string
238
- | ComponentPublicInstance <HTMLElement >
239
- | HTMLElement
240
- | undefined
241
- ): HTMLElement | string | undefined => {
242
- if (typeof target === ' string' ) {
243
- return target
244
- }
245
- if (target instanceof HTMLElement ) {
246
- return target
247
- // eslint-disable-next-line
248
- }
249
- if (typeof target === ' function' )
250
- return (target () as ComponentPublicInstance <HTMLElement >).$el
251
- ? (target () as ComponentPublicInstance <HTMLElement >).$el
252
- : target ()
253
- if (typeof target !== ' undefined' )
254
- return (target as ComponentPublicInstance <HTMLElement >).$el as HTMLElement
255
- return undefined
256
- }
257
-
258
- const getElement = (element : HTMLElement | string | undefined ): HTMLElement | undefined => {
259
- if (! element ) return undefined
260
- if (typeof element === ' string' ) {
261
- const idElement = document .getElementById (element )
262
- return idElement ? idElement : undefined
263
- }
264
- return element
265
- }
266
-
267
227
const sanitizedTitle = computed (() =>
268
228
props .title ? sanitizeHtml (props .title , DefaultAllowlist ) : ' '
269
229
)
@@ -434,9 +394,12 @@ const hideFn = (e: Event) => {
434
394
emit (' hidden' , buildTriggerableEvent (' hidden' ))
435
395
})
436
396
} else {
437
- setTimeout (() => {
438
- hideFn (e )
439
- }, delay < 50 ? 50 : delay )
397
+ setTimeout (
398
+ () => {
399
+ hideFn (e )
400
+ },
401
+ delay < 50 ? 50 : delay
402
+ )
440
403
}
441
404
}, delay )
442
405
}
@@ -447,11 +410,28 @@ defineExpose({
447
410
toggle ,
448
411
})
449
412
413
+ const getElement = (
414
+ target : MaybeRef <
415
+ string | ComponentPublicInstance <HTMLElement > | HTMLSpanElement | HTMLElement | null
416
+ >
417
+ ): HTMLElement | undefined => {
418
+ const element = unref (target )
419
+ if (! element ) return undefined
420
+ if (typeof element === ' string' ) {
421
+ const idElement = document .getElementById (element )
422
+ return idElement ? idElement : undefined
423
+ }
424
+ if ((element as ComponentPublicInstance <HTMLElement >).$el ) {
425
+ return (element as ComponentPublicInstance <HTMLElement >).$el as HTMLElement
426
+ }
427
+ return element
428
+ }
429
+
450
430
const bind = () => {
451
431
// TODO: is this the best way to bind the events?
452
432
// we place a span and get the next element sibling fo rthe listeners
453
433
if (props .target ) {
454
- const elem = getElement (cleanElementProp ( props .target ) )
434
+ const elem = getElement (props .target )
455
435
if (elem ) {
456
436
trigger .value = elem
457
437
} else {
@@ -462,7 +442,7 @@ const bind = () => {
462
442
trigger .value = placeholder .value ?.nextElementSibling as HTMLElement
463
443
}
464
444
if (props .reference ) {
465
- const elem = getElement (cleanElementProp ( props .reference ) )
445
+ const elem = getElement (props .reference )
466
446
if (elem ) {
467
447
targetTrigger .value = elem
468
448
} else {
@@ -503,8 +483,10 @@ onClickOutside(
503
483
)
504
484
505
485
watch ([() => props .click , () => props .target , () => props .reference ], () => {
486
+ console .log (' change' )
506
487
unbind ()
507
488
bind ()
489
+ // update()
508
490
})
509
491
510
492
onMounted (bind )
0 commit comments