streamlit / streamlit

Streamlit — A faster way to build and share data apps.

Home Page:https://streamlit.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

segmented_control with a required value

RubenVanEldik opened this issue · comments

Checklist

  • I have searched the existing issues for similar feature requests.
  • I added a descriptive title and summary to this issue.

Summary

Hi all,

The segmented_control component is a fantastic new component that I think will be used a lot by Streamlit users.

However, I currently miss 1 option, that is to require a value. For example, now it is possible to provide a default value which can be unclicked.

Why?

In many use cases where segmented_control will be used in a single mode, the developer might want to force the user to select something.

How?

I propose to expand the segmented_control (and pills) API by adding an extra parameter 'required' . If required is True, a value must always be selected.

options = ["North", "East", "South", "West"]
selection = st.segmented_control(
    "Directions",
    options,
    selection_mode="single",
    required=True,
    default="South",
)

To help Streamlit prioritize this feature, react with a 👍 (thumbs up emoji) to the initial post.

Your vote helps us identify which enhancements matter most to our users.

Visits

Somewhat related: #7165

Hi @jrieke! Thank you for the feedback. It is indeed related, but I think it is significantly easier to solve, as we won't need any front-end magic, I think. We only need to check if a required=True when the last item is deselected.

If y'all would be interested in this feature I could try to create a pull request for it. I think a lot of users would benefit from this!