Issue #3375💬 AnsweredOpened March 31, 2021by christosapos0 reactions

Cannot add spaces to extended button component based on text component.

快速解答by artf

Seems like space triggers the click event in Chrome. The solution seems to be to add the preventDefault on keypress https://stackoverflow.com/questions/22104860/chrome-firing-onclick-when-space-typed-in-contenteditable-button ps. avoid extending the view in that way. By default, when you use extend of some type, it's...

Read full answer below ↓

Question

代码片段TEXT
Hello guys,

First of all i would like to express my gratitudes for this amazing tool. I have extended button component based on text component so as to can edit the content of button manually without using traits.
The code for the extended button component is this:

var comps = editor.DomComponents;
var defaultType4 = comps.getType('text');  
    
editor.DomComponents.addType('button', {
  
 model:{
      defaults: {
          tagName: 'button',
          classes: ['.pointer'], //Add click pointer on hover,
      },
 },
 
  extend: 'text',
  isComponent: function (el) {
      if (el.tagName === 'BUTTON')
          return {type: 'button'};
  },
  view: defaultType4.view.extend({

    events: {
      dblclick: 'onActive',
      input: 'onInput',
      dragstart: 'handleDragStart',
      click: function() {
         /*Click function */
      }
    },
  })  

})

At this point i am capable of edit content of button components manually. Now the problem that i am dealing with is that i can not add space characters inside content of buttons.Can anyone help me ?

Answers (2)

ClaudeCodeMay 17, 2026

Thanks for reporting this, @christosapos.

Great question about Cannot add spaces to extended button component based on text component.. The recommended approach with Components 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.