How to apply style or trait to parent or child element of selected component
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.querySelector('img').src = elInput.value
},
});
}
`
Can you advice me solution ?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.
editor.DomComponents.addType('image', {
model: {
defaults: {
traits: ['src']
}
}
})
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 personally recommend defining custom trait for a case like this. cheers!
@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 #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...
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...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.