marimo icon indicating copy to clipboard operation
marimo copied to clipboard

keyboard shortcuts for buttons

Open mscolnick opened this issue 1 year ago • 3 comments

Discussed in https://github.com/marimo-team/marimo/discussions/612

Originally posted by tfriedel January 20, 2024 I quite liked the example for data labeling. There are buttons to go to the next or previous image. It would be nice to attach keyboard shortcuts to buttons so such a tool could be used without a mouse.

mscolnick avatar Jan 23 '24 04:01 mscolnick

Hi @mscolnick , can I work on this issue ?

rithik56 avatar Jan 24 '24 13:01 rithik56

@rithik56, that would be awesome! Feel free to ping me on Discord if you need any help getting set up

mscolnick avatar Jan 24 '24 13:01 mscolnick

Sure @mscolnick

rithik56 avatar Jan 24 '24 14:01 rithik56

hi @mscolnick, I'd like to help with this. My thoughts so far:

  • add a keyboard_shortcut parameter in Python, so users can call button(keyboard_shortcut='Ctrl+G')
  • add a keyboardShortcut prop for ButtonProps in JSX
  • if keyboardShortcut is present, add a document event listener for keydown which will trigger the button click
  • render the button with the shortcut, so the button will look something like Image Still thinking about the design but yeah.

What do you think? This makes the keyboard shortcut a global listener which I think is the intended effect.

I'm aware of the custom hooks for hotkeys, still checking it out.

Light2Dark avatar Nov 06 '24 04:11 Light2Dark

@Light2Dark that would be great! And what you laid out makes sense.

Rather than modifying the label, could we default tooltip to be the keyboard shortcut if the tooltip is null. If the user wants to add the shortcut to the label, they can do that themselves manually. Thoughts?

mscolnick avatar Nov 06 '24 17:11 mscolnick

great idea, and we can always change it after getting wider feedback. I've made a draft, imo, the keyboard shortcuts should be universal, so working on that + testing.

Light2Dark avatar Nov 08 '24 15:11 Light2Dark