Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@souvikmaji
Copy link
Contributor

@souvikmaji souvikmaji commented Sep 19, 2024

Describe your changes

Added a new parameter dismissible to @dialog decorator. It will remove the x mark from the top left, and can only be closed by implementing a close button, with st.rerun().

GitHub Issue Link (if applicable)

Testing Plan

  • Explanation of why no additional tests are needed
  • Unit Tests (JS and/or Python)
  • E2E Tests
  • Any manual testing needed?

Contribution License Agreement

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

@souvikmaji souvikmaji marked this pull request as ready for review September 23, 2024 13:07
@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2024

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Oct 9, 2024
@PhilLab
Copy link

PhilLab commented Oct 11, 2024

Pinging @jrieke as you have commented on the related ticket.

@github-actions github-actions bot removed the stale label Oct 12, 2024
@idiose77
Copy link

@jrieke please look into this as it would be super helpful!

@souvikmaji
Copy link
Contributor Author

Hi @jrieke, Let me know how we can take this forward. I have been using my solution successfully in production for over a month. But would love it if this gets merged.

@jrieke
Copy link
Collaborator

jrieke commented Nov 4, 2024

Hey, thanks for your PR and sorry for the wait!

We considered adding this in the past but have not done so for now. The problem is that viewers can still make the app rerun by pressing "R" or clicking on "Rerun" in the app menu. So having a dismissible option might give a false sense of security that viewers won't be able to get out of the dialog when, in fact, they can. Let me play around with your PR in the next few days and see how it feels in practice! Do you have any opinion on this? Would also be fantastic so see some code examples of how/for which use cases you use this!

@jrieke
Copy link
Collaborator

jrieke commented Nov 5, 2024

OK just tried this out and also read up on the issues again. Yeah, I can definitely see that this is helpful for some scenarios where you want to guide the users toward not closing the dialog, but it's not the end of the world if they rerun the app and, therefore, close the dialog. But I still fear that some users might e.g. use this as a login modal and not realize that users can get out of it easily by rerunning the app through the menu.

So I think the options we have are:

  1. Disallow rerunning through the menu/keyboard shortcut altogether. I think it's not likely we'll do that since it would be a big behavior change.
  2. Not launch this. Also not great because I see valid use cases!
  3. Launch this but add a disclaimer to the docs saying that users can still get out of the dialog by rerunning the app.
  4. Disable the "Rerun" menu item while a dialog with dismissible=True is shown. This would be pretty neat but I'm not sure if it isn't pretty complicated to implement. Seems like we do this here if the server is disconnected but it might be hard to pipe the information that a dialog is open into that piece of the code. @raethlein any opinion on this idea?

@frarteaga
Copy link

frarteaga commented Nov 7, 2024

I've tested these changes and when dismissable=False we can't click on the “the app chrome” (the three dots menu on the top right). I think that solve your concern @jrieke

@jrieke
Copy link
Collaborator

jrieke commented Nov 7, 2024

Oh right. I think you can still press R on the keyboard to rerun, no?

@souvikmaji
Copy link
Contributor Author

Pressing R on the keyboard will rerun the app.

However, if we do not make this change and keep dialogs dismissable, they would still be unsuitable for a login page (or as an entry point to a Streamlit app) since users can simply close the modal.
And usually after a successful login, we save some kind of state to denote the user is logged in, if the session state is not set (because the dialog was closed forcefully by pressing R), the user will remain in the logged-out state.

@frarteaga
Copy link

frarteaga commented Nov 8, 2024

Offtopic question for @souvikmaji, how can I install your fork instead of the official one? I tested your changes by changing directly the py file in .venv\Lib\site-packages\streamlit\elements, but I don't know how to do it in an azure web app deployment.

@jrieke
Copy link
Collaborator

jrieke commented Nov 8, 2024

However, if we do not make this change and keep dialogs dismissable, they would still be unsuitable for a login page (or as an entry point to a Streamlit app) since users can simply close the modal.
And usually after a successful login, we save some kind of state to denote the user is logged in, if the session state is not set (because the dialog was closed forcefully by pressing R), the user will remain in the logged-out state.

Yup, agree with that. The danger I see though is that people think this prevents app reruns, write their app in a way where e.g. private data is getting shown after a login dialog is closed, and then that data is getting exposed if viewers press R. For sure, that's an edge case but it's one that potentially touches security (or rather, where there is a common use case that could touch security), so I'm a bit hesitant to just ship this. I think we should at least figure out if there is a good way to prevent the rerun. I'll also discuss this with the team next week to get some more opinions!

@souvikmaji
Copy link
Contributor Author

souvikmaji commented Nov 9, 2024

@frarteaga you can install my fork by running pip install streamlit-dialog.
I made it available in PyPI to install it in production easily.
But since it has not been officially merged yet, use it at your own risk and discretion.

@jrieke jrieke added the change:feature PR contains new feature or enhancement implementation label Mar 14, 2025
@lukasmasuch lukasmasuch added impact:users PR changes affect end users status:needs-product-approval PR requires product approval before merging labels May 19, 2025
@snyk-io
Copy link
Contributor

snyk-io bot commented May 22, 2025

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

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@sfc-gh-lmasuch sfc-gh-lmasuch requested a review from Copilot July 8, 2025 10:02

This comment was marked as outdated.

@sfc-gh-lmasuch sfc-gh-lmasuch added status:product-approved Community PR is approved by product team and removed status:needs-product-approval PR requires product approval before merging labels Jul 8, 2025
@lukasmasuch lukasmasuch self-assigned this Jul 9, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

sfc-gh-lmasuch
sfc-gh-lmasuch approved these changes Jul 23, 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 👍 I added a couple of unit and e2e tests and added a prevention of pressing the R hotkey when the dialog is open (which would also dismiss the dialog).

@lukasmasuch lukasmasuch requested a review from Copilot July 23, 2025 15:38
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 a new dismissible parameter to the @st.dialog decorator that allows creating non-dismissible modal dialogs. When set to False, the dialog removes the X button, prevents dismissal via ESC key or clicking outside, and blocks the R hotkey to prevent accidental script reruns.

Key changes:

  • Added dismissible boolean parameter (default True) to the dialog decorator API
  • Implemented frontend logic to prevent dismissal when dismissible=False
  • Added comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/streamlit/elements/dialog_decorator.py Added dismissible parameter to decorator function signatures and documentation
frontend/lib/src/components/elements/Dialog/Dialog.tsx Implemented keyboard event handling to prevent R key dismissal for non-dismissible dialogs
lib/tests/streamlit/elements/layouts_test.py Added unit test for dismissible=False parameter
frontend/lib/src/components/elements/Dialog/Dialog.test.tsx Added test for dismissible dialog close behavior
e2e_playwright/st_dialog.py Added test app with non-dismissible dialog example
e2e_playwright/st_dialog_test.py Added comprehensive E2E tests for non-dismissible dialog behavior

@sfc-gh-lmasuch sfc-gh-lmasuch added security-assessment-completed Security assessment has been completed for PR status:product-approved Community PR is approved by product team and removed status:product-approved Community PR is approved by product team labels Jul 23, 2025
lukasmasuch and others added 2 commits July 23, 2025 17:52
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
@lukasmasuch lukasmasuch enabled auto-merge (squash) July 23, 2025 16:30
@lukasmasuch lukasmasuch merged commit 8c8199f into streamlit:develop Jul 23, 2025
37 checks passed
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.

Allow dialogs not to be dismissable when clicking outside their area

8 participants