-
Notifications
You must be signed in to change notification settings - Fork 4k
Add icon_position support for button-like components
#13150
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
Add icon_position support for button-like components
#13150
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
icon_position support for button-like components
There was a problem hiding this 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 an icon_position parameter to button-like components (st.button(), st.download_button(), st.link_button(), st.page_link(), and st.form_submit_button()), allowing developers to position icons on either the left (default) or right side of the button label.
Key Changes:
- Added
icon_positionparameter with validation to all button-like components (default:"left", accepts"left"or"right") - Updated protobuf definitions to include the new field
- Modified frontend components to conditionally render icons based on the position parameter
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
proto/streamlit/proto/*.proto |
Added icon_position field to Button, LinkButton, DownloadButton, and PageLink protobuf messages |
lib/streamlit/elements/widgets/button.py |
Added IconPosition type, validation function, and icon_position parameter to all button-like commands |
lib/streamlit/elements/form.py |
Added icon_position parameter to form submit button methods |
frontend/lib/src/components/shared/BaseButton/DynamicButtonLabel.tsx |
Added conditional rendering logic to position icons left or right of the label |
frontend/lib/src/components/widgets/*.tsx |
Updated Button, DownloadButton, FormSubmitButton, and LinkButton to pass iconPosition prop |
frontend/lib/src/components/elements/PageLink/PageLink.tsx |
Added custom icon positioning logic for PageLink component |
lib/tests/streamlit/**/*_test.py |
Added Python unit tests for icon position validation and serialization |
frontend/lib/src/components/shared/BaseButton/DynamicButtonLabel.test.tsx |
Added frontend unit tests for icon positioning |
e2e_playwright/st_*_test.py |
Added E2E snapshot tests for icon positioning across all button types |
e2e_playwright/st_*.py |
Added test apps demonstrating icon positioning with various button types |
frontend/lib/src/components/shared/BaseButton/DynamicButtonLabel.tsx
Outdated
Show resolved
Hide resolved
frontend/lib/src/components/widgets/DownloadButton/DownloadButton.tsx
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
sfc-gh-bnisco
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution @SiddhantSadangi !
I haven't yet taken an in-depth look at the code, but I wanted to point your attention to the amount of merge conflicts that are pending. Please consider rebasing or merging on latest develop and fixing the merge conflicts, then pushing those updates to this branch. Thanks in advance!
|
@sfc-gh-bnisco - conflicts resolved ✅ |
There was a problem hiding this 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 26 out of 26 changed files in this pull request and generated 5 comments.
There was a problem hiding this 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 26 out of 26 changed files in this pull request and generated 5 comments.
frontend/lib/src/components/widgets/DownloadButton/DownloadButton.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 28 out of 28 changed files in this pull request and generated 2 comments.
There was a problem hiding this 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 28 out of 148 changed files in this pull request and generated no new comments.
SummaryThis PR adds an Code QualityOverall the implementation is clean, well-typed, and follows existing patterns for buttons and links.
I did not spot logic bugs, dead code, or style issues; the changes align with existing patterns for buttons and links. Test CoverageTest coverage for the new behavior is strong across Python, TypeScript, and e2e layers.
Given the above, the new feature is covered at unit level, integration/component level, and full-stack/e2e visual level. Backwards Compatibility
I don't see breaking changes for existing apps; the added functionality is strictly additive with safe defaults. Security & Risk
Recommendations
VerdictAPPROVED: The implementation is clean, well-tested across layers, backwards compatible, and the remaining follow-ups are minor documentation/build considerations rather than blockers. This is an automated AI review. Please verify the feedback and use your judgment. |
|
Thanks for the contribution and iterations @SiddhantSadangi! I did another revision and updated the snapshot files. I'm going to have another teammate take a look at this for final review. |
lukasmasuch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation LGTM 👍 but two aspects to double check:
- The popover also uses our button component; we might want to add it here as well. However, since it already has an icon on the right, it might not be desired in this case. Maybe double-check with @jrieke. But this could also be a follow-up
- It feels like a bit too many new snapshots for a relatively simple feature. I think we could reduce this, e.g. by just sprinkling some right/left icons on the existing buttons that get snapshot tested or by have those snapshots only taken on normal app / not themed_app (since theming shouldn't make a difference here).
Yeah I think I wouldn't add |
sfc-gh-bnisco
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like a bit too many new snapshots for a relatively simple feature.
You're right, I'm going to cut the amount of snapshots down.
Describe your changes
Adds an
icon_positionparameter to button-like components, allowing icons to be placed on the left (default) or right of the label.Changes by Category
1. Protobuf Definitions (4 files)
Added
icon_positionstring field to:Button.protoLinkButton.protoDownloadButton.protoPageLink.proto2. Backend (Python)
lib/streamlit/elements/widgets/button.py:IconPositiontype alias (Literal["left", "right"])_normalize_icon_position()for validationicon_positionparameter (default"left") to:st.button()st.download_button()st.link_button()st.page_link()icon_positionis"left"or"right", raisingStreamlitAPIExceptionotherwiselib/streamlit/elements/form.py:icon_positionparameter toform_submit_button()methods3. Frontend (TypeScript/React)
DynamicButtonLabel.tsx:iconPositionprop (default"left")iconPositionComponent updates:
Button.tsx,LinkButton.tsx,DownloadButton.tsx,FormSubmitButton.tsx— passiconPositiontoDynamicButtonLabelPageLink.tsx— custom logic to position icon left or right (doesn't useDynamicButtonLabel)Impact
Users can control icon placement on buttons:
icon_position="right"places the icon on the rightApplies to:
st.button(),st.download_button(),st.link_button(),st.page_link(), andst.form_submit_button().Screenshot or video (only for visual changes)
GitHub Issue Link (if applicable)
#13069
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.