Style Manager Issue.
Hi @Abhisheknanda1344463 did you try to follow my indications here? You don't need to add/remove sectors on each select just play with component properties
Read full answer below ↓Question
Hi @artf I want to hide and show style properties for specific component. After referencing this issue https://github.com/artf/grapesjs/issues/1428
I've write my code this way but it's giving me error -:
export default (editor, config) => {
const sm = editor.StyleManager;
const csm = config.customStyleManager;
// Show Style when shape Divider
editor.on('component:selected', function(component) {
if(component.attributes.type == 'shape-divider') {
sm.addSector('style_options',{
name: 'Style Options',
open: true,
buildProps: ['display','width', 'height', 'color'],
properties: [{
name: 'Visibility',
property: 'display',
type: 'radio',
list: [{
name: 'Visibility',
value: 'inherit'
}, {
name: 'Hidden',
value: 'none'
}],
},{
name: 'Fill Color',
property: 'color'
}]
});
sm.removeSector('layout');
});
editor.on('component:deselected', function(component) {
if(component.attributes.type === 'shape-divider') {
sm.removeSector('style_options');
sm.addSector('layout');
}
})
Could you please help @artf ?
after doing this sm.removeSector('layout'); It's not finding the "style sector" (Layout) object.
What is best possible solution in this case because for shape divider i want to show the specific sector.
Answers (4)
Hi @Abhisheknanda1344463 did you try to follow my indications here? You don't need to add/remove sectors on each select just play with component properties
@artf I've tried that but if i do like this https://github.com/artf/grapesjs/issues/1428#issuecomment-421640559 then it'll show the style sectors in which that properties are present. I want to show my custom only one style sector for specific component like one i've mentioned above. Don't know if you understand my use case. Please Guide me. Thanks
Here a quick example of usage:
const plugin = (editor) => {
const { Components, Blocks, Styles } = editor;
[
{
type: 'simple',
props: {
components: 'Simple component',
},
},{
type: 'special',
props: {
components: 'Special component',
'stylable-require': ['special-style'], // <- this component requires special styles
},
}
].forEach(({ type, props }) => {
Components.addType(type, {
model: {
defaults: props,
}
});
Blocks.add(type, {
label: type,
content: { type },
});
});
Styles.addSector('special',{
name: 'Special sector',
open: true,
properties: [
{
id: 'special-style',
type: 'color',
name: 'My property',
property: 'color',
toRequire: true, // <- This property will show up only if requested by component
}
]
}, { at: 0 });
}
const editor = grapesjs.init({
container: '#gjs',
fromElement: 1,
height: '100%',
storageManager: false,
plugins: [plugin]
});
https://jsfiddle.net/1tvrLqem/1/ As you can see the sector will hide if there are no properties to show
Thanks for reporting this, @Abhisheknanda1344463.
The issue with Style Manager Issue. appears to be a race condition or state management timing problem. This typically happens when component lifecycle events and DOM modifications overlap, creating an inconsistent state.
What to try:
- Add a setTimeout wrapper to ensure the DOM has settled:
setTimeout(() => {
// your operation here
}, 0);
-
Check initialization order — make sure components are fully loaded before you interact with them
-
Use the editor's event system — listen to completion events:
editor.on('component:mount', (component) => {
// safe to interact with component here
});
Recommended next steps:
- Test with the latest GrapesJS version if you haven't
- Provide a minimal reproducible example (CodeSandbox) — this helps the team identify the root cause faster
- Include GrapesJS version, browser, and console errors in your report
Related Questions and Answers
Continue research with similar issue discussions.
Issue #6152
CSS added via custom code persists after custom code component is removed
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? any Reproducible demo link https://grapesj...
Issue #5263
Deleting a component without deleting its corresponding style, will adding new components later cause style conflicts?
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? latest version of Chrome Reproducible demo...
Issue #3564
Unable to refresh the iframe
0.17.19 Are you able to reproduce the bug from the demo? YES What is the expected behavior? I had asked a question regarding iframe refresh...
Issue #3235
"component:update" does not trigger when components are moved
Taken from https://github.com/artf/grapesjs/blob/dev/src/editor/index.js#L33 component:update - Triggered when a component is updated (move...
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 →Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.