Skip to content

Commit

Permalink
Fix useFocused not updated when calling ReactEditor.focus (#5593)
Browse files Browse the repository at this point in the history
  • Loading branch information
12joan authored Jan 24, 2024
1 parent 8f2ad02 commit 54594d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/shiny-numbers-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

Fix: Calling `ReactEditor.focus` doesn't update `useFocused` when running in @testing-library/react
4 changes: 3 additions & 1 deletion packages/slate-react/src/plugin/react-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,10 @@ export const ReactEditor: ReactEditorInterface = {
Transforms.select(editor, Editor.start(editor, []))
editor.onChange()
}
el.focus({ preventScroll: true })
// IS_FOCUSED should be set before calling el.focus() to ensure that
// FocusedContext is updated to the correct value
IS_FOCUSED.set(editor, true)
el.focus({ preventScroll: true })
}
},

Expand Down

0 comments on commit 54594d0

Please sign in to comment.