Skip to content

Conversation

@jensonjohnathon
Copy link
Contributor

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)

Untitled

GitHub Issue Link (if applicable)

#11774

Testing Plan

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

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.

@snyk-io
Copy link
Contributor

snyk-io bot commented Nov 6, 2025

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

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@jensonjohnathon jensonjohnathon force-pushed the slider_select branch 2 times, most recently from 0675bfc to c2272d6 Compare November 6, 2025 14:00
@jensonjohnathon jensonjohnathon changed the title markdown in options string can be rendered correctly Support for markdown in select_slider options Nov 7, 2025
@sfc-gh-bnisco sfc-gh-bnisco added the status:needs-product-approval PR requires product approval before merging label Nov 17, 2025
Copy link
Collaborator

@sfc-gh-bnisco sfc-gh-bnisco left a 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.

@sfc-gh-bnisco sfc-gh-bnisco added feature:st.select_slider Related to the `st.select_slider` widget change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Nov 17, 2025
@jensonjohnathon
Copy link
Contributor Author

Thank you for the feedback I will update my PR this week to incorporate it.

@jrieke jrieke added status:product-approved Community PR is approved by product team and removed status:needs-product-approval PR requires product approval before merging labels Nov 17, 2025
@jrieke
Copy link
Collaborator

jrieke commented Nov 17, 2025

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!

@jensonjohnathon
Copy link
Contributor Author

jensonjohnathon commented Nov 18, 2025

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 sfc-gh-bnisco self-assigned this Nov 18, 2025
Copy link
Collaborator

@sfc-gh-bnisco sfc-gh-bnisco left a 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:

  1. 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!
  2. Legitimate functionality issues (eg: test_main_script_widgets_persist_across_page_changes is failing because it's expected value is not correct)
  3. Frontend lint errors

As next steps I'd suggest looking into my PR feedback, which may help solve error cases 2 + 3.

Comment on lines 213 to 217
// 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]
Copy link
Collaborator

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.

Copy link
Contributor Author

@jensonjohnathon jensonjohnathon Nov 19, 2025

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.

@jensonjohnathon
Copy link
Contributor Author

jensonjohnathon commented Nov 19, 2025

Fixing the linting error:
Warning: 243:6 warning React Hook useEffect has a missing dependency: 'formattedValueArr'. Either include it or remove the dependency array react-hooks/exhaustive-deps

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.
with
// eslint-disable-next-line react-hooks/exhaustive-deps

example of the wrong behavior:

Video.Project.mp4

@sfc-gh-jrieke
Copy link
Contributor

Just tried this out and works well for the most part! Only weird thing I saw is that for code blocks (e.g. "inline code ```code block``` $\\int_0^1 x^2 dx$"), it seems to weirdly stack them vertically instead of just writing them out horizontally in one line, like st.markdown would do. But maybe that's a bit of an edge case.

Screenshot 2025-11-19 at 12 19 43

@jensonjohnathon
Copy link
Contributor Author

jensonjohnathon commented Nov 19, 2025

Just tried this out and works well for the most part! Only weird thing I saw is that for code blocks (e.g. "inline code```code block``` $\\int_0^1 x^2 dx$"), it seems to weirdly stack them vertically instead of just writing them out horizontally in one line, like st.markdown would do. But maybe that's a bit of an edge case.
Screenshot 2025-11-19 at 12 19 43

I have tried to fix this but the fix seems non trivial.
The problem is line 48 in the file styled-components.ts

width: theme.sizes.sliderThumb,

This sets the width of the parent div to a standard 0.75em.
I don't quite know how to get around this.

Increasing the width to a bigger value works but breaks a lot of things.
image

If this is important I can look further into it maybe I can find a way.

@jrieke
Copy link
Collaborator

jrieke commented Nov 19, 2025

Gotcha, yeah I think it's fine, unless one of our engs has a good idea for how to do it!

@jensonjohnathon
Copy link
Contributor Author

I have added the lint error suppression.
The other errors seem to come from my branch being out-of-date. I updated so now I hope everything passes.

Copy link
Contributor

@sfc-gh-nbellante sfc-gh-nbellante left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@lukasmasuch
Copy link
Collaborator

I think it might be good to add st.select_slider to the https://github.com/streamlit/streamlit/blob/develop/e2e_playwright/markdown_features_test.py e2e test as well.

@jensonjohnathon
Copy link
Contributor Author

jensonjohnathon commented Nov 25, 2025

I think it might be good to add st.select_slider to the https://github.com/streamlit/streamlit/blob/develop/e2e_playwright/markdown_features_test.py e2e test as well.

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?
Or do I create an issue first?

@sfc-gh-bnisco
Copy link
Collaborator

Thanks @jensonjohnathon - If you'd like to address this feedback around markdown_features_test.py, please add the changes to this branch directly and we'll take another look at it when you push updates!

@jensonjohnathon
Copy link
Contributor Author

jensonjohnathon commented Nov 26, 2025

Thanks @jensonjohnathon - If you'd like to address this feedback around markdown_features_test.py, please add the changes to this branch directly and we'll take another look at it when you push updates!

Thanks for the info, I will do exactly that.

label, current_option, and min_label
@jensonjohnathon
Copy link
Contributor Author

I have added the necessary test.
Feel free to check it out.

I think it might be good to add st.select_slider to the https://github.com/streamlit/streamlit/blob/develop/e2e_playwright/markdown_features_test.py e2e test as well.

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 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 StreamlitMarkdown component for slider tick bar labels and thumb values
  • Refactored renderThumb callback 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_slider markdown restrictions from DISALLOWED_FEATURES_IN_LABEL to 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 ⚠️ Unrelated snapshot files that should not be included in this PR

Comment on lines +239 to 245
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])
}
})
Copy link

Copilot AI Dec 1, 2025

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.

Copilot uses AI. Check for mistakes.
@sfc-gh-bnisco sfc-gh-bnisco merged commit 3c89c5d into streamlit:develop Dec 4, 2025
39 checks passed
@jrieke
Copy link
Collaborator

jrieke commented Dec 10, 2025

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

@jensonjohnathon
Copy link
Contributor Author

Thank you very much!

Will definitely contribute next year too, it was awesome working with you, Bob and Lukas. 🤗

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

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 feature:st.select_slider Related to the `st.select_slider` widget feature:st.slider Related to the `st.slider` widget 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.

6 participants