grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Toolbar on hover

Open yashvirsoftobiz opened this issue 8 years ago • 9 comments

@artf how can we show toolbar on hover. Currently toolbar is open when we select any element but I want to show it on hover. Any help would be appreciated. toolbarpostion

yashvirsoftobiz avatar Sep 17 '18 16:09 yashvirsoftobiz

The only way I can help you here is to tell you to check this command https://github.com/artf/grapesjs/blob/dev/src/commands/view/SelectComponent.js (id of the command: select-comp) which is responsible for showing the toolbar. So you can try to use Commands API to extend it

artf avatar Sep 17 '18 18:09 artf

@YashPrince Hi, were you able to solve this? I need a similar implementation

sakshigarg9 avatar Mar 04 '19 07:03 sakshigarg9

@sakshigarg9 ,

editor.Commands.extend('select-comp', {
        onHovered(em, component) {
          const trg = component && component.getEl();
          if (trg) {
            const pos = this.getElementPos(trg);
            this.updateBadge(trg, pos);
            this.updateToolbar(component); // show toolbar
            this.updateHighlighter(trg, pos);
            this.showElementOffset(trg, pos);
          }
        },
      });

limbobark avatar Sep 09 '19 04:09 limbobark

This doesn't seem to work anymore

ashercoren avatar Mar 03 '21 17:03 ashercoren

I just figured out solution with invoking select event on editor, it's doing slightly more than opening toolbar (additionally selects component), but for my case its ok.

editor.Commands.extend('select-comp', {
    onHovered(em, component) {
        if (component && component.getEl()) {
            if (!editor.getSelected()) {
                editor.select(component);
            } else if (editor.getSelected().getId() !== component.getId()) {
                editor.select(component);
            }
        }
    },
});

zauchad avatar Feb 15 '22 10:02 zauchad

this.updateToolbar(component); // show toolbar -- it is not showing the toolbar. this.updateHighlighter(trg, pos); -- this is throwing the error in reactjs application. Please let me know, is there anyone made changes for this?

@artf

surya492 avatar Mar 07 '22 16:03 surya492

I just figured out solution with invoking select event on editor, it's doing slightly more than opening toolbar (additionally selects component), but for my case its ok.

editor.Commands.extend('select-comp', {
    onHovered(em, component) {
        if (component && component.getEl()) {
            if (!editor.getSelected()) {
                editor.select(component);
            } else if (editor.getSelected().getId() !== component.getId()) {
                editor.select(component);
            }
        }
    },
});

Additionally, there is no block name visible on hover

vladninja avatar Mar 10 '22 12:03 vladninja

@vladninja- Thank you for reply. but I'm looking for only onHover. in my case it is not acceptable to select event for hover event.

surya492 avatar Mar 10 '22 19:03 surya492

@artf Maybe something changed from your last comment from 2018? I am also trying to find a solution that will show a toolbar with actions, but without calling a "select-comp" command.

vladninja avatar Apr 28 '22 14:04 vladninja