Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Resizable Box Disappears on Component Reselection #6096

Closed
1 task done
kanaihyakumar opened this issue Aug 30, 2024 · 4 comments
Closed
1 task done

BUG: Resizable Box Disappears on Component Reselection #6096

kanaihyakumar opened this issue Aug 30, 2024 · 4 comments
Assignees

Comments

@kanaihyakumar
Copy link

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

  1. Open GrapesJS with the provided HTML code.
  2. Select any component on the canvas to see the bottom resize box.
  3. Click the same component again.
  4. 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
@artf
Copy link
Member

artf commented Aug 31, 2024

I don't see it disappearing if not when you press the click but that is expected as it gets ready to be dragged

@mohamedsalem401 mohamedsalem401 self-assigned this Aug 31, 2024
@kanaihyakumar
Copy link
Author

kanaihyakumar commented Sep 2, 2024

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:

  1. Click on the section directly.
  2. Observe the resizable options displayed.
  3. 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:

  1. When clicking directly on the section, the bottom resizable options are displayed as expected.
  2. 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.

@artf
Copy link
Member

artf commented Sep 6, 2024

Oh ok, I see what you mean now.
I didn't realize there was a column component with selectable: false

@kanaihyakumar
Copy link
Author

kanaihyakumar commented Sep 6, 2024

Trust me, I was lucky that I was able to find this tragic behavior of clicking different places inside section was behaving but different.

@artf artf closed this as completed in bca8dc5 Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants