Skip to content

Conversation

@lukasmasuch
Copy link
Collaborator

@lukasmasuch lukasmasuch commented Nov 8, 2025

Describe your changes

Adds support for configuring shortcuts/hotkeys to trigger buttons (st.button, st.download_button, st.link_button, st.form_submit_button)

Screenshot or video (only for visual changes)

image

GitHub Issue Link (if applicable)

Testing Plan

  • Added unit and e2e tests.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snyk-io
Copy link
Contributor

snyk-io bot commented Nov 8, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-12975/streamlit-1.51.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-12975.streamlit.app (☁️ Deploy here if not accessible)

@lukasmasuch lukasmasuch requested a review from Copilot November 8, 2025 02:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds keyboard shortcut support to button components in Streamlit, allowing users to trigger buttons using keyboard combinations like "Ctrl+K" or "Cmd+N". The implementation spans both the Python backend (shortcut normalization and validation) and the TypeScript frontend (shortcut registration and display).

  • Adds a shortcut parameter to st.button(), st.download_button(), st.link_button(), and st.form_submit_button()
  • Implements shortcut normalization in Python to ensure consistent formatting (lowercase, standardized modifier order)
  • Creates a new React hook (useRegisterShortcut) for keyboard event handling in the frontend
  • Displays shortcut hints as styled <kbd> elements on button labels

Reviewed Changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
proto/streamlit/proto/Button.proto Adds shortcut field (11) to Button message
proto/streamlit/proto/DownloadButton.proto Adds shortcut field (12) to DownloadButton message
proto/streamlit/proto/LinkButton.proto Adds id field (1) and shortcut field (11) to LinkButton message
lib/streamlit/elements/widgets/button.py Implements shortcut normalization, validation, and serialization for all button types
lib/streamlit/elements/form.py Adds shortcut parameter to form submit button
lib/tests/streamlit/elements/button_test.py Adds Python unit tests for shortcut normalization and reserved key validation
frontend/lib/src/hooks/useRegisterShortcut.ts Implements keyboard shortcut registration hook with input field filtering
frontend/lib/src/hooks/useRegisterShortcut.test.tsx Unit tests for the shortcut hook
frontend/lib/src/components/widgets/Button/Button.tsx Integrates shortcut hook and display for regular buttons
frontend/lib/src/components/widgets/DownloadButton/DownloadButton.tsx Integrates shortcut hook and display for download buttons
frontend/lib/src/components/elements/LinkButton/LinkButton.tsx Integrates shortcut hook and display for link buttons
frontend/lib/src/components/elements/LinkButton/BaseLinkButton.tsx Converts to forwardRef to support programmatic clicks via ref
frontend/lib/src/components/widgets/Form/FormSubmitButton.tsx Integrates shortcut hook and display for form submit buttons
frontend/lib/src/components/shared/BaseButton/DynamicButtonLabel.tsx Adds shortcut display logic and formatting
frontend/lib/src/components/shared/BaseButton/DynamicButtonLabel.test.tsx Unit tests for shortcut display formatting
frontend/lib/src/components/shared/BaseButton/styled-components.ts Adds styled components for shortcut badge display
e2e_playwright/st_button.py Adds test button with shortcut
e2e_playwright/st_button_test.py E2E tests for button shortcut display and activation
e2e_playwright/st_download_button.py Adds test download button with shortcut
e2e_playwright/st_download_button_test.py E2E tests for download button shortcut display and activation
e2e_playwright/st_link_button.py Adds test link button with shortcut
e2e_playwright/st_link_button_test.py E2E tests for link button shortcut display and activation
e2e_playwright/st_form.py Adds test form submit button with shortcut
e2e_playwright/st_form_test.py E2E tests for form submit button shortcut display and activation

@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2025

📉 Frontend coverage change detected

The frontend unit test (vitest) coverage has decreased by 0.0000%

  • Current PR: 86.1100% (51619 lines, 7167 missed)
  • Latest develop: 86.1100% (51260 lines, 7118 missed)

✅ Coverage change is within normal range.

📊 View detailed coverage comparison

@lukasmasuch lukasmasuch added the security-assessment-completed Security assessment has been completed for PR label Nov 8, 2025
@lukasmasuch lukasmasuch changed the title Feature/keyboard shortcuts on buttons Allow configuring keyboard shortcuts on buttons Nov 8, 2025
@lukasmasuch lukasmasuch added change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Nov 8, 2025
@jrieke
Copy link
Collaborator

jrieke commented Nov 8, 2025

I removed the "Closes ..." from the GitHub issue since it is about keyboard shortcuts in general, not just for buttons. I think we should keep that issue open a bit longer.

@lukasmasuch
Copy link
Collaborator Author

lukasmasuch commented Nov 8, 2025

I removed the "Closes ..." from the GitHub issue since it is about keyboard shortcuts in general, not just for buttons. I think we should keep that issue open a bit longer.

I would suggest to create a new issue after merging this PR instead to get a better insight on the actual interest in adding more generic hotkeys. Otherwise, we have the same issue as with #5370 where the interest is mixed between the already released header grouping vs the not yet released row spanning. I guess hotkeys on buttons will resolve the majority of use cases already.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 32 out of 50 changed files in this pull request and generated 1 comment.

Comment on lines +23 to +24
// The ID is only needed if a shortcut is provided.
string id = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Can you confirm that 1 has never been used in this proto message before? If it has, then this is not a safe change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it was never used based on the proto history.

@lukasmasuch lukasmasuch enabled auto-merge (squash) November 24, 2025 18:11
@lukasmasuch lukasmasuch disabled auto-merge November 24, 2025 18:11
@lukasmasuch lukasmasuch added the flaky-verify If applied to PR will run flaky test verification workflow label Nov 24, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch removed the flaky-verify If applied to PR will run flaky test verification workflow label Nov 24, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch added the flaky-verify If applied to PR will run flaky test verification workflow label Nov 24, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch removed the flaky-verify If applied to PR will run flaky test verification workflow label Nov 24, 2025
@lukasmasuch lukasmasuch merged commit 03bbb3b into develop Nov 24, 2025
44 of 45 checks passed
@lukasmasuch lukasmasuch deleted the feature/keyboard-shortcuts-on-buttons branch November 24, 2025 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keyboard shortcuts for buttons

5 participants