listen globally to clicks rather than blur event

This commit is contained in:
Samuel Newman
2024-07-31 18:15:54 +02:00
parent ea69babf6f
commit df3da3ac2a
@@ -203,19 +203,21 @@ function Controls({
onOut: onMouseLeave,
} = useInteractionState()
const isFullscreen = useFullscreen()
const {
state: hasFocus,
onIn: onFocus,
onOut: onUnfocus,
} = useInteractionState()
const {state: hasFocus, onIn: onFocus, onOut: onBlur} = useInteractionState()
const [interactingViaKeypress, setInteractingViaKeypress] = useState(false)
const onKeyDown = useCallback(() => {
setInteractingViaKeypress(true)
}, [])
const onBlur = useCallback(() => {
setInteractingViaKeypress(false)
onUnfocus()
}, [onUnfocus])
useEffect(() => {
if (interactingViaKeypress) {
document.addEventListener('click', () => setInteractingViaKeypress(false))
return () => {
document.removeEventListener('click', () =>
setInteractingViaKeypress(false),
)
}
}
}, [interactingViaKeypress])
const autoplayDisabled = useAutoplayDisabled()