1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-04-15 10:52:34 +02:00

run focus event listener after existing onFocus handlers (#4755)

* run focus event listener after existing onFocus handlers

* change window.setTimeout to setTimeout
This commit is contained in:
Jacob Hurwitz 2022-01-10 15:20:47 -08:00 committed by GitHub
parent 51e02de9de
commit 8daa77e9fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
'slate-react': patch
---
fix useFocused hook

View File

@ -57,13 +57,21 @@ export const Slate = (props: {
})
useIsomorphicLayoutEffect(() => {
const fn = () => setIsFocused(ReactEditor.isFocused(editor))
const fn = () => {
setTimeout(() => {
setIsFocused(ReactEditor.isFocused(editor))
}, 0)
}
document.addEventListener('focus', fn, true)
return () => document.removeEventListener('focus', fn, true)
}, [])
useIsomorphicLayoutEffect(() => {
const fn = () => setIsFocused(ReactEditor.isFocused(editor))
const fn = () => {
setTimeout(() => {
setIsFocused(ReactEditor.isFocused(editor))
}, 0)
}
document.addEventListener('blur', fn, true)
return () => document.removeEventListener('blur', fn, true)
}, [])