Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Fix isHTMLBRElement check
Browse files Browse the repository at this point in the history
Summary: When rendering in an `iframe`/other document, I was getting an error when trying to add a newline. Turns out there was an issue with the `isHTMLBRElement` check, so fix that and change the code in `DraftEditorLeaf.react.js` to use `isHTMLBRElement`

Reviewed By: claudiopro

Differential Revision: D18815600

fbshipit-source-id: 6297e29efa987e1e6937b5093d565355c5839b2e
  • Loading branch information
Jack Armstrong authored and facebook-github-bot committed Dec 5, 2019
1 parent 7721805 commit e869fcb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/component/contents/DraftEditorLeaf.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const DraftEditorTextNode = require('DraftEditorTextNode.react');
const React = require('React');

const invariant = require('invariant');
const isHTMLBRElement = require('isHTMLBRElement');
const setDraftEditorSelection = require('setDraftEditorSelection');

type Props = {
Expand Down Expand Up @@ -101,7 +102,7 @@ class DraftEditorLeaf extends React.Component<Props> {

if (child.nodeType === Node.TEXT_NODE) {
targetNode = child;
} else if (child instanceof Element && child.tagName === 'BR') {
} else if (isHTMLBRElement(child)) {
targetNode = node;
} else {
targetNode = child.firstChild;
Expand Down
2 changes: 1 addition & 1 deletion src/component/utils/isElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
* @flow strict
* @emails oncall+draft_js
*/

Expand Down
12 changes: 4 additions & 8 deletions src/component/utils/isHTMLBRElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
* @flow strict
* @emails oncall+draft_js
*/

const isElement = require('isElement');

function isHTMLBRElement(node: ?Node): boolean {
if (!node || !node.ownerDocument) {
return false;
}
if (!node.ownerDocument.defaultView) {
return node instanceof HTMLBRElement;
}
if (node instanceof node.ownerDocument.defaultView.HTMLElement) {
return true;
}
return false;
return isElement(node) && node.nodeName === 'BR';
}

module.exports = isHTMLBRElement;

0 comments on commit e869fcb

Please sign in to comment.