-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Support programatically showing the hotkeys help dialog #1590
Comments
There's a helper function that's exported: http://github.com/palantir/blueprint/blob/874b757e729576a330ee3a8b67a382c7ff4a312e/packages/core/src/components/hotkeys/hotkeysDialog.tsx#L149 Granted, we should document this better |
I found that, but couldn't call it correctly. What should the argument be
to show global hotkeys?
Also it's not exported at the top level so you have to import with the
whole path.
…On 21 Sep 2017 13:40, "Antoine Llorca" ***@***.***> wrote:
There's a helper function that's exported: http://github.com/palantir/
blueprint/blob/874b757e729576a330ee3a8b67a382c7ff4a312e/packages/core/src/
components/hotkeys/hotkeysDialog.tsx#L149
<https://github.com/palantir/blueprint/blob/874b757e729576a330ee3a8b67a382c7ff4a312e/packages/core/src/components/hotkeys/hotkeysDialog.tsx#L149>
Granted, we should document this better
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1590 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AASJzEaiV3o0S--M8Ft19rMugtklMrvfks5skp-kgaJpZM4Pfi51>
.
|
hmm yeah looks like this is not easily possible 😢. that method @llorca linked is prohibitive to use as you'd need to somehow get the list of global hotkeys yourself, but managing that list is why we built the component in the first place! |
I'm also looking for this functionality. Any chance that we can trigger a fake "shift + ?" event on the document.body and trigger it that way as a stopgap? |
Just wanted to drop by and say I'm also looking for this. Also spent a bit of time trying to figure out how to simulate the keyboard event explicitly. Not entirely sure if this is possible, as I noticed there's an
Can't set the |
@chiubaka (disclaimer: I haven't tried this myself) you might have success with something like our
|
Is it possible to programmatically disable the |
Anyone have any updates on this one? Thanks! |
@tnrich not a drop. would you like to submit some updates? 😄 |
Yeah I'd ideally like to allow some more customizability of the hotkeys
dialog itself as well.
…On Thu, Apr 5, 2018, 2:58 PM Gilad Gray ***@***.***> wrote:
@tnrich <https://github.com/tnrich> not a drop. would you like to submit
some updates? 😄
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1590 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACmqcbbymGDYrKYXfXM7QHLGrgGFSWISks5tlpNfgaJpZM4Pfi51>
.
|
@tnrich got some time to put a PR together? happy to review. |
If anyone is interested, you can open the dialog by generating a fake keyboard with code like this: document.dispatchEvent(new KeyboardEvent('keydown', { which: 47, keyCode: 47, shiftKey: true, bubbles: true })) Note that it will show every shortcuts. To show the shortcuts for a specific element (as if a specific element had focus), replace It's not ideal, but it may help. |
Ideally, we could have an API similar to ContextMenu's imperative API... import { HotkeysDialogSingleton } from "@blueprintjs/core";
HotkeysDialogSingleton.show(); however this is tricky because of the state managed through import { createHotkeysTargetEvents, HotkeysTarget, showHotkeysDialog } from "@blueprintjs/core";
const targetEvents = createHotkeysTargetEvents();
@HotkeysTarget({ events: targetEvents })
export class MyComponent extends React.Component {
...
}
// programmatically show the dialog for this target
// HotkeysTarget will have registered the actions in the "events" objects at render time
showHotkeysDialog(targetEvents.getActions()); where core provides: export function createHotkeysTargetEvents() {
const globalEvents = new HotkeysEvents(HotkeyScope.GLOBAL);
const localEvents = new HotkeysEvents(HotkeyScope.LOCAL);
// HotkeysEvents#getActions() will need to be exposed as a new public method
const getActions = [ ...globalEvents.getActions(), ...localEvents.getActions() ];
return {
globalEvents,
localEvents,
getActions,
};
} it's a little janky but could potentially work, if someone wants to attempt a PR... |
import { HotkeysDialogSingleton } from "@blueprintjs/core";
HotkeysDialogSingleton.show(); definitely makes the most sense to me. I don't see why the same API couldn't be used internally as well? |
@tnrich because we don't know which hotkeys dialog to show (there can be local hotkeys). We could ask the |
@adidahiya makes sense. Maybe each //file 1
<Hotkeys id="quitSaveHotKeys">
<Hotkey label="Quit" combo="ctrl+q" global onKeyDown={handleQuit} />
<Hotkey label="Save" combo="ctrl+s" group="File" onKeyDown={handleSave} />
</Hotkeys>
//file 2
<Hotkeys id="awesomeHotkeys">
<Hotkey
global={true}
combo="shift + a"
label="Be awesome all the time"
onKeyDown={() => console.log("Awesome!")}
/>
<Hotkey
group="Fancy shortcuts"
combo="shift + f"
label="Be fancy only when focused"
onKeyDown={() => console.log("So fancy!")}
/>
</Hotkeys>;
//file 3
HotkeysDialogSingleton.show(); //trigger global hotkeys if it exists
HotkeysDialogSingleton.show("quitSaveHotKeys"); //trigger the quitSaveHotKeys
HotkeysDialogSingleton.show("awesomeHotkeys"); //trigger the awesomeHotkeys Could that work? It seems like it would be a lot simpler than the alternative. |
@tnrich yeah, that could work too... although the id would have to be provided to |
With #4532, it will be possible to programmatically show the hotkeys dialog but this is not documented: import { HotkeysContext } from "@blueprintjs/core";
import { useContext, useEffect } from "react";
function MyComponent() {
const [, dispatch] = useContext(HotkeysContext);
useEffect(() => {
dispatch({ type: "OPEN_DIALOG" });
}, []);
return <div />;
} |
To bump a question from 5 years ago: Is there a way to disable the |
In your own event handler, you can try to call The correct long-term solution probably involves providing a prop to let you disable this behavior explicitly. By the way, are you using |
I'm using |
The Shift-/ combo is not particularly discoverable. It'd be nice if we could include some UI menu option that pops the hotkeys dialog to the user so they can learn the shortcuts. I can't see a way to do this though unfortunately within Blueprint as is currently?
The text was updated successfully, but these errors were encountered: