Skip to content

Commit

Permalink
run focus event listener after existing onFocus handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
jhurwitz committed Dec 31, 2021
1 parent 735d2d0 commit bc28754
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-poems-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

fix useFocused hook
12 changes: 10 additions & 2 deletions packages/slate-react/src/components/slate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,21 @@ export const Slate = (props: {
})

useIsomorphicLayoutEffect(() => {
const fn = () => setIsFocused(ReactEditor.isFocused(editor))
const fn = () => {
window.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 = () => {
window.setTimeout(() => {
setIsFocused(ReactEditor.isFocused(editor))
}, 0)
}
document.addEventListener('blur', fn, true)
return () => document.removeEventListener('blur', fn, true)
}, [])
Expand Down

0 comments on commit bc28754

Please sign in to comment.