Skip to content

Commit

Permalink
fix:311-add preserveWhitespace prop (zenoamaro#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
royshouvik authored and alexkrolick committed Oct 16, 2018
1 parent 9be8dc6 commit 916a18e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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;
},
Expand Down

0 comments on commit 916a18e

Please sign in to comment.