Adding multiple text type traits
Got the solution. we need to extend type text in traits. Thankyou. editor.DomComponents.addType('paraJustify', { isComponent: el => ((el.attributes && el.attributes.paraJustify && el.attributes.paraJustify.value)), extend: 'text', model: { defaults: { traits: [ { type: 'select', options: [ { value: 'text-align:center'...
Read full answer below ↓Question
Whenever i am trying to add multiple traits of type text with all different conditions and on different tags/attributes but it will take only last one at every traits conditions.
Please help me out with the solution.
Below is the code
editor.DomComponents.addType('text', {
isComponent: el =>( (el.attributes&&el.attributes.paraJustify&&el.attributes.paraJustify.value) ),
model: {
defaults: {
traits: [
{
type: 'select',
options: [
{ value: 'text-align:center', name: 'Center' },
{ value: 'text-align:left ', name: 'Left' },
{ value: 'text-align:right', name: 'Right' },
{ value: 'text-align:justify', name: 'Justify' },
],
label: 'align',
name: 'style',
},
],
// To make default style.
// attributes: { style: 'text-align:center' },
},
}
});
editor.DomComponents.addType('text', {
isComponent: el => el.attributes&&el.attributes.bannerBackgroundImage&&el.attributes.bannerBackgroundImage.value,
model: {
defaults: {
traits: [
{
type: 'select',
options: [
{ value: 'background-image:url("https://s.freecharge.in/content/images/egold/egold-banner2.png")', name: 'Original' },
{ value: 'background-image:none; background-color:#ffffff; ', name: 'None' },
],
label: 'Backgroud Image',
name: 'style',
},
],
},
}
});
editor.DomComponents.addType('text', {
isComponent: el => el.attributes&&el.attributes.ctaLocation&&el.attributes.ctaLocation.value,
model: {
defaults: {
traits: [
{
type: 'select',
options: [
{ value: ' left:0px; right:0px; bottom:5px; ', name: 'Original' },
{ value: 'top:0px', name: 'Top' },
],
label: 'CTA location',
name: 'style',
},
{
type: 'select',
options: [
{ value: 'background-color:red', name: 'Red' },
{ value: 'background-color:blue ', name: 'Blue' },
{ value: 'background-color:grey', name: 'Grey' },
{ value: 'background-color:orange', name: 'Orange' },
],
label: 'Background-color',
name: 'style',
// changeProp: 1
},
],
},
}
});Answers (1)
Got the solution. we need to extend type text in traits. Thankyou.
editor.DomComponents.addType('paraJustify', {
isComponent: el => ((el.attributes && el.attributes.paraJustify && el.attributes.paraJustify.value)),
extend: 'text',
model: {
defaults: {
traits: [
{
type: 'select',
options: [
{ value: 'text-align:center', name: 'Center' },
{ value: 'text-align:left ', name: 'Left' },
{ value: 'text-align:right', name: 'Right' },
{ value: 'text-align:justify', name: 'Justify' },
],
label: 'align',
name: 'style',
},
],
// To make default style.
// attributes: { style: 'text-align:center' },
},
}
});Related Questions and Answers
Continue research with similar issue discussions.
Issue #2785
Adding multiple text type traits.
Whenever i am trying to add multiple traits of type text with all different conditions and on different tags but it will take only last one...
Issue #3136
Create one more key in JSON
{ "type": "text", "status": "hovered", "content": "Insert your text here", "attributes": { "id": "ixx2" }, "activeOnRender": 0, "open": fal...
Issue #3732
comment component type do not support adding traits
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
Issue #1002
Please help me in integrating grapesjs with graphQL
Hi Guys, Can you help me out on how to query urlStore, urlLoad instead of using rest api call, we need to use graphQL. In GraphQL we will h...
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
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Tutorial
Embed GrapesJS in Your SaaS: A Weekend Guide
Embed GrapesJS in your SaaS and ship a white-label page builder over a weekend. Honest tradeoffs, real code, and the plugins that close the UX gap.
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
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.