-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
segmented_control with a required value #9870
Comments
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! |
I set my segmented controls with a default value, but I just noticed that it is possible to double-click on a segmented control and remove a value from it. I would like to stop that behaviour (I am trying to use them much like a prettier form of radio button), which I think setting required=True could be made to do (i.e. remove the option to set the value to None). |
I think “prettier version of a radio button” is a great way to describe how segmented controls will be used by many users! I would love to hear from the maintainers if they are interested in supporting this feature and if the solution proposed here would work. |
Definitely interested in a PR! We also have a |
Another question is how we deal with default values. E.g. if |
Thank you for the input! I think
I think we should remove the ‘auto’ behaviour in selectbox, as this is both opaque (I only found out about this last month, after using Streamlit for over 2 years) and it makes the Streamlit codebase cleaner. This would be a breaking change though. However, this is up to you, and can be handled completely separately from this request. Regarding the default values. We can use overloads to only accept the combination I am currently on holiday, I can start on a simple demo PR in two weeks. Apologies for any errors, I wrote this on my phone. |
Checklist
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
(andpills
) API by adding an extra parameter 'required' . Ifrequired
is True, a value must always be selected.The text was updated successfully, but these errors were encountered: