Skip to content

Conversation

@KaranPradhan266
Copy link
Contributor

Describe your changes

  • Added full end-to-end dialog-icon support: the proto now includes an optional icon, the backend (_dialog / @st.dialog) validates and forwards it, and the frontend renders the icon next to the dialog title with refreshed styling.

Screenshot or video (only for visual changes)

Screen.Recording.2025-12-06.at.1.11.48.PM.mov

GitHub Issue Link (if applicable)

Issue - #13202

Testing Plan

  • Updated tests: backend dialog tests now verify icon propagation (including decorator usage), and frontend dialog tests cover both icon presence and absence.

Contribution License Agreement

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

@KaranPradhan266 KaranPradhan266 requested a review from a team as a code owner December 6, 2025 21:57
@snyk-io
Copy link
Contributor

snyk-io bot commented Dec 6, 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.

@sfc-gh-lmasuch sfc-gh-lmasuch added change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users status:needs-product-approval PR requires product approval before merging labels Dec 6, 2025
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 comprehensive icon support to Streamlit dialogs across the full stack. Users can now optionally display an emoji, Material Symbol, or spinner icon next to dialog titles using the new icon parameter in both st.dialog decorator and the internal _dialog method.

Key changes:

  • Added protobuf field for dialog icons with backward compatibility
  • Backend validates and forwards icons through the dialog creation pipeline
  • Frontend renders icons with proper styling using the existing DynamicIcon component

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
proto/streamlit/proto/Block.proto Added optional icon field (field number 6) to Dialog message for protobuf compatibility
lib/streamlit/elements/lib/dialog.py Added icon parameter to _create method with validation via validate_icon_or_emoji
lib/streamlit/elements/layouts.py Updated _dialog method signature to accept and forward icon parameter
lib/streamlit/elements/dialog_decorator.py Extended @st.dialog decorator with icon parameter and documentation
lib/tests/streamlit/elements/layouts_test.py Added tests for icon propagation in both direct usage and decorator patterns
frontend/lib/src/components/elements/Dialog/styled-components.ts Added flex layout styles for icon container with proper alignment
frontend/lib/src/components/elements/Dialog/Dialog.tsx Integrated DynamicIcon component with conditional rendering based on icon presence
frontend/lib/src/components/elements/Dialog/Dialog.test.tsx Added tests verifying icon rendering when present and absent

@lukasmasuch
Copy link
Collaborator

@cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no bugs!


@sfc-gh-lwilby sfc-gh-lwilby added the security-assessment-completed Security assessment has been completed for PR label Dec 9, 2025
@sfc-gh-lwilby
Copy link
Collaborator

@KaranPradhan266 thanks for submitting this PR! I am wondering if you could look into whether there are some e2e tests that could be added for this? Since it is a visual change, I think it would be a good idea.

@KaranPradhan266
Copy link
Contributor Author

@sfc-gh-lwilby Sure, will look into it!

@lukasmasuch
Copy link
Collaborator

Also linking @jrieke for doing a quick product review

@lukasmasuch lukasmasuch added ai-review If applied to PR or issue will run AI review workflow and removed ai-review If applied to PR or issue will run AI review workflow labels Dec 9, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

Summary

This PR adds optional icon support to @st.dialog and st._main._dialog(), allowing users to display an emoji or Material icon next to the dialog title. The implementation follows existing Streamlit patterns and touches all layers of the stack: proto definitions, Python backend, TypeScript frontend, and corresponding tests.

Key Changes:

Code Quality

The implementation is clean, well-organized, and follows existing Streamlit patterns:

Good Patterns Followed:

  • Uses existing validate_icon_or_emoji for validation, which handles emojis, Material icons, and the special "spinner" value
  • Leverages existing DynamicIcon component for frontend rendering
  • Proper use of theme spacing in StyledDialogTitle (gap: theme.spacing.sm)
  • Good docstring for the icon parameter in dialog_decorator.py (lines 231-235)
  • Icon is optional with sensible default (None → empty string in proto)

Proto Change (Block.proto:128):

  • Field icon = 6 is a new optional field - this is a backwards-compatible change per protobuf rules
  • Good comment explaining the field's purpose

