Files
headlessui/packages/@headlessui-vue/src/hooks/use-document-event.ts
T
Jordan Pittman 865bd57357 Fix SSR tab rendering on React 17 (#2102)
* Allow clicks inside dialog panel when target is inside shadow root

* Introduce resettable “server” state

This will aid in testing

* Add SSR and hydration tests for react

* Fix server rendering of Tabs on React 17

* Fix CS

* Skip hydration tests

* Tweak SSR implementation in Vue

* Update changelog
2022-12-16 12:55:51 -05:00

16 lines
475 B
TypeScript

import { watchEffect } from 'vue'
import { env } from '../utils/env'
export function useDocumentEvent<TType extends keyof DocumentEventMap>(
type: TType,
listener: (this: Document, ev: DocumentEventMap[TType]) => any,
options?: boolean | AddEventListenerOptions
) {
if (env.isServer) return
watchEffect((onInvalidate) => {
document.addEventListener(type, listener, options)
onInvalidate(() => document.removeEventListener(type, listener, options))
})
}