Skip to content

Commit

Permalink
Merge pull request #10 from taylor-ennen/main
Browse files Browse the repository at this point in the history
Fixed Direct Button Implementation
  • Loading branch information
adriangalilea authored Apr 30, 2024
2 parents 292ac40 + 01845d9 commit fc2da36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'

Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/streamlit_shortcuts/streamlit_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)

0 comments on commit fc2da36

Please sign in to comment.