Skip to main content

useFullscreen

Purpose

Returns

Usage

useFullscreen

ParametersTypePurposeDefault
controllerControllerThe instance of the controller to install the behaviour on. This allows the mixin to automatically register cleanup on the controller's disconnect.this
elementWindow or Document or HTMLElementThe element to open in fullscreenDocument
Return valuesTypePurpose
isFullscreenFunctionA function that returns whether or not the element is currently in fullscreen
enterFunctionA function that when called enters fullscreen
exitFunctionA function that when called exits fullscreen
toggleFunctionA function that enters fullscreen if not already in fullscreen and exits if already in fullscreen

How to Use


import {Controller} from '@hotwired/stimulus';
import {useFullscreen} from 'stimulus-library';

export default class extends Controller {
connect() {
// Retrieve the fullscreen functions, where the whole page will be fullscreened
let {isFullscreen, enter, exit, toggle} = useFullscreen(this)

// Retrieve the fullscreen functions, where the controller's element will be fullscreened
let {isFullscreen, enter, exit, toggle} = useFullscreen(this, this.element)

// Retrieve the fullscreen functions, where the controller's videoTarget element will be fullscreened
let {isFullscreen, enter, exit, toggle} = useFullscreen(this, this.videoTarget)

this.isFullscreen = isFullscreen;
this.enterFullscreen = enter;
this.exitFullscreen = exit;
}

someMethod() {
this.enterFullscreen();
}

somewhereElse() {
if (this.isFullscreen()){
this.exitFullscreen()
}
}
}