BUG: (v0.16.41) Button not set as active on click
Question
Version: v0.16.41
Are you able to reproduce the bug from the demo?
[ ] Yes [x] No
What is the expected behavior?
When I click on a button, the gjs-pn-active class should be added.
Describe the bug detailed
I have 3 buttons for 3 different devices (desktop, tablet and mobile). I have them on a top panel and when I click on them the canvas changes the size but the clicked button is not set as active.
Are you able to attach screenshots, screencasts or a live demo?
[x ] Yes (attach) [ ] No

Answers (2)
Grapesjs requires your commands to have the run and stop functions for them to toggle panel buttons automatically, so maybe that might be the issue:
const cm = editor.Commands;
// grapesjs unable to toggle panel buttons on this command format
cm.add('desktop', e => e.setDevice('Desktop'))
// grapesjs able to toggle panel buttons because of run and stop
cm.add('desktop', {
run(e) {
e.setDevice('Desktop')
},
stop() {}
});
@Ju99ernaut
Thank you for that. Active state is now working for me when creating devices-c panel through grapesjs.init().
const editor = grapesjs.init({
panels: {
defaults : [{
id: 'devices-c', // Responsive view controls
appendTo: '.gjs-toolbar-responsive-views',
buttons: [
{ id: "set-device-desktop", command: { run(e) { e.setDevice('Desktop') }, stop() {}}, className: "fa fa-desktop", active: 1},
{ id: "set-device-tablet", command: { run(e) { e.setDevice('Tablet') }, stop() {}}, className: "fa fa-tablet" },
{ id: "set-device-mobile", command: { run(e) { e.setDevice('Mobile portrait') }, stop() {}}, className: "fa fa-mobile" }
]
}]
}
});
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3310
BUG: Tablet and mobile view not resizing
Version: The one in the demo Are you able to reproduce the bug from the demo? [X] Yes [ ] No What is the expected behavior? Mobile and tabl...
Issue #3295
BUG (v0.16.41): Button component with draggable property is not working properly
Version: v0.16.41 Are you able to reproduce the bug from the demo? [ ] Yes [ ] No What is the expected behavior? When we have a button with...
Issue #3015
BUG: HTML exported from the demo not responsive to screen size
Version: 0.16.22 Are you able to reproduce the bug from the demo? [] Yes [ ] No What is the expected behavior? the exported html should be...
Issue #3291
BUG (v0.16.41): the duplicate icon from the icon toolbar is modifying the original element too
Version: v0.16.41 Are you able to reproduce the bug from the demo? [ ] Yes What is the expected behavior? The elements duplicated not shoul...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.