Resizable Box Disappears on Component Reselection
Earlier, I needed to be more clearer about the steps to reproduce the issue. Here is the refined steps to produce the issue. Steps to Reproduce the Issue:Click on the section directly.Observe the resizable options displayed.Click in an area within the section where there is a column component(I have added a border to...
Read full answer below βQuestion
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
Chrome
Reproducible demo link
https://jsfiddle.net/kanaihyakumar/oedg76nt/
Describe the bug
Description
When selecting any component on the canvas, it highlights the bottom resize box as per the settings. However, upon clicking the same component again, the resize box disappears.
Steps to Reproduce
- Open GrapesJS with the provided HTML code.
- Select any component on the canvas to see the bottom resize box.
- Click the same component again.
- Observe that the resize box disappears.
Expected Behavior
The bottom resize box should remain visible even after reselecting the same component.
Actual Behavior
The bottom resize box disappears after reselecting the same component.
Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/grapesjs/0.21.12/css/grapes.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/grapesjs/0.21.12/grapes.min.js"></script>
<script src="https://unpkg.com/[email protected]"></script>
<style>
html,
body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<main>
<div id="gjs"></div>
</main>
<script>
const htmlContent = `
<style>
.banner {
height: 480px;
color: #ffffff;
}
.banner__container {
padding-top: 6%;
padding-left: 15%;
padding-bottom: 10%;
}
.banner__headline {
font-family: Figtree;
}
@media (max-width:767px) {
.banner {
height: 350px;
}
.banner__container {
padding-left: 5%;
}
}
@media (max-width:480px) {
.banner {
height: 250px;
}
}
</style>
<section class="banner attribute" style="background-image: linear-gradient(#023f8080, #023f8080), url(https://images.pexels.com/photos/27308359/pexels-photo-27308359/free-photo-of-pigeons-on-a-tree.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1); background-position: top left; background-size: cover; background-repeat: no-repeat;">
<div class="banner__container container-fluid column">
<h2 class="banner__headline mb-4 fs-1">The birds are the eye of someone special</h2>
<a class="banner__button btn button-variable px-5 py-1" role="button">Click</a>
</div>
</section>
`;
const editor = grapesjs.init({
container: '#gjs',
fromElement: true,
height: '100vh',
width: 'auto',
plugins: ['gjs-blocks-basic'],
storageManager: false,
});
editor.DomComponents.addType('section', {
isComponent: el => el.tagName === 'SECTION',
model: {
defaults: {
tagName: 'SECTION',
draggable: 'main',
droppable: false,
highlightable: false,
name: 'Section',
dmode: '',
resizable: {
tl: 0,
tc: 0,
tr: 0,
cr: 0,
cl: 0,
bl: 0,
bc: 1,
br: 0
}
}
}
});
editor.DomComponents.addType('column', {
extend: 'default',
isComponent: el => el.classList && el.classList.contains("column"),
model: {
defaults: {
tagName: 'DIV',
draggable: false,
droppable: true,
attributes: {},
name: 'Column',
editable: true,
hoverable: false,
selectable: false,
layerable: false,
highlightable: false,
removable: false
}
},
});
const mainComponent = editor.setComponents(htmlContent);
let sectionComponent = editor.getComponents().models[0];
editor.on('component:selected', (component) => {
const selected = editor.getSelected();
if (selected) {
selected.set({
draggable: true,
droppable: true,
resizable: {
tl: 0,
tc: 0,
tr: 0,
cl: 0,
cr: 0,
bl: 0,
bc: 1,
br: 0,
},
});
}
});
</script>
</body>
</html>
### Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Answers (4)
Earlier, I needed to be more clearer about the steps to reproduce the issue. Here is the refined steps to produce the issue.
Steps to Reproduce the Issue:
- Click on the section directly.
- Observe the resizable options displayed.
- Click in an area within the section where there is a column component(I have added a border to all elements in the provided video for clarity). Observe the section component is selected but the bottom resizable option is not showing. Video Link
Actual Behavior:
- When clicking directly on the section, the bottom resizable options are displayed as expected.
- However, when clicking on an area where a column component is present, the section is selected but the bottom resizable options are not displayed.
Expected Behavior:
When clicking anywhere inside the section, if the clicked point does not include any selectable component, the section should be selected and the bottom resizable options should be displayed.
Trust me, I was lucky that I was able to find this tragic behavior of clicking different places inside section was behaving but different.
I don't see it disappearing if not when you press the click but that is expected as it gets ready to be dragged
Thanks for reporting this, @kanaihyakumar.
The issue with Resizable Box Disappears on Component Reselection 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 #5990
When you delete a component, duplicate classes between components will be deleted.
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome 126.0.6478.127(Windows) Reproducibl...
Issue #4576
Clicking 'wrap for style' button affects the inner components of other components inside the same text box
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Chrome 104.0.5112.101 Reproducible demo link...
Issue #5319
Undo doesn't refresh class on component
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome V116.0.5845.96 Reproducible demo li...
Issue #4754
Closing `</script>` tag not escaped for script properties
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Version 107.0.5304.122 (64-bit) Rep...
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.