Issue #2621Opened March 4, 2020by yuzhva1 reactions

[Bug] editor.Panels.addPanel duplicate buttons

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, 20201 reactions

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, 20200 reactions

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

hellocaioJune 25, 20200 reactions

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...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.