Interactive widgets should not output labels if label argument is an empty string
See original GitHub issueSummary
Since Streamlit 0.83, all the interactive widgets (except for streamlit.radio) outputs a <label>
element for the widget even if the label value is an empty string. Before 0.83, setting a widget’s label to an empty string left out the <label>
element.
The current behaviour results in unwanted vertical whitespace before a widget for empty labels.
Steps to reproduce
Code snippet:
import streamlit as st
for widget in (st.text_input, st.number_input, st.date_input, st.time_input, st.slider, st.color_picker, st.text_area):
st.subheader(widget.__name__)
c1, c2 = st.beta_columns(2)
with c1:
widget("Label")
with c2:
widget("")
for widget in (st.selectbox, st.radio, st.multiselect, st.select_slider):
st.subheader(widget.__name__)
c1, c2 = st.beta_columns(2)
with c1:
widget("Label", ["A", "B", "C"])
with c2:
widget("", ["A", "B", "C"])
The code snippet shows the differences for all the interactive widget. But, here’s a select screenshot showing the differences between 0.82 and 0.84 for streamlit.selectbox and streamlit.radio. In Streamlit 0.84, only streamlit.radio works the same as before. Everything else outputs empty <label>
elements.
Streamlit 0.82:
Streamlit 0.84:
Expected behavior:
All the widgets should omit outputting labels if the label argument is an empty string.
Actual behavior:
The streamlit.radio widget is the only one that does not output empty labels.
Is this a regression?
The current behaviour was introduced in Streamlit 0.83.
Debug info
- Streamlit version: Streamlit, version 0.84.2
- Python version: Python 3.8.11
- Using Conda? PipEnv? PyEnv? Pex? Just pip
- OS version: Debian buster (in a python:3.8 container)
- Browser version: Safari 14.1 on macOS Mojave 10.14.6
Additional information
None.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
The issue’s a bit complicated, because it seems the empty
<label>
elements were intentionally added in #3317, in response to #3220. That PR optimizes for alignment across columns, but reverses past behaviour and gets in the way for other layouts.I’m hiding the empty labels for now with a bit of css.
Hey, this is fixed now with the
label_visibility
param, that we add for all widgets with labels.We encourage to always use a meaningful labels for accessibility reasons
But now you can use keyword argument
label_visibility="hidden"
to hide label orlabel_visibility="collapsed"
to collapse whitespace completely.This feature will be available on streamlit 1.13.0 (or you can use it now with
streamlit-nightly