-
Notifications
You must be signed in to change notification settings - Fork 4k
Support for markdown in select_slider options #12960
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
Support for markdown in select_slider options #12960
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
0675bfc to
c2272d6
Compare
sfc-gh-bnisco
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.
Thanks for the contribution @jensonjohnathon! Before I do an in-depth code review, I've marked this as requires product approval so we can ensure that we do want to ship this (cc @jrieke ).
With that said, I took a quick look at the code I noticed that this adds a new top-level package.json and yarn.lock file, and takes a net-new dependency on react-markdown. Note that we already have established patterns in our code for rendering Markdown, and we would want to reuse those in this code if we were to move forward with this change.
|
Thank you for the feedback I will update my PR this week to incorporate it. |
|
Haven't tested this out in detail but we definitely want this feature and from the screenshot it looks fine, so marking as product approved. Let me know once these bigger issues are fixed and I can try this out again! |
c2272d6 to
c30448b
Compare
|
I have exchanged ReactMarkdown for StreamlitMarkdown. So no more files and dependencies that are not needed. Feel free to test it out. |
sfc-gh-bnisco
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.
Thank you for the revisions here!
I've left some inline comments and I ran the CI jobs. There are a number of test failures. The main cases I see are:
- Snapshots are failing due to different styling because the font size is different than it was prior. @jrieke , would like to hear your take on expected font behavior given that this is a change to how fonts are rendered here!
- Legitimate functionality issues (eg:
test_main_script_widgets_persist_across_page_changesis failing because it's expected value is not correct) - Frontend lint errors
As next steps I'd suggest looking into my PR feedback, which may help solve error cases 2 + 3.
| // Only run this on first render, to avoid losing the focus state. | ||
| // Then, when the value written about the thumb needs to change, that | ||
| // happens with the function below instead. | ||
| [] | ||
| [formattedValueArr] |
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: Adding this to the dependency array will likely cause unintended behaviors, let's keep this empty so that the code matches the expected behavior + 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.
The Problem is the way thumbValueRefs updates the value with innerText.
// Update the numbers on the thumb via DOM manipulation to avoid a redraw,
// which drops the widget's focus state.
thumbValueRefs.map((ref, i) => {
if (ref.current) {
ref.current.innerText = formattedValueArr[i]
}
})
With innerText React does not know it has to update how it renders the text. So the thumbValue is just a string again.
So *red* not red again.
To get the correct rendering formattedValueArr has to be passed along, DOM manipulation is not possible in this case as far as I know.
I think the only option is to update the comment before.
|
Fixing the linting error: Is not possible while also rendering the selected thumbValue as markdown. This is because of visual bugs that arise when adding it to the dependency error. I suggest suppressing it. example of the wrong behavior: Video.Project.mp4 |
|
Gotcha, yeah I think it's fine, unless one of our engs has a good idea for how to do it! |
2d73f25 to
9ac2b47
Compare
|
I have added the lint error suppression. |
...ywright/__snapshots__/linux/iframe_resizer_test/iframe_resizer-embedded_iframe[chromium].png
Show resolved
Hide resolved
sfc-gh-nbellante
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 think it might be good to add |
I would like to get to know the test suite better. So if you want I can look into this and make a pr but what would be the right process? Do I just make the PR once I am finished? |
|
Thanks @jensonjohnathon - If you'd like to address this feedback around |
Thanks for the info, I will do exactly that. |
label, current_option, and min_label
|
I have added the necessary test.
|
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 implements markdown rendering support for st.select_slider options, enabling rich text formatting (bold, italic, icons, colored text, etc.) in slider option labels and tick marks. This addresses issue #11774 by allowing users to enhance the visual presentation of select slider options.
Key Changes
- Replaced plain text rendering with
StreamlitMarkdowncomponent for slider tick bar labels and thumb values - Refactored
renderThumbcallback to maintain referential stability while accessing current element data via ref - Updated E2E tests to include comprehensive markdown feature coverage for select_slider
- Changed
st_select_slidermarkdown restrictions fromDISALLOWED_FEATURES_IN_LABELto empty list (allowing all markdown features)
Reviewed changes
Copilot reviewed 5 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
frontend/lib/src/components/widgets/Slider/Slider.tsx |
Integrated StreamlitMarkdown component for rendering slider option labels and thumb values; refactored renderThumb for better performance with elementRef pattern; replaced useEffect with useLayoutEffect for accessibility updates |
e2e_playwright/st_select_slider.py |
Added test case with comprehensive markdown-formatted options (strikethrough, bold, italic, code, icons, colored text, links) |
e2e_playwright/st_select_slider_test.py |
Added snapshot assertion for markdown options rendering across themes and browsers |
e2e_playwright/markdown_features.py |
Updated select_slider to use markdown in both label and options for feature testing |
e2e_playwright/markdown_features_test.py |
Added special case handling for st_select_slider to validate markdown rendering in label, current option, and min label positions; removed markdown restrictions for select_slider |
e2e_playwright/__snapshots__/.../st_select_slider-markdown_in_options[...].png |
Visual regression test snapshots for markdown rendering across different themes and browsers |
e2e_playwright/__snapshots__/.../iframe_resizer-embedded_iframe[...].png |
| useLayoutEffect(() => { | ||
| // Keep aria-valuetext in sync with the formatted values for accessibility. | ||
| thumbRefs.forEach((ref, i) => { | ||
| if (ref.current) { | ||
| ref.current.setAttribute("aria-valuetext", formattedValueArr[i]) | ||
| } | ||
| }) |
Copilot
AI
Dec 1, 2025
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.
Potential accessibility issue: When slider options contain markdown syntax (e.g., "*italic*" or "**bold**"), the aria-valuetext attribute is set to the raw markdown string rather than the rendered plain text. This means screen readers will announce "asterisk italic asterisk" instead of just "italic".
Consider stripping markdown syntax from the aria-valuetext value for better accessibility. You could use a utility to convert markdown to plain text, or extract the text content from the rendered markdown. For example:
// In useLayoutEffect:
const plainTextValue = stripMarkdown(formattedValueArr[i]) // or similar
ref.current.setAttribute("aria-valuetext", plainTextValue)This would ensure screen readers announce the actual content rather than the markdown syntax.
|
Wohoo, thanks for getting this across the finish line, @jensonjohnathon! 🥳 Would love to send you some swag as a little thank you, just fill out this form and we'll get it on the way: https://forms.gle/RZCUTKCrg7aHyqH78 |
|
Thank you very much! Will definitely contribute next year too, it was awesome working with you, Bob and Lukas. 🤗
|



Describe your changes
I altered the slider_select to allow for markdown rendering in the options field.
Now this,
color = st.select_slider( "Select a color of the rainbow", options=[ "*red*", "*orange*", "yellow", "green", "blue", "indigo", "**violet**", ], )kind of code renders correctly like in the picture.
Not just as
*red*but actually as red.Screenshot or video (only for visual changes)
GitHub Issue Link (if applicable)
#11774
Testing Plan
Further testing would be useful but I am not sure if the issue is still being pursued, as it is older. If yes I can do that and also update the docs.
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.