Skip to content

Commit

Permalink
fix(useFullscreen): isFullscreen handling for mutliple fullscreen e…
Browse files Browse the repository at this point in the history
…lements (#3000)

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
zaqvil and antfu committed Apr 22, 2023
1 parent af3ca89 commit 4a7a12c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/core/useFullscreen/index.ts
Expand Up @@ -76,6 +76,13 @@ export function useFullscreen(
].find(m => (document && m in document) || (targetRef.value && m in targetRef.value)) as any
})

const fullscreenElementMethod = [
'fullscreenElement',
'webkitFullscreenElement',
'mozFullScreenElement',
'msFullscreenElement',
].find(m => (document && m in document)) as 'fullscreenElement' | undefined

const isSupported = useSupported(() =>
targetRef.value
&& document
Expand All @@ -84,6 +91,12 @@ export function useFullscreen(
&& fullscreenEnabled.value !== undefined,
)

const isCurrentElementFullScreen = (): boolean => {
if (fullscreenElementMethod)
return document?.[fullscreenElementMethod] === targetRef.value
return false
}

const isElementFullScreen = (): boolean => {
if (fullscreenEnabled.value) {
if (document && document[fullscreenEnabled.value] != null) {
Expand Down Expand Up @@ -139,7 +152,9 @@ export function useFullscreen(
}

const handlerCallback = () => {
isFullscreen.value = isElementFullScreen()
const isElementFullScreenValue = isElementFullScreen()
if (!isElementFullScreenValue || (isElementFullScreenValue && isCurrentElementFullScreen()))
isFullscreen.value = isElementFullScreenValue
}

useEventListener(document, eventHandlers, handlerCallback, false)
Expand Down

0 comments on commit 4a7a12c

Please sign in to comment.