Comment component type do not support adding traits
Question
i am working on a script that add a trait on all the component type , but the comment type do not have the prototype object. code
ddw = editor.DomComponents.getTypes();
for (let i = 0; i < ddw.length; i++) {
ddq = ddw[i].id;
editor.DomComponents.addType(ddq, {
model: editor.DomComponents.getType(ddq).model.extend({
defaults: Object.assign({}, editor.DomComponents.getType(ddq).model.prototype.defaults, {
traits: editor.DomComponents.getType(ddq).model.prototype.defaults.traits.concat([
'hallo'
])
})
})
view: editor.DomComponents.getType('text').view
});}
Answers (4)
@artf
Don't use model.extend/view.extend, those are part of the old API.
This is an example of how properly extend traits on all components
const { Components } = editor;
Components.getTypes().forEach(({ id, model }) => {
Components.addType(id, {
model: {
defaults: {
traits: [ ...model.getDefaults().traits, 'new-trait', ]
},
},
})
});
This is a great solution artf, any tips on how to use this for components that have traits defined in a function?, as per the docs: https://grapesjs.com/docs/modules/Traits.html#add-traits-to-components
Thanks for reporting this, @aliibrahim123.
Thanks for sharing your report about comment component type do not support adding traits. To help the team investigate and prioritize this:
Please provide:
- A minimal reproducible example (CodeSandbox/JSFiddle)
- Your GrapesJS version number
- Browser and OS information
- Any error messages from the browser console
- Steps to reproduce the issue
What helps most:
- Minimal code example (not your full project)
- Screen recording or screenshot showing the issue
- Expected vs actual behavior clearly stated
- GrapesJS configuration you're using
With these details, the maintainers can identify and prioritize a fix much faster. The GrapesJS team is very responsive to well-documented issues.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3500
Remove custom trait by its type.
I have created a custom trait but the name of that trait will be dynamic which is unknown. The problem is that the current removeTrait() on...
Issue #3578
version 0.17.4 the components missing when try to add background image to body
I add domComponents: { storeWrapper: 1 }, when initialize the webeditor, to enable add background image to body. it works fine when use the...
Issue #3388
FEAT: adding indication as a Trait without any input.
I want to add an indication for a trait. For my component, I have the traits: and for the type 'dateformat-indication', I created the type:...
Issue #3546
How can I add the custom left toolbar for Image component similar to text
We want to add a custom toolbar to the image component to be shown at left side (similar to what we show for text component). Please let me...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →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.
Tutorial
GrapesJS vs Webflow vs Builder.io vs Puck: Which Visual Builder to Choose in 2026
A practitioner's 2026 comparison of GrapesJS, Webflow, Builder.io, and Puck — pricing, AI features, lock-in, and a one-line rule for picking the right one
Tutorial
Find the Right GrapesJS Plugin in Seconds: Smarter Discovery Is Live
We're shipping a set of discovery upgrades. New label filters, a proper compatibility switch for GrapesJS vs Studio, one-click and a smarter sort bar.
Tutorial
Why use grapesjs shadcn for your template builder
Skip months of editor plumbing and start with a fully working visual builder — polished UI included.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.