BUG: Resizable Box Disappears on Component Reselection
kanaihyakumar opened this issue · 4 comments
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/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/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/grapesjs-blocks-basic@1.0.1"></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
I don't see it disappearing if not when you press the click but that is expected as it gets ready to be dragged
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.
Oh ok, I see what you mean now.
I didn't realize there was a column
component with selectable: false
Trust me, I was lucky that I was able to find this tragic behavior of clicking different places inside section was behaving but different.