Number_input without stepper

Say, is it possible to have the number_input widget NOT show the -/+ stepper ?

I have an app with tens of numeric inputs that are miscellaneous physical quantities…a stepper does not make sense and it is getting in the way of a smooth user experience.

The way that it bother the user experience is when tabbing from one input to the next, without the stepper, a single tab would take me to the next input; with the stepper, I need to tab 3 times !!

1 Like

Hi @gsal, one possible hack is to use a text_input and convert the user entry into a number/float in the widget callback.

Cheers

I see; that’s an idea, I guess.

But then

  • I need two widgets, one for the label and one for the number
  • It will be my responsibility to validate and make sure the entry can be converted to a number and/or not allowed the typing of non-numeric characters (when is the callback called? after typing every character or until pressing enter or tab?)

Thanks, again.

  1. You just need 1 widget - the label is part of the widget
  2. Yes, you will have to validate the user entry. For invalid inputs, you can blank the entry via the session state[key of your widget] = ‘’. You could also add a conditional st.error within the callback

Cheers

Hey @gsal, you could try using CSS to hide + and - buttons for the stepper

st.markdown(
        """
        <style>
            [class="css-76z9jo e1jwn65y2"]{
                display: none;
            }
        """,
        unsafe_allow_html=True,
    )

Optional stepper would be really nice to have, so that the other functionality of number_input() can be reused when the stepper hurts the UX. I suggest you file a feature request.

1 Like

That’s true, @Goyo. For that reason, I just used st.text_input in my scenario, as the field can have an empty string.

number = st.text_input('Enter your number', placeholder='000')
if number != '':
    try:
        number = int(number)  # try to convert the variable to an integer
    except ValueError:  # if it's not convertible, catch the ValueError exception
        st.markdown(f"Oh no 😱 **:red[{number}]** is NOT a number")

And yes, having the option to display or not display the stepper buttons would be great. This feature has already been suggested here on Dec 24, 2019

1 Like

Oh, sorry, I misread your initial post. I thought you suggested to use text; but, it is text_input, so, yes, one widget.

I see, this was brought up before

  • 2019-Dec, ajberlier opened issue #894
  • 2021-Feb, CFrez created pull-request #2791 and proposed an implementation of the freature
  • 2021-Mar, somebody from the product team denied the request and closed it
  • 2021-Sep, ks00x opened issue #3630; it was marked as duplicate of #894 and closed
  • 2022- , user continue to show interest on this feature request
  • 2023-Feb, latest post to issue #894 by walsha2 with proposed remedy; thought, I presonally don’t know what to do with it, where to place it, how to use it.

So, yes, this feature request has been kicked around for 3 years…but no cigar.

1 Like

Hey, @gsal , I don’t know if you saw the latest releases, but now, a single tab can bring you to the next input, not three anymore. Basically, the steps are ignored when using tab.