Documentation

Bold

Emphasize selected text with bold.

Try it

Select “Yurich” in the example and click Bold. getHTML() returns <p><strong>Yurich</strong> deserves a little emphasis.</p>. Click again with the same selection to remove bold.

Live example
Example result

Add it to your editor

Import Bold from yurich and add it to the editor’s extensions array. The toolbar calls toggleBold and reads the active state through useIsActive.

import { EditorContent, EditorProvider, Bold, useEditor, useIsActive } from 'yurich';

export function BoldEditor() {
  const editor = useEditor({
    extensions: [Bold],
    initialValue: "<p>Yurich deserves a little emphasis.</p>",
  });
  const active = useIsActive(editor, 'toggleBold');

  return (
    <EditorProvider editor={editor}>
      <button
        type="button"
        aria-pressed={active}
        onMouseDown={event => event.preventDefault()}
        onClick={() => editor.execute('toggleBold')}
      >
        Bold
      </button>
      <EditorContent ariaLabel="Editor" />
    </EditorProvider>
  );
}

Behavior to account for

Mod+B also runs the command. With only a caret, the command leaves the document as it is. When only part of the selection is bold, toggling applies bold to the entire selection.

Features