Skip to content
On this page

useWindowFocus

Category
Export Size
1.07 kB
Last Changed
last year

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()
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.

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

Type Declarations

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

Source

SourceDemoDocs

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.