Editor.js Accordion Block

September 6, 2025 · View on GitHub

A customizable Accordion block tool for Editor.js that lets you group and toggle visibility of multiple blocks (headings, paragraphs, tables, images, etc.) under a collapsible title. All styles are customizable

example


Features

  • Group any number of Editor.js blocks under an expandable/collapsible section.
  • Works in both edit and read-only modes.
  • Configurable default expanded state and block count.
  • Fully styleable via CSS overrides.
  • Optional animations.
  • Max block count enforcement.

Installation

npm install editorjs-collapsible-block

or via CDN:

<script src="https://cdn.jsdelivr.net/npm/editorjs-collapsible-block"></script>

Usage

1. Register in Editor.js

import EditorJS from '@editorjs/editorjs';
import Accordion from 'editorjs-collapsible-block';

const editor = new EditorJS({
  holder: 'editor',
  tools: {
    accordion: {
      class: Accordion,
      // optional config
      config: {
        defaultExpanded: true,
        maxBlockCount: 10,
        disableAnimation: false,
        overrides: {
          styles: {
            blockWrapper: 'background-color: lightyellow;',
            blockContent: 'border-left: 2px solid #ccc;',
            lastBlockContent: 'border-bottom: 2px solid #ccc;',
            insideContent: 'padding: 10px;',
          },
        },
      },
    },
  },
});

2. Using in the Editor

  • Title: Editable inline text for the accordion heading.

  • Block count: Number of following blocks to include in the accordion group.

  • Default expanded: Whether the accordion starts open in read mode.

  • Controlled blocks can be any Editor.js block type (header, paragraph, table, list, image, etc.).

3. Saving Data

save() returns:

{
  "type": "accordion",
  "data": {
    "settings": {
      "blockCount": 3,
      "defaultExpanded": true
    },
    "title": "My Accordion"
  }
}

Configuration Options

OptionTypeDescriptionDefault
defaultExpandedbooleanWhether accordion is expanded in read mode by default.true
overrides.classes.wrapperstringExtra CSS classes for the accordion wrapper.""
overrides.classes.settingsstringExtra classes for settings button container.""
overrides.classes.titlestringExtra classes for the titlec.""
overrides.classes.settingsPopoverstringExtra classes for settings popover container.""
overrides.classes.settingsContentstringExtra classes for popover content.""
overrides.classes.settingsBlockConfigstringExtra classes for popover block config wrapper.""
overrides.classes.settingsCheckboxstringExtra classes for settings checkbox input.""
overrides.classes.settingsDelimiterstringExtra classes for popover delimiter element.""
overrides.styles.blockWrapperstringCSS rules applied to .ce-block[data-readonly] .accordion-wrapper.undefined
overrides.styles.blockContentstringCSS rules applied to .ce-block__content when editor is read-only.undefined
overrides.styles.lastBlockContentstringCSS rules applied to the last block’s content.undefined
overrides.styles.insideContentstringCSS rules applied to the content inside the block (.ce-block__content > *).undefined
overrides.settingsIconHTMLElementCustom element for settings icon.undefined
disableAnimationbooleanDisables expand/collapse animations.false
maxBlockCountnumberMaximum allowed block count in accordion.10

FAQ

Why am I using style overrides written only as CSS strings

Because I rely on plain CSS to style only the necessary blocks, without directly manipulating the DOM. This approach helps minimize unexpected bugs. In the future, I plan to add an option to use JavaScript for styling, as it would offer better performance.