From 916a18e88cbe2111e19a02c27f20717b2c36dfbd Mon Sep 17 00:00:00 2001 From: Shouvik Roy Date: Tue, 16 Oct 2018 22:40:00 +0200 Subject: [PATCH] fix:311-add preserveWhitespace prop (#407) --- README.md | 3 +++ src/component.js | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dc3a8afa..edb6cc2b 100644 --- a/README.md +++ b/README.md @@ -622,6 +622,9 @@ import ReactQuill, { Quill, Mixin, Toolbar } from 'react-quill'; // ES6 `onKeyUp(event)` : Called after a key has been released. +`preserveWhitespace` +: If true, a `pre` tag is used for the editor area instead of the default `div` tag. This prevents Quill from +collapsing continuous whitespaces on paste. [Related issue](https://github.com/quilljs/quill/issues/1751). ### Methods diff --git a/src/component.js b/src/component.js index 634bae4e..600a445e 100644 --- a/src/component.js +++ b/src/component.js @@ -34,6 +34,7 @@ var QuillComponent = createClass({ onKeyPress: T.func, onKeyDown: T.func, onKeyUp: T.func, + preserveWhitespace: T.bool, modules: function(props) { var isNotObject = T.object.apply(this, arguments); @@ -331,6 +332,7 @@ var QuillComponent = createClass({ renderEditingArea: function() { var self = this; var children = this.props.children; + var preserveWhitespace = this.props.preserveWhitespace; var properties = { key: this.state.generation, @@ -341,10 +343,10 @@ var QuillComponent = createClass({ var customElement = React.Children.count(children) ? React.Children.only(children) : null; - + var defaultElement = preserveWhitespace ? DOM.pre : DOM.div; var editingArea = customElement ? React.cloneElement(customElement, properties) - : DOM.div(properties); + : defaultElement(properties); return editingArea; },