Rich text editor
Installation
Package has peer dependencies: react, react-dom, @mantine/hooks and @mantine/core:.
Install with npm:
Install with yarn:
Demo
Usage
value
and onChange
props are required for component to work.
Note that though component is controlled you cannot force value (limitation of Quill.js library).
Configure toolbar
RichTextEditor supports these controls in toolbar:
bold
,strike
,italic
,underline
– general inline formattingclean
– removes all inline formattingh1
,h2
, ...,h6
– headings, in default toolbar only h1-h4 headings are displayedlink
– link editorblockquote
– blockquotesub
,sup
– super and sub scriptsvideo
,image
– video and image embedsunorderedList
,orderedList
– ul and ol tagsalignCenter
,alignLeft
,alignRight
– controls text-aligncode
andcodeBlock
– inline and block code
You can add, remove and configure controls arrangement in toolbar with controls
prop:
To configure sticky toolbar properties set following props:
sticky
– set to false to make toolbar stay at the topstickyOffset
– top property, used with sticky position, use it to offset elements with fixed position, for example, Mantine docs website has 60px header, in this case you should set stickyOffset to 60
Images and videos embeds
Images upload
RichTextEditor will handle images upload in following situations:
- Image button click in toolbar
- Image was pasted from clipboard into editor
- Image was dropped into editor
To set up images upload add onImageUpload
function:
Important! If you do not provide onImageUpload
all images will be converted to
base64 format. In most cases this is not a valid option to store images so make sure you provide onImageUpload
if you are planning to use images.
Mentions
RichTextEditor comes with quill-mentions plugin.
To add mentions support, add provide quill-mentions configuration to mentions
prop:
Extra modules
You can provide any amount of extra modules. Note that it is required to memoize modules object:
Read only
When editor is readonly state, user cannot edit content, toolbar is hidden:
Keyboard shortcuts
⌘ + B
/Ctrl + B
– toggle bold format in current selection⌘ + I
/Ctrl + I
– toggle italic format in current selection⌘ + U
/Ctrl + U
– toggle underline format in current selection⌘ + K
/Ctrl + K
– add link to current selection⌘ + option + 1
/Ctrl + Alt + 1
– toggle heading at current line, valid for 1-6 headings
Get editor ref
Server side rendering
Quill does not support server side rendering as it relies on browser API. To make component work on server you will need to create a wrapper component with additional checks.
General strategy:
Usage with Next.js
To make component work with Next.js use dynamic module:
Then when you want to use RichTextEditor import your component instead: