Issue #3170πŸ’¬ AnsweredOpened December 7, 2020by ThetripGr0 reactions

Add class name from traits

Quick answerby ThetripGr

So i got it working after some more tries, i will try to explain how i got it to work. When you define the trait you can declare a name. When you select option A from the dropdown selection you can track this change on init(), as this.on('change:traitName', this.handleChange);, then all you have to do is write down th...

Read full answer below ↓

Question

Hello, what i am trying to achieve is to have the text component extended by assigning an extra trait named Alignment and deciding through the trait the kind of alignment i wish to do, after that no css should be applied but the appropriate class name should be given to the component. Is there an example of how i could do something like that, i couldn't find something on my own :/ ?

Answers (3)

ThetripGrβ€’ December 7, 2020

So i got it working after some more tries, i will try to explain how i got it to work. When you define the trait you can declare a name. When you select option A from the dropdown selection you can track this change on init(), as this.on('change:traitName', this.handleChange);, then all you have to...

GJSBlockβ€’ May 17, 2026

Thanks for reporting this, @ThetripGr. Great question about Add class name from traits. The recommended approach with StyleManager is to use the event-driven API. Start here: Check the GrapesJS documentation for your specific module Look for the on() event listener method Most operations can be ach...

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.