-
Notifications
You must be signed in to change notification settings - Fork 4k
Option to have non dismissable dialog #9504
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
Option to have non dismissable dialog #9504
Conversation
|
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. |
|
Pinging @jrieke as you have commented on the related ticket. |
|
@jrieke please look into this as it would be super helpful! |
|
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. |
|
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 |
|
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:
|
|
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 |
|
Oh right. I think you can still press R on the keyboard to rerun, no? |
|
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. |
|
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. |
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! |
|
@frarteaga you can install my fork by running |
…reamlit into pr/souvikmaji/9504
🎉 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) |
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.
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).
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 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
dismissibleboolean parameter (defaultTrue) 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 |
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: Copilot <[email protected]>
Describe your changes
Added a new parameter
dismissibleto@dialogdecorator. It will remove the x mark from the top left, and can only be closed by implementing a close button, withst.rerun().GitHub Issue Link (if applicable)
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.