1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-27 09:04:31 +02:00

When the isInEditor parameter is a text node use its parent only if the parent exists (#974)

* When the parameter passed to `isInEditor` is a text node use its parent if the parent exists

* Add comment on `parentElement` text node browser compatibility
This commit is contained in:
David Gertmenian-Wong
2017-08-15 12:23:01 -07:00
committed by Ian Storm Taylor
parent 169a59a596
commit 458c022013

View File

@@ -251,7 +251,9 @@ class Content extends React.Component {
const { element } = this
// COMPAT: Text nodes don't have `isContentEditable` property. So, when
// `target` is a text node use its parent element for check.
const el = target.nodeType === 3 ? target.parentElement : target
// COMPAT: `parentElement` is not defined on text nodes in certain browsers:
// https://developer.mozilla.org/en-US/docs/Web/API/Node/parentElement#Browser_compatibility
const el = (target.nodeType === 3 && target.parentElement) ? target.parentElement : target
return (
(el.isContentEditable) &&
(el === element || findClosestNode(el, '[data-slate-editor]') === element)