Issue #2621💬 AnsweredOpened March 4, 2020by yuzhva1 reactions

Editor.Panels.addPanel duplicate buttons

快速解答by yuzhva1

Closing the issue, as I found the other solution: But the issue with editor.Panels.addPanel({ buttons: [] }); still exist (=

Read full answer below ↓

Question

While creating a custom plugin, in case, when editor.Panels.addPanel is using inside plugin function - buttons are duplicated.

Example: https://jsfiddle.net/kncdah8b/

Buttons are not duplicated:

  • when using single Panels.addButton API while loop buttons separately
  • when adding panel after editor const editor = grapesjs.init({}) has been created

Currently, I'm using the next trick to avoid the duplications:

function gjsPlugin(editor) {
  editor.on('load', () => {
    editor.Panels.addPanel({
      id: 'custom-panel',
      el: '.custom-panel',
      buttons: [
        {
          id: 'PANEL_ACTION.EXPT',
          className: 'fa fa-code',
          command: 'export-template',
          attributes: { title: 'View code' }
        }
      ]
    });
  });
}

Answers (3)

yuzhvaMarch 6, 2020

Closing the issue, as I found the other solution:

const panelCustom = editor.Panels.addPanel({
    id: 'panel__custom',
    el: '.panel__custom'
  });

const panelCustomButtons = panelCustom.get('buttons');
panelCustomButtons.add(topBarButtonsCenter);

But the issue with editor.Panels.addPanel({ buttons: [] }); still exist (=

artfMarch 7, 2020

Thanks @YUzhva for the report and the solution. I'll try to check this out

hellocaioJune 25, 2020

Same here, I tested the panels example (Getting started) in the docs too and keep getting duplicate buttons. @yuzhva solution works, thanks :)

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.