Files
headlessui/packages/@headlessui-vue/src/utils/dom.ts
T
Robin Malfait 7195eeed1a Fix ref element (#249)
* add small dom utility to resolve the dom node from a ref

* use dom() to resolve underlying DOM node

There is probably a better way to do this, the idea is that we apply a
ref to the component. However by default for html components
`yourRef.value` will be the underlying DOM node. However if you pass the
ref to another component, the actual DOM node will be located at
`yourRef.value.$el`.

Fixes: #21

* update changelog
2021-04-02 15:55:15 +02:00

8 lines
254 B
TypeScript

import { Ref } from 'vue'
export function dom<T extends HTMLElement>(ref?: Ref<T | null>): T | null {
if (ref == null) return null
if (ref.value == null) return null
return ((ref as Ref<T & { $el: unknown }>).value.$el ?? ref.value) as T | null
}