Skip to content

Commit

Permalink
feat(useFullscreen): autoExit support (vitest-dev#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz committed Feb 26, 2022
1 parent f82b064 commit c0b1ad0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/core/useFullscreen/index.ts
@@ -1,6 +1,7 @@
/* this implementation is original ported from https://github.com/logaretm/vue-use-web by Abdelrahman Awad */

import { ref } from 'vue-demi'
import { tryOnScopeDispose } from '@vueuse/shared'
import type { MaybeElementRef } from '../unrefElement'
import { unrefElement } from '../unrefElement'
import { useEventListener } from '../useEventListener'
Expand Down Expand Up @@ -62,6 +63,15 @@ const functionsMap: FunctionMap[] = [
],
] as any

export interface UseFullscreenOptions extends ConfigurableDocument {
/**
* Automatically exit fullscreen when component is unmounted
*
* @default false
*/
autoExit?: boolean
}

/**
* Reactive Fullscreen API.
*
Expand All @@ -71,9 +81,9 @@ const functionsMap: FunctionMap[] = [
*/
export function useFullscreen(
target?: MaybeElementRef,
options: ConfigurableDocument = {},
options: UseFullscreenOptions = {},
) {
const { document = defaultDocument } = options
const { document = defaultDocument, autoExit = false } = options
const targetRef = target || document?.querySelector('html')
const isFullscreen = ref(false)
let isSupported = false
Expand Down Expand Up @@ -130,6 +140,9 @@ export function useFullscreen(
}, false)
}

if (autoExit)
tryOnScopeDispose(exit)

return {
isSupported,
isFullscreen,
Expand Down

0 comments on commit c0b1ad0

Please sign in to comment.