Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(useFullscreen): isFullscreen handling for mutliple fullscreen elements #3000

Merged
merged 2 commits into from
Apr 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion packages/core/useFullscreen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ export function useFullscreen(
].find(m => (document && m in document) || (targetRef.value && m in targetRef.value)) as any
})

const fullscreenElement = computed<'fullscreenElement' | undefined>(() => {
return [
'fullscreenElement',
'webkitFullscreenElement',
'mozFullScreenElement',
'msFullscreenElement',
].find(m => (document && m in document)) as any
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this only checks for document, there's no need for this to be computed, as document is not going to be reactive


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

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

const isElementFullScreen = (): boolean => {
if (fullscreenEnabled.value) {
if (document && document[fullscreenEnabled.value] != null) {
Expand Down Expand Up @@ -139,7 +154,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