Frontend Code (Dialog.tsx:162-166):

  • Conditional rendering pattern ({icon && ...}) is idiomatic React
  • Test ID stDialogIcon follows Streamlit's naming convention (stComponentSubcomponent)
  • Uses size="lg" for the icon which is appropriate for header context

Styled Components (styled-components.ts:19-32):

  • StyledDialogTitle properly uses flexbox for layout with theme-based spacing
  • StyledDialogIcon includes flexShrink: 0 to prevent icon compression

Test Coverage

Python Unit Tests (layouts_test.py:1037-1060):

  • test_dialog_sets_icon: Tests direct _dialog() API with icon
  • test_dialog_decorator_sets_icon: Tests decorator API with icon
  • Both tests verify the icon value propagates to the proto message correctly
  • Tests include brief docstrings as per guidelines

Frontend Unit Tests (Dialog.test.tsx:84-106):

  • renders an icon when provided: Verifies icon visibility and content
  • does not render an icon when not provided: Verifies no icon element when prop is absent
  • Uses screen.getByTestId / screen.queryByTestId appropriately
  • Uses toBeVisible() instead of redundant toBeInTheDocument() as per best practices

E2E Tests (st_dialog_test.py:291-297):

  • test_dialog_icon_is_displayed: Verifies icon is visible with correct text content
  • Uses expect() for auto-wait assertions (not assert)
  • Uses stable locators (get_by_role("dialog"), get_by_test_id("stDialogIcon"))

Minor Suggestions for Test Coverage:

  1. Consider adding a test case using a Material icon shortcode (e.g., ":material/info:") in addition to the emoji test to verify the full icon system works with dialogs.
  2. A snapshot test for the dialog with icon could help catch visual regressions in the icon + title layout.

Backwards Compatibility

Fully Backwards Compatible:

  • Proto field icon = 6 is a new optional string field with implicit default ""
  • Python icon parameter defaults to None, maintaining existing API
  • Frontend handles missing/empty icon gracefully with conditional rendering
  • No breaking changes to existing dialog functionality

Security & Risk

No Security Concerns:

  • Icon validation uses existing validate_icon_or_emoji which restricts values to:
    • Valid single-character emojis from the allowed list
    • Valid Material Symbol shortcodes
    • The special "spinner" value
  • No user-provided HTML/JS can be injected through the icon parameter

Low Regression Risk:

  • Changes are additive and don't modify existing behavior
  • Existing tests for dialog functionality are preserved
  • New icon styling uses flexbox which won't affect dialogs without icons

Recommendations

  1. Consider Material icon test case (optional enhancement): Add an E2E or unit test using :material/info: syntax to ensure complete coverage of the icon system.

  2. Consider snapshot test (optional enhancement): A snapshot test for st_dialog-with_icon would catch visual regressions in the icon + title layout.

  3. Example in docstring (nice to have): The main example in the docstring could show icon usage alongside the existing vote example, though this is minor since the parameter documentation is clear.

Verdict

APPROVED: This is a well-implemented feature that follows Streamlit patterns, includes appropriate test coverage across all layers (Python, TypeScript, E2E), maintains backwards compatibility, and poses no security risks. The suggestions above are optional enhancements rather than required changes.


This is an automated AI review. Please verify the feedback and use your judgment.

@KaranPradhan266
Copy link
Contributor Author

@lukasmasuch @sfc-gh-lwilby In my next commit, I’ll be covering updates to the icon comment descriptions, adding snapshot tests to verify both material-style and emoji icons, and adding a test to assert that the spinner icon’s test ID is visible. In addition to these updates, let me know if there is anything else you’d like me to address?

@lukasmasuch lukasmasuch requested a review from jrieke December 9, 2025 22:50
@KaranPradhan266
Copy link
Contributor Author

@sfc-gh-lmasuch @sfc-gh-lwilby @jrieke Let me know if these look good!
Screenshot 2025-12-09 at 3 00 11 PM

@jrieke jrieke added status:product-approved Community PR is approved by product team and removed status:needs-product-approval PR requires product approval before merging labels Dec 10, 2025
@jrieke
Copy link
Collaborator

