diff --git a/README.md b/README.md index 72a06da..dd224f9 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ import streamlit_shortcuts def delete_callback(): st.write("DELETED!") -streamlit_shortcuts.button("delete", on_click=delete_callback, shortcut,="Ctrl+Shift+X") +streamlit_shortcuts.button("delete", on_click=delete_callback, shortcut="Ctrl+Shift+X") ``` 🥱 Old @@ -40,12 +40,12 @@ add_keyboard_shortcuts({ The 'Ctrl+Shift+X' combination will trigger "Another Button". ## Keys -- Modifiers: 'Control', 'Shift', 'Alt', 'Meta' ('Cmd' on Mac or 'Win' on Windows, thanks to @toolittlecakes) +- Modifiers: 'Ctrl', 'Shift', 'Alt', 'Meta' ('Cmd' on Mac or 'Win' on Windows, thanks to @toolittlecakes) - Common Keys: 'Enter', 'Escape', 'Space' - Arrow Keys: 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown' Examples of Key Combinations: -- 'Control+Enter' +- 'Ctrl+Enter' - 'Shift+ArrowUp' - 'Alt+Space' @@ -62,6 +62,8 @@ Contributions are welcome! If you have suggestions for improvements or bug fixes @quantum-ernest - Improved usage ergonomics +@taylor-ennen - Fixed usage `flow` of code + ## Credits Solution seen on: https://github.com/streamlit/streamlit/issues/1291 diff --git a/src/streamlit_shortcuts/streamlit_shortcuts.py b/src/streamlit_shortcuts/streamlit_shortcuts.py index 4f1beb4..3e7d2a6 100644 --- a/src/streamlit_shortcuts/streamlit_shortcuts.py +++ b/src/streamlit_shortcuts/streamlit_shortcuts.py @@ -12,12 +12,12 @@ def add_keyboard_shortcuts(key_combinations: dict[str, str]): Add keyboard shortcuts to trigger Streamlit buttons. Keys: - - Modifiers: 'Control', 'Shift', 'Alt' + - Modifiers: 'Ctrl', 'Shift', 'Alt' - Common Keys: 'Enter', 'Escape', 'Space' - Arrow Keys: 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown' Examples of Key Combinations: - - 'Control+Enter' + - 'Ctrl+Enter' - 'Shift+ArrowUp' - 'Alt+Space' @@ -57,6 +57,7 @@ def add_keyboard_shortcuts(key_combinations: dict[str, str]): components.html(js_code, height=0, width=0) -def button(label: str, shortcut: dict[str, str], on_click: Callable[..., None]): +def button(label: str, shortcut: str, on_click: Callable[..., None]): + shortcut={shortcut: label} st.button(label=label, on_click=on_click) add_keyboard_shortcuts(shortcut)