-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Safari: selection becomes null when editor blurs #4376
Comments
I think this has caused an issue with our BalloonToolbar plugin. It is designed to stay open as long as the editor has selection but a bug was reported after we upgraded where it closes in Safari when the editor blurs. @clauderic do you think we could come up with another solution for #4324? Happy to help if we can. |
@clauderic I can confirm that undoing the change in #4324 does fix this issue. export function toggleMark(editor: Editor, format: INLINE_TYPE): void {
const isActive = isMarkActive(editor, format);
if (isActive) {
Editor.removeMark(editor, format);
} else {
Editor.addMark(editor, format, true);
}
ReactEditor.focus(editor);
} |
The backward typing bug can be reproduced consistently in Safari if you programatically blur the editor. Try adding a toolbar button that blurs the editor when clicked to the RichText example https://github.com/ianstormtaylor/slate/blob/main/site/examples/richtext.tsx: <Slate editor={editor} value={value} onChange={value => setValue(value)}>
<Toolbar>
<MarkButton format="bold" icon="format_bold" />
// ...
+ <button onClick={() => ReactEditor.blur(editor)}>Blur</button>
</Toolbar> Safari.backwards.typing.bug.-.Before.mp4 |
As far as toolbar buttons go, the approach I would recommend is to prevent the default browser behaviour (blurring the contenteditable element) on pointer down: function ToolbarButton() {
return <button onPointerDown={preventDefault} />
}
function preventDefault(event) {
event.preventDefault();
} |
Thanks @clauderic, unfortunately the |
@jamestowers I am also using React.focusEditor to get around the backward typings bug in Safari. But I have to use an older version of slate-react v0.65.0 to get similar behaviour in all browsers. |
@Harsh1796 is the older version to prevent the null selection issue you first posted above, or are there other issues too? I may be missing something but I feel the downsides of the changes in #4324 are bigger than the those of adding |
Does anyone know the root cause of #4324? I expect it's a safari quirk? I'd be keen to work on an alternative solution if we had an idea of where to look. |
@jamestowers I am using an older version to prevent the null selection issue and maintain a similar behaviour in all browsers for my use case. |
Running into the same issue today, I have menu components that live outside of the Slate editor, I want to bring back the focus to the editor after the user clicks something in the menus, in Chrome caret position is restored properly but not in Safari. Has anybody found a workaround for this? |
In Safari the editor selection becomes null when the editor is blurred. However in Chrome & Firefox, the selection is preserved when the editor blurs.
Chrome
SlateJs-selectionChrome.mp4
Firefox
SlateJs-selectionFirefox.mp4
Safari
SlateJs-selectionSafari.mp4
Sandbox
Steps
Bold
. To make the text bold.Expectation
Expected behavior is get similar output for editor.selection across browsers when the editor blurs. In this case the selection is preserved for Chrome & Firefox but becomes null in Safari.
Environment
Cause of this issue can be #4324, where to fix a backward typing bug in Safari. Safari specific code was added to make sure the selection becomes null when editor is blurred.
The text was updated successfully, but these errors were encountered: