@@ -80,19 +80,20 @@ import {
8080 type ComponentPublicInstance ,
8181 computed ,
8282 type CSSProperties ,
83+ type MaybeRef ,
8384 nextTick ,
8485 onBeforeUnmount ,
8586 onMounted ,
8687 readonly ,
8788 ref ,
8889 toRef ,
90+ unref ,
8991 type VNode ,
9092 watch ,
9193 watchEffect ,
9294} from ' vue'
9395import {useBooleanish , useId } from ' ../composables'
9496import type {Booleanish , BPopoverPlacement , ClassValue , ColorVariant } from ' ../types'
95-
9697defineOptions ({
9798 inheritAttrs: false ,
9899})
@@ -101,20 +102,12 @@ const props = withDefaults(
101102 defineProps <{
102103 modelValue? : Booleanish
103104 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+ >
118111 content? : string
119112 id? : string
120113 title? : string
@@ -231,39 +224,6 @@ const arrow = ref<HTMLElement | null>(null)
231224const trigger = ref <HTMLElement | null >(null )
232225const placeholder = ref <HTMLElement | null >(null )
233226
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-
267227const sanitizedTitle = computed (() =>
268228 props .title ? sanitizeHtml (props .title , DefaultAllowlist ) : ' '
269229)
@@ -434,9 +394,12 @@ const hideFn = (e: Event) => {
434394 emit (' hidden' , buildTriggerableEvent (' hidden' ))
435395 })
436396 } else {
437- setTimeout (() => {
438- hideFn (e )
439- }, delay < 50 ? 50 : delay )
397+ setTimeout (
398+ () => {
399+ hideFn (e )
400+ },
401+ delay < 50 ? 50 : delay
402+ )
440403 }
441404 }, delay )
442405}
@@ -447,11 +410,28 @@ defineExpose({
447410 toggle ,
448411})
449412
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+
450430const bind = () => {
451431 // TODO: is this the best way to bind the events?
452432 // we place a span and get the next element sibling fo rthe listeners
453433 if (props .target ) {
454- const elem = getElement (cleanElementProp ( props .target ) )
434+ const elem = getElement (props .target )
455435 if (elem ) {
456436 trigger .value = elem
457437 } else {
@@ -462,7 +442,7 @@ const bind = () => {
462442 trigger .value = placeholder .value ?.nextElementSibling as HTMLElement
463443 }
464444 if (props .reference ) {
465- const elem = getElement (cleanElementProp ( props .reference ) )
445+ const elem = getElement (props .reference )
466446 if (elem ) {
467447 targetTrigger .value = elem
468448 } else {
@@ -503,8 +483,10 @@ onClickOutside(
503483)
504484
505485watch ([() => props .click , () => props .target , () => props .reference ], () => {
486+ console .log (' change' )
506487 unbind ()
507488 bind ()
489+ // update()
508490})
509491
510492onMounted (bind )
0 commit comments