Skip to main content

RichTextField

A rich text editor with a ready-made toolbar. Use it when users need to write formatted text with headings, lists, links and images, and the content is reported back as an HTML string.

Base
Wrapper over Mantine
Import
{ RichTextField } from '@multiconsult-group-products/design-system'
Source
src/components/RichTextField/RichTextField.tsx
src/components/RichTextField/RichTextField.module.css

Usage​

React
<RichTextField defaultValue="<p>Beskriv omfanget av oppdraget...</p>" />

Props​

Besides the props below, the component accepts style props and standard div attributes. Mantine's RichTextEditor props are not exposed.

PropertyTypeAllowed valuesDefaultDescription
defaultValuestring——Initial content as an HTML string. Read once, when the editor is created — later changes are ignored.
onChange(html: string) => void——Called with the full HTML document on every edit.
withToolbarboolean—trueRenders the toolbar above the content area.
toolbarGroupsPartial<Record<RichTextFieldToolbarGroup, boolean>>formatting · blockType · textColor · alignment · lists · link · image—Switches individual toolbar groups on or off — toolbarGroups={{ blockType: true }}. Every group is on unless named here, except blockType and textColor, which are off.
colorsRichTextFieldColor[]—7 palette swatchesSwatches offered by the text-colour control. The default set is darkGrey[8], blue[6], green[7], red[7], orange[7], yellow[7], purple[6].
contentLabelstring—'Tekstinnhold'Accessible name of the editable area.
labelsPartial<RichTextFieldLabels>—Norwegian textsOverrides any of the editor's texts: Mantine's control labels (boldControlLabel, …) plus the custom controls' (blockTypeLabel, insertImageLabel, imageTooLargeError, …). Only the keys given are replaced.

Three controls are built here and have no Mantine equivalent. The block type dropdown offers paragraph and heading levels 1–3. The text colour control opens a swatch popover. The image control opens the file browser and inserts the chosen file, up to 2 MB, as a data URI — there is no upload endpoint.

Accessibility​

Toolbar controls are labelled through labels. The defaults are Norwegian; an app in another language passes its own through labels, and the swatch names through colors.

Inserting an image opens a modal with an alternative text field. The field may be left empty for purely decorative images. Set contentLabel when a page has more than one RichTextField, so each editable area has a distinct name.

Theme-wide requirements are covered in Accessibility.