Skip to content

useWindowFocus ​

Category
Export Size
532 B
Last Changed
6 months ago

Reactively track window focus with window.onfocus and window.onblur events.

Demo ​

💡 Click somewhere outside of the document to unfocus.

Usage ​

js
import { useWindowFocus } from '@vueuse/core'

const focused = useWindowFocus()

Component Usage ​

This function also provides a renderless component version via the @vueuse/components package. Learn more about the usage.

vue
<template>
  <UseWindowFocus v-slot="{ focused }">
    Document Focus: {{ focused }}
  </UseWindowFocus>
</template>

Type Declarations ​

typescript
/**
 * Reactively track window focus with `window.onfocus` and `window.onblur`.
 *
 * @see https://vueuse.org/useWindowFocus
 */
export declare function useWindowFocus(
  options?: ConfigurableWindow,
): Ref<boolean>

Source ​

Source • Demo • Docs

Contributors ​

Anthony Fu
vaaski
vaakian X

Changelog ​

v9.11.0 on 1/17/2023
d5321 - fix(components): mark defineComponent as pure (#2623)

Released under the MIT License.