Issue #3305Opened March 3, 2021by RaresVlaiduc11 reactions

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

image image

Answers (2)

Ju99ernautMarch 3, 20219 reactions

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() {} 
});
kerryj89March 26, 20212 reactions

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

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.