-
Notifications
You must be signed in to change notification settings - Fork 4k
Display empty expanders and empty containers with a border. #11669
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
Display empty expanders and empty containers with a border. #11669
Conversation
🎉 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) |
✅ PR preview is ready!
|
3f79f53 to
2b1f5ad
Compare
e2e_playwright/st_expander_test.py
Outdated
| def test_empty_expander_not_rendered(app: Page): | ||
| """Test that an empty expander is not rendered.""" | ||
| expect(app.get_by_text("Empty expander")).not_to_be_attached() | ||
| expect(app.get_by_text("Empty expander")).to_be_visible() |
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.
suggestion (non-blocking): Consider adding snapshot tests for these scenarios.
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.
I was thinking for these we could save some snapshot space. But I was on the fence with this one since there are some visual details of how the expander looks when empty that could be altered.
| def test_empty_expander_rendered(app: Page, assert_snapshot: ImageCompareFunction): | ||
| """Test that an empty expander is not rendered.""" | ||
| expect(app.get_by_text("Empty expander")).not_to_be_attached() | ||
| empty_expander = app.get_by_test_id("stExpander").nth(13) | ||
| expect(empty_expander).to_be_visible() | ||
|
|
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.
The docstring for test_empty_expander_rendered() still states "Test that an empty expander is not rendered" which contradicts the new behavior being implemented and tested. The docstring should be updated to accurately reflect that the test is now verifying empty expanders are rendered, matching the actual test assertions and the PR's purpose.
| def test_empty_expander_rendered(app: Page, assert_snapshot: ImageCompareFunction): | |
| """Test that an empty expander is not rendered.""" | |
| expect(app.get_by_text("Empty expander")).not_to_be_attached() | |
| empty_expander = app.get_by_test_id("stExpander").nth(13) | |
| expect(empty_expander).to_be_visible() | |
| def test_empty_expander_rendered(app: Page, assert_snapshot: ImageCompareFunction): | |
| """Test that an empty expander is rendered.""" | |
| empty_expander = app.get_by_test_id("stExpander").nth(13) | |
| expect(empty_expander).to_be_visible() | |
Spotted by Diamond (based on custom rules)
Is this helpful? React 👍 or 👎 to let us know.
|
Sadly, my code takes advantage of what I did not know was a bug. I want my expanders to only render when not empty. Is it possible to add a parameter that makes this a controllable feature? e.g., |
Can you give more details of what you are trying to do @okapiadmin ? The expanders are not being rendered when they are empty except when they have height or a border, is your issue that you want to style with a border or height but hide them when empty? Or is the issue you want to display an empty expander with no border/height? cc @jrieke |
|
The code I use to set up the filters is "st.expander(label, expanded=True)". I do not set the height and am not aware of an st.expander parameter that controls the border. The app in question (https://nychsfilter.streamlit.app) allows users to dynamically select filters from >100 choices. To make it easier to navigate the filters are grouped into categories with one expander per category The expanders are set up early in the code and filter widgets are added later. The desired behavior is to render expanders if and only if they contain at least one filter widget. The live production version, running streamlit 1.44.1, does not render empty expanders. This is as desired. When I run locally, the code behaves as desired with streamlit 1.46.1 and below; but starting with 1.47.0 all expanders - including empty ones - are rendered. |
|
@okapiadmin ahh, yes, sorry we changed this also for containers and I was thinking of the behaviour for containers. For Can you create an enhancement request with your use case? Our product/design team will take a look at the enhancement issue to weigh in. But also, for your app, I think there could be a workaround using a wrapper function, or maybe classes. If you are able to share the source code I could take a look. |
|
@okapiadmin Feel free to create a GitHub issue as an enhancement, so we can see if other people want the same thing :) |
Describe your changes
Our original implementation doesn't render expanders when they are empty. This PR removes this restriction so that empty expanders are rendered.
Our original implementation doesn't render containers when they are empty (except if a height is provided). This modifies the implementation so that containers without height but with a border are also rendered. Empty containers with no border and no height are not rendered.
GitHub Issue Link (if applicable)
Testing Plan
Unit Tests (JS and/or Python) ✅
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.