Skip to content

Conversation

@jrieke
Copy link
Collaborator

@jrieke jrieke commented Dec 26, 2024

Describe your changes

Many of our widgets have dropdowns but they look slightly different. This PR makes them look more consistent.

While I was at it, I also converted BaseColorPicker to a functional component because I couldn't figure out how to fix some issues with theming in the class-based component. The only things that changed in the color picker are the injection of custom styles and the placement of the popover, so I think doing the conversion at the same time shouldn't be too confusing. But I can separate both changes if it's easier to review.

Before After
CleanShot 2024-12-26 at 22 19 26 CleanShot 2024-12-26 at 22 20 04
CleanShot 2024-12-26 at 22 20 37 CleanShot 2024-12-26 at 22 20 57
CleanShot 2024-12-26 at 22 21 45 CleanShot 2024-12-26 at 22 22 21
CleanShot 2024-12-26 at 22 24 24 CleanShot 2024-12-26 at 22 24 08
CleanShot 2024-12-26 at 22 24 55 CleanShot 2025-01-13 at 01 10 48

Note that the date input has a red border and is in the foreground when focused (just like the other components), my screenshot tool somehow removes that, though.

GitHub Issue Link (if applicable)

Closes #8705

Testing Plan

  • Updated snapshot tests for date input.
  • I added a snapshot test for the dropdown of color picker since that has a few customizations now.
  • I realized we don't really have snapshot tests for the dropdown elements of the other widgets. One problem is though that the snapshots test only capture the content of the dropdown, not the shadow and positioning around it. Ideally, we'd have some way to take a snapshot with some additional padding around it but I'm not sure if it's worth introducing that.
  • Don't think it makes sense to have unit tests for such small styling things.

Contribution License Agreement

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

@jrieke jrieke added security-assessment-completed Security assessment has been completed for PR change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Dec 26, 2024
@jrieke jrieke changed the title Make dropdowns of different widgets consistent Make widget dropdowns look more consistent Dec 26, 2024
@jrieke jrieke changed the title Make widget dropdowns look more consistent [WIP] Make widget dropdowns look more consistent Dec 26, 2024
// We force an update by changing the key of the popover after this error,
// to re-mount the UIPopover - because the error sometimes cause it to be
// unmounted. This is an unfortunate hack.
setPopoverKey(prev => prev + 1)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this does the same thing as before but I'm not sure if it always works well and if that's the most elegant solution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I'm not 100% confident that this is handling the situation correctly. Have you been able to trigger the SecurityError somehow? The previous implementation used an error boundary, which also prevented the error from bubbling up to the window. Error boundaries are not supported by functional components. This will just react to an error in the window, but this error might cause other issues in the application itself.

Copy link
Collaborator Author

@jrieke jrieke Jan 12, 2025

Choose a reason for hiding this comment

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

Ok I just deployed this on Cloud with this part removed and I can't see that error anymore (also verified that it's indeed using this version with the removed code). Maybe that went away because the app and iframe are nowadays running on the same domain in Cloud? It might still be a problem in other deployment setups though. Anyway, I'll remove this code for now and I think we can just wait and see if someone files a GitHub issue for this, or wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a bit worried that it might crash in SiS or notebooks. Can you test if it also works correctly of you embed the cloud app on a different domain (e.g. notion)? This might be a potential patch/workaround to fix the underlying issue: uiwjs/react-color#81 (comment)

Copy link
Collaborator Author

@jrieke jrieke Jan 13, 2025

Choose a reason for hiding this comment

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

Good call, it does happen in an embedded app and results in this exception being shown:

CleanShot 2025-01-13 at 02 54 41

Copy link
Collaborator Author

@jrieke jrieke Jan 13, 2025

Choose a reason for hiding this comment

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

Applied the workaround (had to modify a few things for TypeScript to be happy), and it seems to work well. Tested this on Cloud and in an embedded app and I don't see errors anymore.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it might be quite simple to test if this works correctly via our iframed app testing in hostframe_app. Just add a color picker in the app and a test that verifies that the popup can be closed without running into the issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh that's a sweet idea. Added a small test.

