mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-12 10:14:02 +02:00
Fix backward typing bug in Safari by ensuring the selection is removed on blur (#4324)
Safari doesn't always remove the selection, even if the contenteditable element no longer has focus. In this scenario, we need to forcefully remove the selection on blur https://stackoverflow.com/questions/12353247/force-contenteditable-div-to-stop-accepting-input-after-it-loses-focus-under-web
This commit is contained in:
@@ -560,8 +560,6 @@ export const Editable = (props: EditableProps) => {
|
||||
return
|
||||
}
|
||||
|
||||
const window = ReactEditor.getWindow(editor)
|
||||
|
||||
// COMPAT: If the current `activeElement` is still the previous
|
||||
// one, this is due to the window being blurred when the tab
|
||||
// itself becomes unfocused, so we want to abort early to allow to
|
||||
@@ -605,6 +603,14 @@ export const Editable = (props: EditableProps) => {
|
||||
}
|
||||
}
|
||||
|
||||
// COMPAT: Safari doesn't always remove the selection even if the content-
|
||||
// editable element no longer has focus. Refer to:
|
||||
// https://stackoverflow.com/questions/12353247/force-contenteditable-div-to-stop-accepting-input-after-it-loses-focus-under-web
|
||||
if (IS_SAFARI) {
|
||||
const domSelection = root.getSelection()
|
||||
domSelection?.removeAllRanges()
|
||||
}
|
||||
|
||||
IS_FOCUSED.delete(editor)
|
||||
},
|
||||
[readOnly, attributes.onBlur]
|
||||
|
Reference in New Issue
Block a user