Issue #3174💬 AnsweredOpened December 9, 2020by ThetripGr1 reactions

Creating a new component type does not inherit the functions of it's parent type

快速解答by ThetripGr1

nvm , I revisited the docs more carefully, I somehow missed this about extending parent functions

Read full answer below ↓

Question

Hello, I am trying to create a new common trait shared among all components by creating the following plugin

function backgroundColors(editor) {
    editor.DomComponents.getTypes().map(type => {
        var model = type.model;

        editor.DomComponents.addType(type.id, {
            model: {
                defaults: {
                    traits: [{
                        type: 'select',
                        options: [
                            { value: 'gjs_bgColor_teal', name: 'Teal' }
                        ],
                        label: 'Background Color',
                        name: 'bgColor',
                        changeProp: 1
                    }].concat(model.prototype.defaults.traits),
                },
                init() {
                    this.listenTo(this, 'change:bgColor', this.handleBgColorChange);
                },
                handleBgColorChange() {
                    alert('background color changed');
                }
            },

        });
    })
}

on another plugin file I am also creating a new component type same way following the docs, called extendedText which uses the text type as it's basis. While the text type has the handleBgColorChange() as shown below

image

the new type branching from text does not

image

how do I pass down the parent type functions?

Answers (2)

ThetripGrDecember 9, 2020

nvm , I revisited the docs more carefully, I somehow missed this about extending parent functions

domc.addType('new-type', {
  extend: 'parent-type',
  extendFn: ['init'], // array of model functions to extend from `parent-type`
  model: {
    init() {
      // do something
    },
  }
});
ClaudeCodeMay 17, 2026

Thanks for reporting this, @ThetripGr.

Great question about Creating a new component type does not inherit the functions of it's parent type. 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.