How to update toolbar of component?
Question

Hi Artf, i was added new command to editable component, update style work well but i don't know how to update this toolbar after component updated (update align icon for example), do you have any suggetion?
` defaultCommands['testCommand'] = {
run(ed) {
var sel = ed.getSelected();
var styles = sel.get('style');
var tbs = sel.get('toolbar');
var tmpTbs = [];
var tmpStyles = {};
tbs.map((tb) => {
if (tb['command'] == 'testCommand') {
switch (styles['text-align']) {
case 'center':
tb['attributes'] = { class: 'fa fa-align-right' };
tmpStyles['text-align'] = "right";
break;
case 'left':
tb['attributes'] = { class: 'fa fa-align-center' };
tmpStyles['text-align'] = "center";
break;
case 'right':
tb['attributes'] = { class: 'fa fa-align-left' };
tmpStyles['text-align'] = "left";
break;
default:
tb['attributes'] = { class: 'fa fa-align-center' };
tmpStyles['text-align'] = "center";
break;
}
}
tmpTbs.push(tb);
})
sel.set({
'style': tmpStyles,
'toolbar': tmpTbs
});
}
};`Answers (2)
You can set a listener on component update
editor.on('component:update', () => {
editor.runCommand('testCommand');
})
Be aware that with var styles = sel.get('style') you get the style of the component and not what is selected in Style Manager (if the component has classes, the css rule will be selected)
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1237
Before you drag and drop the image,there was nothing in assetManager
and I don't know how to set the backgroundImage
Issue #1723
[QUESTION] replacing particular text in dropped component
Hi, I get the value from custom traits from what I entered but I don't know how to change the particular value in dropped component and ren...
Issue #990
How to listen an event for custom component's style update?
@artf @arthuralmeidap @nojacko I have a custom component like, this and i the code looks like https://jsfiddle.net/nganand/n97g7g43/ . How...
Issue #1434
Toolbar Hide text element
@artf Please check you demo page text is hiding under the toolbar. how can we update the toolbar position?
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.