grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

[QUESTION] Select and focus an html element from a panel button

Open dmmprog opened this issue 8 years ago • 4 comments

Hi everyone,

Is it possible to set focus in a section html with Grapes, like as an anchor? I have a panel button and it just select the section that I want but not focus to element. Here is the code:

   panel.addButton('options', [{
        id: 'link',
        className: 'fa fa-th-list',            
        command: function linkChap(e) {
            editor.DomComponents.getWrapper().find('section').forEach(model => {
                const current = model.getAttributes()['id'] || '';
                if(current == "chap10"){
                  editor.select(model);   //Here just select the section, but not set focus
                }
              });
        }

Thanks in advance. Regards.

dmmprog avatar Mar 02 '18 17:03 dmmprog

If for focus you mean scrolling the view to the component, unfortunately, there is no such a method, but you can actually implement it by relying on editor.Canvas.getBody().scrollTop

artf avatar Mar 04 '18 12:03 artf

Did you manage to make it work?

Amir2828 avatar Jun 18 '19 13:06 Amir2828

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jun 24 '20 22:06 lock[bot]

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jun 24 '20 22:06 lock[bot]