diff --git a/packages/core/unrefElement/index.test.ts b/packages/core/unrefElement/index.test.ts deleted file mode 100644 index 3eab915c076..00000000000 --- a/packages/core/unrefElement/index.test.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { defineComponent, h, nextTick, onMounted, ref } from 'vue-demi' -import { mount } from '../../.test' -import { templateRef } from '../templateRef' -import { unrefElement } from '.' - -describe('unrefElement', () => { - it('should be defined', () => { - expect(unrefElement).toBeDefined() - }) - - it('works with regular html elements', () => { - const refKey = 'target' - - mount(defineComponent({ - setup() { - const targetEl = templateRef(refKey) - - expect(unrefElement(targetEl)).toBeNull() - - onMounted(() => { - expect(unrefElement(targetEl)).toBeInstanceOf(HTMLElement) - }) - - return { targetEl } - }, - render() { - return h('div', { ref: refKey }) - }, - })) - }) - - it('works with Vue components which expose a proxy $el', () => { - const helperComponent = defineComponent({ - props: { - text: String, - }, - setup(props, { expose }) { - const buttonRef = ref(null) - - expose({ $el: buttonRef }) - - return () => [ - props.text && h('button', { ref: buttonRef }), - h('p', props.text), - ] - }, - - }) - - mount(defineComponent({ - setup() { - const targetEl = ref | null>(null) - const myText = ref('') - - expect(unrefElement(targetEl)).toBeNull() - - onMounted(() => { - expect(targetEl.value?.$el).toBeNull() - expect(unrefElement(targetEl)).toEqual(targetEl.value?.$el) - - myText.value = 'Hello' - nextTick(() => { - expect(targetEl.value?.$el).not.toBeNull() - expect(unrefElement(targetEl)).toEqual(targetEl.value?.$el) - }) - }) - - return () => h(helperComponent, { ref: targetEl, text: myText.value }) - }, - })) - }) -}) diff --git a/packages/core/unrefElement/index.ts b/packages/core/unrefElement/index.ts index 4f966fc0289..712be030647 100644 --- a/packages/core/unrefElement/index.ts +++ b/packages/core/unrefElement/index.ts @@ -15,6 +15,5 @@ export type UnRefElementReturn = T extend */ export function unrefElement(elRef: MaybeElementRef): UnRefElementReturn { const plain = unref(elRef) - - return plain != null && '$el' in (plain as VueInstance) ? (plain as VueInstance).$el : plain + return (plain as VueInstance)?.$el ?? plain }