Editor.Panels.addPanel duplicate buttons
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.addButtonAPI 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)
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 (=
Thanks @YUzhva for the report and the solution. I'll try to check this out
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.
Issue #2943
BUG: this.get('content') returns empty string when trying to add custom component type
Version: 0.16.18 Are you able to reproduce the bug from the demo?>> Demo <<< [ X ] Yes [ ] No What is the expected behavior? Expecting this...
Issue #6409
Cannot drag to move components on mobile
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v133 Reproducible demo link https:/...
Issue #5705
Component tools misalign when the editor is resized
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v122 Reproducible demo link https:/...
Issue #5334
Selection of custom component type not working in the canvas
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome, Opera, Edge, etc Reproducible demo...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →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.