listen globally to clicks rather than blur event
This commit is contained in:
@@ -203,19 +203,21 @@ function Controls({
|
|||||||
onOut: onMouseLeave,
|
onOut: onMouseLeave,
|
||||||
} = useInteractionState()
|
} = useInteractionState()
|
||||||
const isFullscreen = useFullscreen()
|
const isFullscreen = useFullscreen()
|
||||||
const {
|
const {state: hasFocus, onIn: onFocus, onOut: onBlur} = useInteractionState()
|
||||||
state: hasFocus,
|
|
||||||
onIn: onFocus,
|
|
||||||
onOut: onUnfocus,
|
|
||||||
} = useInteractionState()
|
|
||||||
const [interactingViaKeypress, setInteractingViaKeypress] = useState(false)
|
const [interactingViaKeypress, setInteractingViaKeypress] = useState(false)
|
||||||
const onKeyDown = useCallback(() => {
|
const onKeyDown = useCallback(() => {
|
||||||
setInteractingViaKeypress(true)
|
setInteractingViaKeypress(true)
|
||||||
}, [])
|
}, [])
|
||||||
const onBlur = useCallback(() => {
|
useEffect(() => {
|
||||||
setInteractingViaKeypress(false)
|
if (interactingViaKeypress) {
|
||||||
onUnfocus()
|
document.addEventListener('click', () => setInteractingViaKeypress(false))
|
||||||
}, [onUnfocus])
|
return () => {
|
||||||
|
document.removeEventListener('click', () =>
|
||||||
|
setInteractingViaKeypress(false),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [interactingViaKeypress])
|
||||||
|
|
||||||
const autoplayDisabled = useAutoplayDisabled()
|
const autoplayDisabled = useAutoplayDisabled()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user