jrieke commented Dec 10, 2025

LGTM from product/design side!

@sfc-gh-lwilby
Copy link
Collaborator

@KaranPradhan266 it looks like you will need to commit your snapshots that you added now. You can run make update-snapshots locally and then commit the results. I will do a final review later today or tomorrow.

click_button(app, "Open Dialog without Images")


def open_dialog_with_icon(app: Page):
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] We would more typically just combine the tests to take the snapshot and the tests to check the icon, then I think we don't need this helper functions. But this isn't blocking since it is a more minor style decision with how to write tests. Your tests are more focused on testing one thing.

Copy link
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby left a comment

Choose a reason for hiding this comment

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

Thanks @KaranPradhan266, just a minor comment on the e2e tests, but it is not blocking.

Copy link
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby left a comment

Choose a reason for hiding this comment

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

Sorry, @KaranPradhan266 I just noticed there is an e2e test failing that might be related -- maybe affected by the tests you added because if I remember correctly, the CI was passing previously? Lukas just merged a fix for dialogs, so maybe rebasing on develop and fixing the merge conflict as well will help with the test failure.

@KaranPradhan266
Copy link
Contributor Author

@sfc-gh-lwilby @lukasmasuch I looked into the failing tests and none of the failures appear to be caused by changes in this PR.

The Python unit test failure seems related to LoginHandlerTest, unlikely because of curent changes. For Playwright e2e, the failure is isolated to test_dialog_with_chart and occurs only on Firefox. This looks like test flakiness due to using a fixed hover position ({x: 80, y: 200}), not the dialog icon changes.

image

We can make the test more deterministic by hovering using the chart’s bounding box instead. I can push a fix for the test if you’d like, but it would be unrelated to this PR. Let me know how you’d like to proceed.

image

@sfc-gh-lwilby
Copy link
Collaborator

sfc-gh-lwilby commented Dec 12, 2025

Thanks for looking into these failures @KaranPradhan266 . Apologies for the flaky test, unfortunately, it seems like maybe adding more elements into the test file for your tests is triggering the failure in this other test even though that test already had this flaw. If you have time to fix this other test it will help merge your PR faster. We can't merge it with the test failing because it will break develop.

For the python unit test, I agree it doesn't apper related to your changes exactly, but it seems to also be persistently failing so it needs to be resolved before merging into the develop to keep develop green. I wonder if something went wrong when you merged in develop and fixed the merge conflict.

I can try to take a look if you don't have time, but if you have time to resolve these fixes that will likely be the fastest solution because I have some other priorities to attend to first.

Thanks again! Sorry these test failures are getting in the way of merging your PR.

@sfc-gh-lwilby
Copy link
Collaborator

@KaranPradhan266 an update on the LoginHandlerTest failure. This is an issue affecting other PRs that was introduced during a dependency update and we are working on a fix. So it is just the e2e test failure.

@KaranPradhan266
Copy link
Contributor Author

@sfc-gh-lwilby Thanks for the update! I’ve pushed the latest changes, which should now handle the e2e failures as well. Please let me know if you still see any issues on your end.

@KaranPradhan266
Copy link
Contributor Author

@lukasmasuch My apologies for the oversight on type checker part, resolved it!

@KaranPradhan266
Copy link
Contributor Author

@lukasmasuch @sfc-gh-lwilby I believe all feedback has been addressed, can you confirm whether this PR is ready to merge, or if there’s anything else needed?

Copy link
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby left a comment

Choose a reason for hiding this comment

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

Thank you @KaranPradhan266 ! Thanks for fixing our flaky test as well :)

@lukasmasuch lukasmasuch self-assigned this Dec 15, 2025
Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Removed one accidental method call (probably from a recent merge).

@lukasmasuch lukasmasuch enabled auto-merge (squash) December 15, 2025 23:59
@lukasmasuch lukasmasuch merged commit bc166f5 into streamlit:develop Dec 16, 2025
40 checks passed
@mayagbarnes mayagbarnes mentioned this pull request Dec 16, 2025
2 tasks
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 status:product-approved Community PR is approved by product team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants