Skip to content
A plugin for adding rich formatting controls -
JavaScript HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis.yml Update Jan 26, 2018

DraftJS RichButtons Plugin

npm version Build Status npm downloads

This is a plugin for the draft-js-plugins-editor. This plugin allows you to add essential rich formatting buttons (inline and block styles) to your plugins-enabled editor.


First instantiate the plugin:

import createRichButtonsPlugin from 'draft-js-richbuttons-plugin';

const richButtonsPlugin = createRichButtonsPlugin();

Now get any desired components for inline or block formatting buttons from the instance:

/* import only the ones you need; all available shown */
const {   
  // inline buttons
  ItalicButton, BoldButton, MonospaceButton, UnderlineButton,
  // block buttons
  ParagraphButton, BlockquoteButton, CodeButton, OLButton, ULButton, H1Button, H2Button, H3Button, H4Button, H5Button, H6Button
} = richButtonsPlugin;

Render these where desired in your component:

<div className="myToolbar">


Custom Block Types or Inline Styles

Button components behaving exactly like those above can be obtained for any custom block or inline style types used in your draft instance, by invoking either createStyleButton or createBlockButton:

const { createStyleButton, createBlockButton } = richButtonsPlugin;

// create a custom inlinestyle button
const RedStyleButton = createStyleButton({style: 'RED', label: 'Red'});

// create a custom block-type button
const BorderedBlockButton = createBlockButton({type: 'BorderedBox', label: 'LittleBox'}); 

See more complete code in the included example.

Rendering Your Own Buttons

The default buttons are intentionally plain, but will pass the needed props down to their child, allowing you to customize rendering to your needs.

Props passed to both inline and block buttons:

  • isActive (bool) - true if style / blocktype active in selection
  • label (string) - default label

Props unique to inline buttons:

  • toggleInlineStyle (func) - to be attached to your click event
  • inlineStyle (string) - the draft code for the style
  • onMouseDown (func) - attach this to the onMouseDown event of your custom controls; important for preventing focus from leaving the editor when toggling an inline style with a click

Props unique to block buttons:

  • toggleBlockType (func) - to be attached to your click event
  • blockType (string) - the draft code for the block type


  Stateless component for inline style buttons, using the passed props as well as a custom prop "iconName"
const MyIconButton = ({iconName, toggleInlineStyle, isActive, label, inlineStyle, onMouseDown, title}) =>
  <a onClick={toggleInlineStyle} onMouseDown={onMouseDown}>
      className={`fa fa-${iconName}`}
      title={title ? title : label}
      style={{ color: isActive ? '#000' : '#777' }}

The above presentational component could then be used this way:

  <MyIconButton iconName="bold"/>
  <MyIconButton iconName="italic" title="Italicize" />

Key Bindings

The plugin automatically applies default key bindings from draft's RichUtils, including Tab / Shift-Tab behavior for nested lists.



You can’t perform that action at this time.