Issue #2461πŸ’¬ AnsweredOpened December 20, 2019by obrazkow2 reactions

How to apply style or trait to parent or child element of selected component

Quick answerby pouyamiralayi❀ 1

@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)

pouyamiralayiβ€’ December 21, 2019

@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!

pouyamiralayiβ€’ December 21, 2019

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...

obrazkowβ€’ December 21, 2019

@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.

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.