@jrieke jrieke changed the title [WIP] Make widget dropdowns look more consistent [WIP] Make widget dropdowns look more consistent + convert BaseColorPicker to functional component Dec 26, 2024
@jrieke jrieke changed the title [WIP] Make widget dropdowns look more consistent + convert BaseColorPicker to functional component Make widget dropdowns look more consistent + convert BaseColorPicker to functional component Dec 26, 2024
@jrieke jrieke marked this pull request as ready for review December 26, 2024 23:30
// We force an update by changing the key of the popover after this error,
// to re-mount the UIPopover - because the error sometimes cause it to be
// unmounted. This is an unfortunate hack.
setPopoverKey(prev => prev + 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I'm not 100% confident that this is handling the situation correctly. Have you been able to trigger the SecurityError somehow? The previous implementation used an error boundary, which also prevented the error from bubbling up to the window. Error boundaries are not supported by functional components. This will just react to an error in the window, but this error might cause other issues in the application itself.

@jrieke
Copy link
Collaborator Author

jrieke commented Jan 13, 2025

@lukasmasuch I think this is ready for another review. I fixed a few additional things along the way (especially with color picker styling), so would be good if you could look through everything again. I'll talk with Jessi about making the dropdowns look more distinguishable in dark mode but I might do that in a follow-up PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume this is expected that time_input now shows more options?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup, I increased the max height there to be the same as all other dropdowns.

Copy link
Collaborator

Choose a reason for hiding this comment

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

And the scroll to the selected item on open still works in this case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just verified, yup this still works!

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.

A few small comments (maybe add a iframed test to hostframe_app and add a comment to declarations.d.ts), but overall LGTM 👍

@jrieke jrieke enabled auto-merge (squash) January 14, 2025 01:37
@jrieke jrieke merged commit b688c7c into develop Jan 14, 2025
33 checks passed
@jrieke jrieke deleted the fix/make-dropdowns-consistent branch January 14, 2025 02:11
edegp pushed a commit to edegp/streamlit that referenced this pull request Jan 19, 2025
…` to functional component (streamlit#10083)

## Describe your changes

Many of our widgets have dropdowns but they look slightly different.
This PR makes them look more consistent.

While I was at it, I also converted `BaseColorPicker` to a functional
component because I couldn't figure out how to fix some issues with
theming in the class-based component. The only things that changed in
the color picker are the injection of custom styles and the placement of
the popover, so I think doing the conversion at the same time shouldn't
be too confusing. But I can separate both changes if it's easier to
review.

| Before | After |
|----------|----------|
| ![CleanShot 2024-12-26 at 22 19
26](https://github.com/user-attachments/assets/8c7a4cc5-f169-4fbc-8256-8e9e8a39b5e8)
| ![CleanShot 2024-12-26 at 22 20
04](https://github.com/user-attachments/assets/fbb48ab0-8296-4632-9885-e9ec55b0402d)
|
| ![CleanShot 2024-12-26 at 22 20
37](https://github.com/user-attachments/assets/eb2d6172-d08c-4d54-9533-029197946c90)
| ![CleanShot 2024-12-26 at 22 20
57](https://github.com/user-attachments/assets/38fed40e-6582-4b52-a4e8-fc366b8cce92)
|
| ![CleanShot 2024-12-26 at 22 21
45](https://github.com/user-attachments/assets/f4f97485-c4c5-4137-9b72-3e8d2651aa0d)
| ![CleanShot 2024-12-26 at 22 22
21](https://github.com/user-attachments/assets/0b97eba6-9e1a-49f5-b4b6-122c01fff086)
|
| ![CleanShot 2024-12-26 at 22 24
24](https://github.com/user-attachments/assets/b3b3a6bd-8b27-439f-8cb9-44673196b3b5)
| ![CleanShot 2024-12-26 at 22 24
08](https://github.com/user-attachments/assets/9e390b46-7e30-464c-8320-d2c0d291835d)
|
| ![CleanShot 2024-12-26 at 22 24
55](https://github.com/user-attachments/assets/7c5212c6-7454-4554-9b1a-a76e33a321de)
| ![CleanShot 2025-01-13 at 01 10
48](https://github.com/user-attachments/assets/4679bd63-1965-4901-ae81-f1212069d277)
|

Note that the date input has a red border and is in the foreground when
focused (just like the other components), my screenshot tool somehow
removes that, though.


## GitHub Issue Link (if applicable)

Closes streamlit#8705 

## Testing Plan

- Updated snapshot tests for date input.
- I added a snapshot test for the dropdown of color picker since that
has a few customizations now.
- I realized we don't really have snapshot tests for the dropdown
elements of the other widgets. One problem is though that the snapshots
test only capture the content of the dropdown, not the shadow and
positioning around it. *Ideally*, we'd have some way to take a snapshot
with some additional padding around it but I'm not sure if it's worth
introducing that.
- Don't think it makes sense to have unit tests for such small styling
things.

---

**Contribution License Agreement**

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

---------

Co-authored-by: Johannes Rieke <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify dropdown styles for st.selectbox, st.multiselect, and st.date_input

5 participants