Issue #3506Opened May 31, 2021by iabhiyaan5 reactions

FEAT: add click event on blocks

Question

editor.on('block:click', (block) => {
  console.log(block)
})

Or Is there any way to listen for click event in block ?

Answers (2)

artfJune 21, 20214 reactions

Well you can actually make use of custom render from blocks to apply custom DOM events.

blockManager.add('some-block-id', {
  // ... block definition
  render: ({ model, el }) => {
   el.addEventListener('click', () => {
     console.log('block', model)
   })
  },
});
YyueeiWYJune 6, 20211 reactions
Code SnippetTEXT
<pre>
    editor.on('component:selected', (some, argument) => {
      console.log(some, argument);
    })
</pre>

https://grapesjs.com/docs/api/editor.html#available-events

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.