Rich text editor
Tiptap based rich text editor
Source
LLM docs
Docs
PackageIcon
License
Installation
Install with yarn:
After installation import package styles at the root of your application:
TipTap editor
The @mantine/tiptap package provides a UI for Tiptap. The RichTextEditor component
works with the Editor instance of tiptap.
This means that you have full control over the editor state and configuration
with the useEditor hook.
In other words, the RichTextEditor component does not manage state for you;
controls just execute operations on the Editor instance. If you want to
implement something that is related to state or component value (for example, controlled mode, value transforms to HTML/Markdown),
you should look for documentation on the tiptap.dev website.
Usage
Subtle variant
variant="subtle" removes borders from the control groups, makes controls
larger, and reduces spacing of the toolbar:
Controlled
To control the editor state, create a wrapper component and pass the onChange handler
to the useEditor hook:
Controls and extensions
Some controls require installation of additional Tiptap extensions.
For example, if you want to use RichTextEditor.Superscript control, you will need to install @tiptap/extension-superscript package:
Included with @tiptap/starter-kit (should be installed by default):
RichTextEditor.H1RichTextEditor.H2RichTextEditor.H3RichTextEditor.H4RichTextEditor.H5RichTextEditor.H6RichTextEditor.BulletListRichTextEditor.OrderedListRichTextEditor.BoldRichTextEditor.ItalicRichTextEditor.StrikethroughRichTextEditor.ClearFormattingRichTextEditor.BlockquoteRichTextEditor.CodeRichTextEditor.CodeBlockRichTextEditor.HrRichTextEditor.UndoRichTextEditor.RedoRichTextEditor.UnderlineRichTextEditor.Unlink
Controls that require @tiptap/extension-text-align extension:
RichTextEditor.AlignLeftRichTextEditor.AlignRightRichTextEditor.AlignCenterRichTextEditor.AlignJustify
Controls that require @tiptap/extension-color and @tiptap/extension-text-style extensions:
RichTextEditor.ColorPickerRichTextEditor.ColorRichTextEditor.UnsetColor
Other controls with required extensions:
RichTextEditor.Superscriptrequires @tiptap/extension-superscriptRichTextEditor.Subscriptrequires @tiptap/extension-subscriptRichTextEditor.Highlightrequires @tiptap/extension-highlight
Placeholder
To use a placeholder, you will need to install the @tiptap/extension-placeholder package:
Link extension
The @mantine/tiptap package provides a custom Link extension that is required to be used instead of
@tiptap/extension-link in order for the Ctrl + K keyboard shortcut to work:
Text color
To use text color, you will need to install additional packages:
You can use the following controls to change text color:
RichTextEditor.ColorPicker– allows you to pick colors from given predefined color swatches and with the ColorPicker componentRichTextEditor.Color– allows you to apply a given color with one clickRichTextEditor.UnsetColor– clears color styles
Code highlight
To use code highlighting, you will need to install additional packages:
Source code mode
You can use the following control to see and edit the source code of editor content:
RichTextEditor.SourceCode– allows switching on/off source code mode
Tasks
To use tasks, you will need to install additional packages:
Typography styles
By default, RichTextEditor renders content with Typography and some additional styles.
You can disable these styles by setting withTypographyStyles={false}:
Then you will be able to add your own styles either with global styles or with Styles API:
Bubble menu
You can use the BubbleMenu component
with any RichTextEditor controls. The bubble menu will appear near a selection of text:
Floating menu
You can use the FloatingMenu component
with any RichTextEditor controls. The floating menu will appear in an empty line:
Sticky toolbar
Set the sticky prop on the RichTextEditor.Toolbar component to make the toolbar sticky;
control the top property with stickyOffset. For example, on the mantine.dev documentation
website there is a header with var(--docs-header-height) height. In this case, we will need to
set stickyOffset="var(--docs-header-height)" to make the sticky position work correctly with the fixed positioned element.
Editor context
Use the useRichTextEditorContext hook to get the Editor from
the context. This hook can be used to create a custom control or run any operations supported
by the Tiptap editor API.
Custom controls
Use the RichTextEditor.Control component to create custom controls. It supports all
props supported by the button element and has an active prop to indicate active state.
Note that you will need to set the aria-label attribute to make the control visible for screen readers.
Change icons
You can change the icon of a control by setting the icon prop. It accepts a component
that must handle the size prop:
Labels and localization
RichTextEditor supports changing labels for all controls with the labels prop:
Most labels are used to add aria-label and title attributes to controls; some of the labels
can be a function that returns a string. If you do not provide all labels, they will be merged with
the default labels.
All available labels:
Default labels (can be imported from @mantine/tiptap package):