Skip to content

Commit

Permalink
fix unref element
Browse files Browse the repository at this point in the history
  • Loading branch information
KABBOUCHI committed May 4, 2023
1 parent 6f8f32f commit 0951cce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-tippy",
"version": "6.1.1",
"version": "6.1.2",
"main": "index.js",
"module": "dist/vue-tippy.mjs",
"unpkg": "dist/vue-tippy.iife.js",
Expand Down
8 changes: 7 additions & 1 deletion playground/pages/Wga.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<template>
<div>
<tippy content="Choose an aggregation for this area" :tag="null">
<button class="text-sm py-2 px-3 bg-gray-900 text-white rounded-lg">Aggregation #1</button>
<button class="text-sm py-2 px-3 bg-gray-900 text-white rounded-lg">Aggregation #1</button>
</tippy>

<tippy content="View Android device page" :tag="null">
<RouterLink to="/" aria-label="View Android device page">
Link
</RouterLink>
</tippy>
</div>
</template>
Expand Down
11 changes: 10 additions & 1 deletion src/components/Tippy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ declare module '@vue/runtime-core' {
interface ComponentCustomProperties extends UnwrapNestedRefs<ReturnType<typeof useTippy>> { }
}

function toValue(r: any): any {
return typeof r === 'function'
? (r as any)()
: unref(r)
}
function unrefElement(elRef: any): any {
const plain = toValue(elRef)
return (plain as any)?.$el ?? plain
}

const TippyComponent = defineComponent({
props: {
Expand Down Expand Up @@ -95,7 +104,7 @@ const TippyComponent = defineComponent({
return options
}

let target: any = () => elem.value
let target: any = () => unrefElement(elem)

if (props.to) {
if (typeof Element !== 'undefined' && props.to instanceof Element) {
Expand Down

0 comments on commit 0951cce

Please sign in to comment.