Custom traits are not loading inside a custom block
Your component has inner components, so if you select one of those, you will see traits of those components, not event-block. If you properly select event-block, you'll see your traits. <img width="856" alt="Image" src="https://github.com/user-attachments/assets/a0913237-02f9-44f8-af51-6d151b618a37" /> and FYI, this i...
Read full answer below βQuestion
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
Version 133.0.6943.98
Reproducible demo link
https://codesandbox.io/p/sandbox/loving-breeze-mdls43?file=%2Findex.js%3A77%2C6
Describe the bug
Iam trying to add some custom triats to my block unfortunately i can only see the default triats [id,title] my block have few html code but if i remove all the html code and put only one string like hellow world without any html in component property the triats will show
components: `
<h2 class="text-2xl font-bold text-gray-800" data-event-title>
Event Name
</h2>
<p class="text-gray-600 mt-2">
Start Date: <span data-event-start>YYYY-MM-DD</span>
</p>
<p class="text-gray-600">
End Date: <span data-event-end>YYYY-MM-DD</span>
</p>
`, when do like this it traits will not come
but
components: `
Hello world
`,
if i put like this all my triats will come
this is my entire block code
const myEventBlockPlugin = (editor, options = {}) => {
editor.Components.addType("event-block", {
model: {
defaults: {
tagName: "div",
draggable: true,
droppable: false,
attributes: { class: "p-4 bg-white shadow-lg rounded-lg text-center" },
components: `
<h2 class="text-2xl font-bold text-gray-800" data-event-title>
Event Name
</h2>
<p class="text-gray-600 mt-2">
Start Date: <span data-event-start>YYYY-MM-DD</span>
</p>
<p class="text-gray-600">
End Date: <span data-event-end>YYYY-MM-DD</span>
</p>
`,
traits: [
{
name: "event-title",
label: "Event Name",
type: "text",
changeProp: true,
},
{
name: "event-start",
label: "Start Date",
type: "date",
changeProp: true,
},
{
name: "event-end",
label: "End Date",
type: "date",
changeProp: true,
},
],
props: {
"event-title": "Event Name",
"event-start": "YYYY-MM-DD",
"event-end": "YYYY-MM-DD",
},
},
init() {
this.on("change:event-title", this.updateTitle);
this.on("change:event-start", this.updateStartDate);
this.on("change:event-end", this.updateEndDate);
},
updateTitle() {
const title = this.get("event-title");
this.view.el.querySelector("[data-event-title]").innerText = title;
},
updateStartDate() {
const startDate = this.get("event-start");
this.view.el.querySelector("[data-event-start]").innerText = startDate;
},
updateEndDate() {
const endDate = this.get("event-end");
this.view.el.querySelector("[data-event-end]").innerText = endDate;
},
},
});
editor.Blocks.add("event-block", {
label: "Event Block",
content: { type: "event-block" },
category: "Basic",
});
};
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (2)
Your component has inner components, so if you select one of those, you will see traits of those components, not event-block.
If you properly select event-block, you'll see your traits.
<img width="856" alt="Image" src="https://github.com/user-attachments/assets/a0913237-02f9-44f8-af51-6d151b618a37" />
and FYI, this
this.view.el.querySelector("[data-event-end]").innerText = endDate;
is only updating the view of the component, so it does not affect the HTML code to export.
Thanks for reporting this, @gopukinapp.
The issue with Custom traits are not loading inside a custom block appears to be a race condition or state management timing problem. This typically happens when component lifecycle events and DOM modifications overlap, creating an inconsistent state.
What to try:
- Add a setTimeout wrapper to ensure the DOM has settled:
setTimeout(() => {
// your operation here
}, 0);
-
Check initialization order β make sure components are fully loaded before you interact with them
-
Use the editor's event system β listen to completion events:
editor.on('component:mount', (component) => {
// safe to interact with component here
});
Recommended next steps:
- Test with the latest GrapesJS version if you haven't
- Provide a minimal reproducible example (CodeSandbox) β this helps the team identify the root cause faster
- Include GrapesJS version, browser, and console errors in your report
Related Questions and Answers
Continue research with similar issue discussions.
Issue #6152
CSS added via custom code persists after custom code component is removed
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? any Reproducible demo link https://grapesj...
Issue #4601
update() of custom types added to StyleManager is no more triggered when switching between some targets.
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chromium 104 Reproducible demo link https:...
Issue #5232
Worker - Headless "document is not defined"
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? 114.0.5735.133 Reproducible demo link Impo...
Issue #4897
component:styleUpdate / component:styleUpdate:propertyName not fired
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Edge 109.0.1518.70 Reproducible demo link...
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.