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
[QUESTION] 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
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
Big Updates: TinyMCE 8 and Placeholder 2.0 for GrapesJS
In May we shipped major updates to two of our most popular GrapesJS plugins β TinyMCE Inline Text Editor and Placeholder.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.