How to apply style or trait to parent or child element of selected component
@obrazkow You can access the parent like this: component.parent(); and for the children: const collection = component.components();Also i have such problem with Trait, i cannot update src for img. cheers!
Read full answer below βQuestion
For example i have component image that wrapped in div. I want to style image with multiple properties(horizontal position, border-radius, etc) When update horizontal position, need to update current element - div When update border-radius, need to update child element - img. Also i have such problem with Trait, i cannot update src for img. I added listener at Trait and on change i apply value on img, then div and img had src together, but it's bad solution. export default (editor) => { editor.TraitManager.addType('image', { onEvent({ elInput, component, event }) { component.view.el.querySele...
Answers (3)
@obrazkow You can access the parent like this: component.parent(); and for the children: const collection = component.components();Also i have such problem with Trait, i cannot update src for img. cheers!
With your solution trait don't know src value and input will be empty at init editor phase. i do not understand what you are talking about!What do you think about my solution with override target in init method you are treating a very simple use case with an advanced solution, and i do not personal...
@pouyamiralayi that's exactly what I did, but with such solution selected component have attribute or style that need only for child component.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1889
How to append a child component at required position/index
For example, I have a parent component and this parent component has 4 child components. Here with trait functionality, I want to move the...
Issue #1388
Update the style of selected component
I'm trying to update the css of selected element. Example: Selected element: <div id="inul" class='class1'>Hello</div> the above code was r...
Issue #3346
Can I develop my own stylemanager and bind the properties conveniently?
I want to build my own stylemanager useing some UI framework like Element-UI to make a beauty UI quickly. But how can I bind the properties...
Issue #917
Custom style properties per element
Is it possible to have custom style property UI per element. For example, consider that I want the font-size to be shown as textbox for tex...
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
Lighthouse for GrapesJS: Audit Accessibility and SEO Without Leaving the Editor
Live WCAG 2.1/2.2 accessibility auditor + SEO manager for GrapesJS. Every finding is bound to the exact component β click to select, then one-click fix.
Tutorial
GrapesJS DevTools: A Developer Panel Inside Your Editor
If you've ever debugged GrapesJS with console.log(editor.getSelected()) and a dozen throwaway event listeners β this post is for you.
Tutorial
How We Built Composeit in Record Time Using GrapesJS Shadcn
Bypass foundational builder boilerplate and focus on what truly matters.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.