mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-15 11:44:05 +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:
@@ -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)
|
||||
)
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user