Files
headlessui/packages/@headlessui-vue/src/hooks/use-window-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
463 B
TypeScript

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