Serenity: Shortcut Keys [Hot Keys] for Editor buttons

Created on 3 Sep 2020  路  9Comments  路  Source: serenity-is/Serenity

Hi @volkanceylan @minhhungit

Can you guys please guide me how I can assign a shortcut Key [hotkey] to Editor Button till now I have tried following and it doesn't work. It is very important to get this functionality for the project I am working on.

// *** Add Select Button to Grid Editor ***
            buttons.push({
                title: "Select Items",
                cssClass: "add-button",
                hotkey: "Alt+K",
                onClick: () => {}
});

Thank you for your support

Regards,

Arvind

Most helpful comment

@reach2rv ah I see your comment, try this code

put this on your editor.ts

protected createToolbar(buttons: Serenity.ToolButton[]): void {
            var toolbarDiv = $('<div class="grid-toolbar"></div>').appendTo(this.element);
            this.toolbar = new Serenity.Toolbar(toolbarDiv, { buttons: buttons, hotkeyContext: document.getElementsByTagName('body')[0] });
        }

        getButtons() {
            let buttons = super.getButtons();

            buttons.push({
                title: "Test shortkey",
                hotkey: "alt+k",
                //hotkeyContext: document.getElementsByTagName('body')[0],
                onClick: () => {
                    Q.notifyInfo("Hello");
                }
            })

            return buttons;
        }

All 9 comments

Any suggestions or workaround??

I am not sure about "editor button", what is that

@reach2rv you mean button on inline grid editor ?

image

@reach2rv you mean button on inline grid editor ?

image

yes

@minhhungit

I have tried following code too to make it focusable but onclick and shortcut key still doesn't work

 this.element.find('.add-button').attr("role", "button");
            this.element.find('.add-button').attr("tabindex", "0");
            var addbutton = this.element.find('.add-button');
            $('document').bind('keypress', function (e) {
                var alt = false;
                if (e.keyCode == 18)
                    alt = true;
                if (alt == true && e.keyCode == 75)
                    addbutton.trigger('click');
            });

@reach2rv where did you put the code on?, grid, dialog or inline grid on dialog

inline grid Editor constructor

@reach2rv ah I see your comment, try this code

put this on your editor.ts

protected createToolbar(buttons: Serenity.ToolButton[]): void {
            var toolbarDiv = $('<div class="grid-toolbar"></div>').appendTo(this.element);
            this.toolbar = new Serenity.Toolbar(toolbarDiv, { buttons: buttons, hotkeyContext: document.getElementsByTagName('body')[0] });
        }

        getButtons() {
            let buttons = super.getButtons();

            buttons.push({
                title: "Test shortkey",
                hotkey: "alt+k",
                //hotkeyContext: document.getElementsByTagName('body')[0],
                onClick: () => {
                    Q.notifyInfo("Hello");
                }
            })

            return buttons;
        }

@minhhungit the above code works. I do get a notification. Thank you!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JohnRanger picture JohnRanger  路  3Comments

Akarsh03 picture Akarsh03  路  3Comments

Shraddha996 picture Shraddha996  路  3Comments

chintankukadiya18 picture chintankukadiya18  路  3Comments

dudeman972 picture dudeman972  路  3Comments