diff --git a/.changeset/calm-readers-brake.md b/.changeset/calm-readers-brake.md new file mode 100644 index 000000000..f7ebf19d0 --- /dev/null +++ b/.changeset/calm-readers-brake.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +Fix editor selection out of sync in readonly mode diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index a55e35c16..84f2f559e 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -231,6 +231,11 @@ export const Editable = (props: EditableProps) => { } } } + + // Deselect the editor if the dom selection is not selectable in readonly mode + if (readOnly && (!anchorNodeSelectable || !focusNodeSelectable)) { + Transforms.deselect(editor) + } } }, 100), [readOnly]