fn

useFullscreen

v0.0.14testeddemo

Reactive Fullscreen API for an element (or the document element). Handles vendor-prefixed fallbacks for request/exit/state detection and syncs isFullscreen from fullscreenchange events. SSR-safe.

Examples

ts
const el = useTemplateRef('el');
const { isFullscreen, enter, exit, toggle } = useFullscreen(el);
ts
// Fullscreen the whole page
const { toggle } = useFullscreen();

Demo

Loading demo…

Signature

ts
export function useFullscreen(
  target?: MaybeComputedElementRef,
  options: UseFullscreenOptions ={ ... }

Parameters

ParameterTypeDescription
target?MaybeComputedElementRefElement to display fullscreen (ref, getter, or component instance). Defaults to document.documentElement
options?UseFullscreenOptionsOptions (document, autoExit)

Returns

UseFullscreenReturn{ isSupported, isFullscreen, enter, exit, toggle }
PropertyTypeDescription
isSupportedComputedRef<boolean>Whether the Fullscreen API is supported for the target element
isFullscreenShallowRef<boolean>Whether the target element is currently in fullscreen mode
enter() => Promise<void>Request fullscreen mode for the target element
exit() => Promise<void>Exit fullscreen mode
toggle() => Promise<void>Toggle fullscreen mode for the target element