Gathering detailed insights and metrics for react-quill
Gathering detailed insights and metrics for react-quill
Gathering detailed insights and metrics for react-quill
Gathering detailed insights and metrics for react-quill
react-quill-emoji
React Quill Extension for Emoji Selection
react-quill-abrarhayat
The Quill rich-text editor as a React component. This is a fork of https://github.com/zenoamaro/react-quill.
@plasmicpkgs/react-quill
Plasmic registration call for react-quill WYSIWYG Editor
react-quill-image-uploader
a plugin for react-quill which can upload multi image and remember the image url histroy
npm install react-quill
86.8
Supply Chain
94.7
Quality
77.7
Maintenance
50
Vulnerability
99.6
License
v1.1.0
Published on 04 Aug 2017
v1.0.0-rc.3
Published on 21 Jun 2017
Version 1.0.0-beta-5
Published on 10 Apr 2017
Version 1.0.0-beta-4
Published on 27 Mar 2017
Version 1.0.0-beta-3
Published on 03 Mar 2017
Version 1.0.0-beta-2
Published on 26 Feb 2017
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
6,792 Stars
430 Commits
926 Forks
59 Watching
12 Branches
48 Contributors
Updated on 28 Nov 2024
Minified
Minified + Gzipped
JavaScript (64.52%)
TypeScript (35.48%)
Cumulative downloads
Total Downloads
Last day
-3.3%
105,583
Compared to previous day
Last week
2.9%
576,282
Compared to previous week
Last month
2.9%
2,476,696
Compared to previous month
Last year
17.6%
26,943,965
Compared to previous year
3
30
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.
1npm install react-quill --save
1import React, { useState } from 'react'; 2import ReactQuill from 'react-quill'; 3import 'react-quill/dist/quill.snow.css'; 4 5function MyComponent() { 6 const [value, setValue] = useState(''); 7 8 return <ReactQuill theme="snow" value={value} onChange={setValue} />; 9}
1<link 2 rel="stylesheet" 3 href="https://unpkg.com/react-quill@1.3.3/dist/quill.snow.css" 4/>
1<script 2 src="https://unpkg.com/react@16/umd/react.development.js" 3 crossorigin 4></script> 5<script 6 src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" 7 crossorigin 8></script> 9<script src="https://unpkg.com/react-quill@1.3.3/dist/react-quill.js"></script> 10<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script> 11<script type="text/babel" src="/my-scripts.js"></script>
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.
1<ReactQuill theme="snow" .../>
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:
1import 'react-quill/dist/quill.snow.css';
The styles are also available via CDN:
1<link 2 rel="stylesheet" 3 href="https://unpkg.com/react-quill@1.3.3/dist/quill.snow.css" 4/>
The Quill Toolbar Module API provides an easy way to configure the default toolbar icons using an array of format names.
1class MyComponent extends Component { 2 constructor(props) { 3 super(props); 4 this.state = { 5 text: "", 6 } 7 } 8 9 modules = { 10 toolbar: [ 11 [{ 'header': [1, 2, false] }], 12 ['bold', 'italic', 'underline','strike', 'blockquote'], 13 [{'list': 'ordered'}, {'list': 'bullet'}, {'indent': '-1'}, {'indent': '+1'}], 14 ['link', 'image'], 15 ['clean'] 16 ], 17 }, 18 19 formats = [ 20 'header', 21 'bold', 'italic', 'underline', 'strike', 'blockquote', 22 'list', 'bullet', 'indent', 23 'link', 'image' 24 ], 25 26 render() { 27 return ( 28 <div className="text-editor"> 29 <ReactQuill theme="snow" 30 modules={this.modules} 31 formats={this.formats}> 32 </ReactQuill> 33 </div> 34 ); 35 } 36} 37 38export default MyComponent;
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
1/* 2 * Custom "star" icon for the toolbar using an Octicon 3 * https://octicons.github.io 4 */ 5const CustomButton = () => <span className="octicon octicon-star" />; 6 7/* 8 * Event handler to be attached using Quill toolbar module 9 * http://quilljs.com/docs/modules/toolbar/ 10 */ 11function insertStar() { 12 const cursorPosition = this.quill.getSelection().index; 13 this.quill.insertText(cursorPosition, '★'); 14 this.quill.setSelection(cursorPosition + 1); 15} 16 17/* 18 * Custom toolbar component including insertStar button and dropdowns 19 */ 20const CustomToolbar = () => ( 21 <div id="toolbar"> 22 <select 23 className="ql-header" 24 defaultValue={''} 25 onChange={(e) => e.persist()} 26 > 27 <option value="1"></option> 28 <option value="2"></option> 29 <option selected></option> 30 </select> 31 <button className="ql-bold"></button> 32 <button className="ql-italic"></button> 33 <select className="ql-color"> 34 <option value="red"></option> 35 <option value="green"></option> 36 <option value="blue"></option> 37 <option value="orange"></option> 38 <option value="violet"></option> 39 <option value="#d0d1d2"></option> 40 <option selected></option> 41 </select> 42 <button className="ql-insertStar"> 43 <CustomButton /> 44 </button> 45 </div> 46); 47 48/* 49 * Editor component with custom toolbar and content containers 50 */ 51class Editor extends React.Component { 52 constructor(props) { 53 super(props); 54 this.state = { editorHtml: '' }; 55 this.handleChange = this.handleChange.bind(this); 56 } 57 58 handleChange(html) { 59 this.setState({ editorHtml: html }); 60 } 61 62 render() { 63 return ( 64 <div className="text-editor"> 65 <CustomToolbar /> 66 <ReactQuill 67 onChange={this.handleChange} 68 placeholder={this.props.placeholder} 69 modules={Editor.modules} 70 /> 71 </div> 72 ); 73 } 74} 75 76/* 77 * Quill modules to attach to editor 78 * See http://quilljs.com/docs/modules/ for complete options 79 */ 80Editor.modules = { 81 toolbar: { 82 container: '#toolbar', 83 handlers: { 84 insertStar: insertStar, 85 }, 86 }, 87}; 88 89/* 90 * Quill editor formats 91 * See http://quilljs.com/docs/formats/ 92 */ 93Editor.formats = [ 94 'header', 95 'font', 96 'size', 97 'bold', 98 'italic', 99 'underline', 100 'strike', 101 'blockquote', 102 'list', 103 'bullet', 104 'indent', 105 'link', 106 'image', 107 'color', 108]; 109 110/* 111 * PropType validation 112 */ 113Editor.propTypes = { 114 placeholder: React.PropTypes.string, 115}; 116 117/* 118 * Render component on page 119 */ 120ReactDOM.render( 121 <Editor placeholder={'Write something or insert a star ★'} />, 122 document.querySelector('.app') 123);
The component has two types of formats:
formats
prop. All formats are enabled by default.1import ReactQuill, { Quill } from 'react-quill'; // ES6 2const ReactQuill = require('react-quill'); // CommonJS
1/* 2 * Example Parchment format from 3 * https://quilljs.com/guides/cloning-medium-with-parchment/ 4 * See the video example in the guide for a complex format 5 */ 6let Inline = Quill.import('blots/inline'); 7class BoldBlot extends Inline {} 8BoldBlot.blotName = 'bold'; 9BoldBlot.tagName = 'strong'; 10Quill.register('formats/bold', BoldBlot); 11 12const formats = ['bold']; // add custom format name + any built-in formats you need 13 14/* 15 * Editor component with default and custom formats 16 */ 17class MyComponent extends React.Component { 18 constructor(props) { 19 this.formats = formats; 20 this.state = { text: '' }; 21 } 22 23 handleChange(value) { 24 this.setState({ text: value }); 25 } 26 27 render() { 28 return ( 29 <ReactQuill 30 value={this.state.text} 31 onChange={this.handleChange} 32 formats={this.formats} 33 /> 34 ); 35 } 36}
If you instantiate ReactQuill without children, it will create a <div>
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 <textarea>
s are not supported by Quill at this time.
Note: Custom editing areas lose focus when using React 16 as a peer dep at this time (bug).
1class MyComponent extends React.Component { 2 3 render() { 4 return ( 5 <ReactQuill> 6 <div className="my-editing-area"/> 7 </ReactQuill> 8 ); 9 } 10 11});
Upgrading to ReactQuill v2 should be as simple as updating your dependency. However, it also removes support for long-deprecated props, the ReactQuill Mixin, and the Toolbar component.
Support for the toolbar
, styles
, pollInterval
Quill options has long disabled. Starting from this release, ReactQuill will not warn you anymore if you try using them.
The ReactQuill Mixin allowed injecting the core functionality that made ReactQuill tick into your own components, and create deeply customized versions.
The Mixin has been considered an anti-pattern for a long time now, so we have decided to finalize its deprecation.
There is no upgrade path. If you have a use case that relied on the Mixin, you're encouraged to open an issue, and we will try to provide you with a new feature to make it possible, or dedicated support to migrate out of it.
Quill has long provided built-in support for custom toolbars, which replaced ReactQuill's (quite inflexible) Toolbar component.
Use the Toolbar Module or the HTML Toolbar feature instead.
1// ES6 2import ReactQuill, { Quill } from 'react-quill'; 3 4// CommonJS 5const ReactQuill = require('react-quill'); 6const { Quill } = ReactQuill;
Quill
: The Quill
namespace on which you can call register
.
id
: ID to be applied to the DOM element.
className
: Classes to be applied to the DOM element.
value
: Value for the editor as a controlled component. Can be a string containing HTML, a Quill Delta instance, or a plain object representing a Delta.
Note that due to limitations in Quill, this is actually a semi-controlled mode, meaning that the edit is not prevented, but changing value
will still replace the contents.
Also note that passing a Quill Delta here, and then an HTML string, or vice-versa, will always trigger a change, regardless of whether they represent the same document.
⚠️ Do not pass the delta
object from the onChange
event as value
, as it will cause a loop. See Using Deltas for details.
defaultValue
: Initial value for the editor as an uncontrolled component. Can be a string containing HTML, a Quill Delta, or a plain object representing a Delta.
readOnly
: If true, the editor won't allow changing its contents. Wraps the Quill disable
API.
placeholder
: The default value for the empty editor. Note: The Quill API does not support changing this value dynamically. Use refs and data-attributes instead (see #340).
modules
: An object specifying which modules are enabled, and their configuration. The editor toolbar is a commonly customized module. See the modules section over the Quill documentation for more information on what modules are available.
formats
: An array of formats to be enabled during editing. All implemented formats are enabled by default. See Formats for a list.
Custom formats should not be included in the array as of version 1.0.0. Instead they should be created through Parchment and registered with the module's Quill export.
style
: An object with custom CSS rules to apply on the editor's container. Rules should be in React's "camelCased" naming style.
theme
: The name of the theme to apply to the editor. Defaults to snow
, Quill's standard theme. Pass null
to use the minimal core theme. See the docs on themes for more information on including the required stylesheets.
tabIndex
: The order in which the editor becomes focused, among other controls in the page, during keyboard navigation.
bounds
: Selector or DOM element used by Quill to constrain position of popups. Defaults to document.body
.
children
: A single React element that will be used as the editing area for Quill in place of the default, which is a <div>
. Note that you cannot use a <textarea>
, as it is not a supported target. Also note that updating children is costly, as it will cause the Quill editor to be recreated. Set the value
prop if you want to control the html contents of the editor.
onChange(content, delta, source, editor)
: Called back with the new contents of the editor after change. It will be passed the HTML contents of the editor, a delta object expressing the change, the source of the change, and finally a read-only proxy to editor accessors such as getHTML()
.
⚠️ Do not use this delta
object as value
, as it will cause a loop. Use editor.getContents()
instead. See Using Deltas for details.
onChangeSelection(range, source, editor)
: Called back with the new selected range, or null when unfocused. It will be passed the selection range, the source of the change, and finally a read-only proxy to editor accessors such as getBounds()
.
onFocus(range, source, editor)
: Called when the editor becomes focused. It will receive the new selection range.
onBlur(previousRange, source, editor)
: Called when the editor loses focus. It will receive the selection range it had right before losing focus.
onKeyPress(event)
: Called after a key has been pressed and released.
: Note that, like its native counterpart, this won't be called for special keys such as shift or enter. If you need those, hook onto onKeyDown
or onKeyUp
.
onKeyDown(event)
: Called after a key has been pressed, but before it is released.
: Note that, due to how Quill works, it's possible that you won't receive events for keys such as enter, backspace or delete. If that's the case, try hooking onto onKeyUp
instead.
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.
If you have a ref to a ReactQuill node, you will be able to invoke the following methods:
focus()
: Focuses the editor.
blur()
: Removes focus from the editor.
getEditor()
: Returns the Quill instance that backs the editor. While you can freely use this to access methods such as getText()
, please avoid from imperatively manipulating the instance, to avoid getting ReactQuill and Quill out-of-sync. A much-safer unprivileged editor is available as replacement.
1class Editor extends React.Component { 2 constructor(props) { 3 super(props); 4 this.quillRef = null; // Quill instance 5 this.reactQuillRef = null; // ReactQuill component 6 } 7 8 componentDidMount() { 9 this.attachQuillRefs(); 10 } 11 12 componentDidUpdate() { 13 this.attachQuillRefs(); 14 } 15 16 attachQuillRefs = () => { 17 if (typeof this.reactQuillRef.getEditor !== 'function') return; 18 this.quillRef = this.reactQuillRef.getEditor(); 19 }; 20 21 insertText = () => { 22 var range = this.quillRef.getSelection(); 23 let position = range ? range.index : 0; 24 this.quillRef.insertText(position, 'Hello, World! '); 25 }; 26 27 render() { 28 return ( 29 <div> 30 <ReactQuill 31 ref={(el) => { 32 this.reactQuillRef = el; 33 }} 34 theme={'snow'} 35 /> 36 <button onClick={this.insertText}>Insert Text</button> 37 </div> 38 ); 39 } 40}
makeUnprivilegedEditor
: Creates an unprivileged editor. Pass this method a reference to the Quill instance from getEditor
. Normally you do not need to use this method since the editor exposed to event handlers is already unprivileged.
1const editor = this.reactQuillRef.getEditor(); 2const unprivilegedEditor = this.reactQuillRef.makeUnprivilegedEditor(editor); 3// You may now use the unprivilegedEditor proxy methods 4unprivilegedEditor.getText();
During events, ReactQuill will make a restricted subset of the Quill API available as the editor
argument. This prevents access to destructive methods, which might cause ReactQuill to get out-of-sync with the component. It provides the following methods, which are mostly proxies of existing Quill methods:
getLength()
: Returns the length of the editor contents, in characters, not including any HTML tag.
getText()
: Returns the string contents of the editor, not including any HTML tag.
getHTML()
: Returns the full HTML contents of the editor.
getContents()
: Returns a Quill Delta of the complete document.
getSelection()
: Returns the current selection range, or null
if the editor is unfocused.
getBounds()
: Returns the pixel position, relative to the editor container, and dimensions, of a selection, at a given location.
You can build libs, types and bundles:
1npm build # or watch
You can also run the automated test suite:
1npm test
More tasks are available as package scripts:
Script | Description |
---|---|
npm run build | Builds lib and browser bundle |
npm run watch | Rebuilds on source code changes |
npm run test | Runs unit tests and coverage |
npm run clean | Cleans build artifacts |
npm run demo | Serves a simple ReactQuill test application |
Please check the browser support table for the upstream Quill dependency. The ReactQuill distributable itself is ES5-compatible.
ReactQuill would not be where it is today without the contributions of many people, which we are incredibly grateful for:
The MIT License (MIT)
Copyright (c) 2020, zenoamaro zenoamaro@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 6/21 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
54 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More