Issue #4376πŸ’¬ AnsweredOpened June 13, 2022by iamqinglong0 reactions

Unselected custom component will also listen to event 'styleable:change'

Quick answerby artf

Hi @iamqinglong this is the expected behavior as you're creating a listener on the editor model, but you can check the selected component in this way

Read full answer below ↓

Question

GrapesJS version

  • I confirm to use the latest version of GrapesJS

What browser are you using?

chrome 100

Reproducible demo link

https://grapesjs.com/demo.html

Describe the bug

How to reproduce the bug?

  1. Drop two or more custom component <img width="1230" alt="Screen Shot 2022-06-10 at 3 11 54 PM" src="https://user-images.githubusercontent.com/48402616/173286267-09325ccd-6475-4b81-84ca-790a3f1b168b.png">
  2. Restyle either of the component
  3. The other unselected component will also listen to 'styleable:change' event <img width="1438" alt="Screen Shot 2022-06-10 at 3 10 29 PM" src="https://user-images.githubusercontent.com/48402616/173286325-4bd75e2e-21ef-4e3b-9d83-a78aea0674b0.png">

What is the expected behavior? The unselected component shouldn't listen to 'styleable:change' event of selected component

What is the current behavior? The unselected component listen to 'styleable:change' event of selected component

If is necessary to execute some code in order to reproduce the bug, paste it here below:

view: {
    init() {
        this.listenTo(this.em, `styleable:change`, (args, property) => {
          console.log(args,property)
        })
      }
}

Code of Conduct

  • I agree to follow this project's Code of Conduct

Answers (2)

artfβ€’ June 17, 2022

Hi @iamqinglong this is the expected behavior as you're creating a listener on the editor model, but you can check the selected component in this way

init() {
    const component = this.model;
    this.listenTo(this.em, `styleable:change`, (args, property) => {
        if (editor.getSelected() === component) {
            console.log(args, property);
        }
    });
}
ClaudeCodeβ€’ May 17, 2026

Thanks for reporting this, @iamqinglong.

Great question about Unselected custom component will also listen to event 'styleable:change'. The recommended approach with StyleManager is to use the event-driven API.

Start here:

  1. Check the GrapesJS documentation for your specific module
  2. Look for the on() event listener method
  3. Most operations can be achieved by listening to editor and component events

Common patterns:

// Listen for changes
editor.on('change', () => console.log('something changed'));

// Component lifecycle
editor.on('component:mount', (c) => console.log('component ready', c));
editor.on('component:update', (c) => console.log('component updated', c));

If you're still stuck:

  • Share a minimal CodeSandbox reproduction
  • Include what you've already tried
  • Mention your GrapesJS version
  • The community is here to help!

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 β†’

Related tutorials

In-depth guides on the same topic.

All tutorials β†’

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.