1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-15 03:33:59 +02:00

fix: check isContentEditable of target element in ReactEditor.hasDOMNode (#3389)

* fix ReactEditor.hasDOMNode

* make ReactEditor.hasDOMNode variables more clear
This commit is contained in:
Efim
2020-02-26 07:50:53 +03:00
committed by GitHub
parent 0d6271bc15
commit d8cc9fc46b

View File

@@ -149,15 +149,17 @@ export const ReactEditor = {
options: { editable?: boolean } = {}
): boolean {
const { editable = false } = options
const el = ReactEditor.toDOMNode(editor, editor)
let element
const editorEl = ReactEditor.toDOMNode(editor, editor)
let targetEl
// COMPAT: In Firefox, reading `target.nodeType` will throw an error if
// target is originating from an internal "restricted" element (e.g. a
// stepper arrow on a number input). (2018/05/04)
// https://github.com/ianstormtaylor/slate/issues/1819
try {
element = isDOMElement(target) ? target : target.parentElement
targetEl = (isDOMElement(target)
? target
: target.parentElement) as HTMLElement
} catch (err) {
if (
!err.message.includes('Permission denied to access property "nodeType"')
@@ -166,13 +168,13 @@ export const ReactEditor = {
}
}
if (!element) {
if (!targetEl) {
return false
}
return (
element.closest(`[data-slate-editor]`) === el &&
(!editable || el.isContentEditable)
targetEl.closest(`[data-slate-editor]`) === editorEl &&
(!editable || targetEl.isContentEditable)
)
},