The Quill rich-text editor as a React component.
npm install react-quillReactQuill  

==============================================================================
A [Quill] component for [React].
See a [live demo] or Codepen.
[quill]: https://quilljs.com
[react]: https://facebook.github.io/react/
[live demo]: https://zenoamaro.github.io/react-quill/
- Quick Start
- With webpack or create-react-app
- With the browser bundle
- Usage
- Controlled mode caveats
- Using Deltas
- Themes
- Custom Toolbar
- Default Toolbar Elements
- HTML Toolbar
- Custom Formats
- Custom editing area
- Upgrading to ReactQuill v2
- Deprecated props
- ReactQuill Mixin
- Toolbar component
- API reference
- Exports
- Props
- Methods
- The unprivileged editor
- Building and testing
- Browser support
- Changelog
- Contributors
- License
---
This is the documentation for ReactQuill v2 — Previous releases: v1
---
💯 ReactQuill v2
ReactQuill 2 is here, baby! And it brings a full port to TypeScript and React 16+, a refactored build system, and a general tightening of the internal logic.
We worked hard to avoid introducing any behavioral changes. For the vast majority of the cases, no migration is necessary at all. However, support for long-deprecated props, the ReactQuill Mixin, and the Toolbar component have been removed. Be sure to read the migration guide.
We expect this release to be a drop-in upgrade – if that isn't the case, please file an issue with the v2 label.
---
Make sure you have react and react-dom, and some way to load styles, like style-loader. See the documentation on themes for more information.
``sh`
npm install react-quill --save
`jsx
import React, { useState } from 'react';
import ReactQuill from 'react-quill';
import 'react-quill/dist/quill.snow.css';
function MyComponent() {
const [value, setValue] = useState('');
return
}
`
`html`
rel="stylesheet"
href="https://unpkg.com/react-quill@1.3.3/dist/quill.snow.css"
/>
`html`
src="https://unpkg.com/react@16/umd/react.development.js"
crossorigin
>
src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"
crossorigin
>
In controlled mode, components are supposed to prevent local stateful changes, and instead only have them happen through onChange and value.
Because Quill handles its own changes, and does not allow preventing edits, ReactQuill has to settle for a hybrid between controlled and uncontrolled mode. It can't prevent the change, but will still override the content whenever value differs from current state.
If you frequently need to manipulate the DOM or use the Quill APIs imperatively, you might consider switching to fully uncontrolled mode. ReactQuill will initialize the editor using defaultValue, but won't try to reset it after that. The onChange callback will still work as expected.
Read more about uncontrolled components in the React docs.
You can pass a Quill Delta, instead of an HTML string, as the value and defaultValue properties. Deltas have a number of advantages over HTML strings, so you might want use them instead. Be aware, however, that comparing Deltas for changes is more expensive than comparing HTML strings, so it might be worth to profile your usage patterns.
Note that switching value from an HTML string to a Delta, or vice-versa, will trigger a change, regardless of whether they represent the same document, so you might want to stick to a format and keep using it consistently throughout.
⚠️ Do not use the delta object you receive from the onChange event as value. This object does not contain the full document, but only the last modifications, and doing so will most likely trigger an infinite loop where the same changes are applied over and over again. Use editor.getContents() during the event to obtain a Delta of the full document instead. ReactQuill will prevent you from making such a mistake, however if you are absolutely sure that this is what you want, you can pass the object through new Delta() again to un-taint it.
The Quill editor supports themes. It includes a full-fledged theme, called _snow_, that is Quill's standard appearance, and a _bubble_ theme that is similar to the inline editor on Medium. At the very least, the _core_ theme must be included for modules like toolbars or tooltips to work.
To activate a theme, pass the name of the theme to the theme prop. Pass a falsy value (eg. null) to use the core theme.
`jsx`
Then, import the stylesheet for the themes you want to use.
This may vary depending how application is structured, directories or otherwise. For example, if you use a CSS pre-processor like SASS, you may want to import that stylesheet inside your own. These stylesheets can be found in the Quill distribution, but for convenience they are also linked in ReactQuill's dist folder.
Here's an example using style-loader for Webpack, or create-react-app, that will automatically inject the styles on the page:
`jsx`
import 'react-quill/dist/quill.snow.css';
The styles are also available via CDN:
`html`
rel="stylesheet"
href="https://unpkg.com/react-quill@1.3.3/dist/quill.snow.css"
/>
#### Default Toolbar Elements
The Quill Toolbar Module API provides an easy way to configure the default toolbar icons using an array of format names.
Example Code
`jsx
class MyComponent extends Component {
constructor(props) {
super(props);
this.state = {
text: "",
}
}
modules = {
toolbar: [
[{ 'header': [1, 2, false] }],
['bold', 'italic', 'underline','strike', 'blockquote'],
[{'list': 'ordered'}, {'list': 'bullet'}, {'indent': '-1'}, {'indent': '+1'}],
['link', 'image'],
['clean']
],
},
formats = [
'header',
'bold', 'italic', 'underline', 'strike', 'blockquote',
'list', 'bullet', 'indent',
'link', 'image'
],
render() {
return (
export default MyComponent;
`
#### HTML Toolbar
You can also supply your own HTML/JSX toolbar with custom elements that are not part of the Quill theme.
See this example live on Codepen: Custom Toolbar Example
Example Code
`jsx
/*
* Custom "star" icon for the toolbar using an Octicon
* https://octicons.github.io
*/
const CustomButton = () => ;
/*
* Event handler to be attached using Quill toolbar module
* http://quilljs.com/docs/modules/toolbar/
*/
function insertStar() {
const cursorPosition = this.quill.getSelection().index;
this.quill.insertText(cursorPosition, '★');
this.quill.setSelection(cursorPosition + 1);
}
/*
* Custom toolbar component including insertStar button and dropdowns
*/
const CustomToolbar = () => (
/*
* Editor component with custom toolbar and content containers
*/
class Editor extends React.Component {
constructor(props) {
super(props);
this.state = { editorHtml: '' };
this.handleChange = this.handleChange.bind(this);
}
handleChange(html) {
this.setState({ editorHtml: html });
}
render() {
return (
/*
* Quill modules to attach to editor
* See http://quilljs.com/docs/modules/ for complete options
*/
Editor.modules = {
toolbar: {
container: '#toolbar',
handlers: {
insertStar: insertStar,
},
},
};
/*
* Quill editor formats
* See http://quilljs.com/docs/formats/
*/
Editor.formats = [
'header',
'font',
'size',
'bold',
'italic',
'underline',
'strike',
'blockquote',
'list',
'bullet',
'indent',
'link',
'image',
'color',
];
/*
* PropType validation
*/
Editor.propTypes = {
placeholder: React.PropTypes.string,
};
/*
* Render component on page
*/
ReactDOM.render(
document.querySelector('.app')
);
`
The component has two types of formats:
1. The default Quill formats that are enabled/disabled using the formats prop. All formats are enabled by default.
2. Custom formats created using Parchment and registered with your component's Quill instance
Example Code
`js`
import ReactQuill, { Quill } from 'react-quill'; // ES6
const ReactQuill = require('react-quill'); // CommonJS
`jsx
/*
* Example Parchment format from
* https://quilljs.com/guides/cloning-medium-with-parchment/
* See the video example in the guide for a complex format
*/
let Inline = Quill.import('blots/inline');
class BoldBlot extends Inline {}
BoldBlot.blotName = 'bold';
BoldBlot.tagName = 'strong';
Quill.register('formats/bold', BoldBlot);
const formats = ['bold']; // add custom format name + any built-in formats you need
/*
* Editor component with default and custom formats
*/
class MyComponent extends React.Component {
constructor(props) {
this.formats = formats;
this.state = { text: '' };
}
handleChange(value) {
this.setState({ text: value });
}
render() {
return (
onChange={this.handleChange}
formats={this.formats}
/>
);
}
}
`
If you instantiate ReactQuill without children, it will create a
for you, to be used as the editing area for Quill. If you prefer, you can specify your own element for ReactQuill to use. Note that