palantir / blueprint

A React-based UI toolkit for the web
https://blueprintjs.com/
Apache License 2.0
20.72k stars 2.18k forks source link

Multiple components with the same hotkeys #3267

Open warpdesign opened 5 years ago

warpdesign commented 5 years ago

Environment

Question

I have a component that is reused twice inside my app:

...
renderHotkeys() {
           return <Hotkeys>
            <Hotkey
                global={true}
                combo="meta + c"
                label="Copy selected files to clipboard"
                onKeyDown={this.onCopy}
            />
}
...

Since renderHotkeys() is called twice, the hotkey is registered twice and appears twice in the hotkeys dialog

This is working as expected, but since the component is mounted twice, the hotkeys appear also twice in the hotkey dialog.

How could I avoid that?

Moving the hotkeys up to the parent component is not really an option since it means moving all the logic inside the parent too.

giladgray commented 5 years ago

this is a limitation of the current API. there's no easy workaround at this time. pulling the hotkey up will be your best bet.