When using a daterange picker with style={"width": "fit-content"} inside a dashbootstrap Row, the layout keeps changing between Dash releases. Biggest change is from Dash 3.4 to Dash 4.0, but Dash 4.0 to 4.1 introduced another layout change.
The following example creates 3 different layouts, but under 3.4 it works as expected:
fromdatetimeimportdatetime, timedelta, UTCfromdashimportDash, dcc, htmlimportdash_bootstrap_componentsasdbcend_date=datetime.now(UTC).replace(hour=0, minute=0, second=0, microsecond=0)
start_date=end_date-timedelta(days=7)
app=Dash(__name__, title="Dash", external_stylesheets=[dbc.themes.BOOTSTRAP])
app.layout= (
html.Div(
dbc.Row(
[
dbc.Label("Date Range", className="me-2", width="auto"),
dcc.DatePickerRange(
id="date-range-picker",
start_date=start_date,
end_date=end_date,
display_format="YYYY-MM-DD",
style={"width": "fit-content"},
)
],
justify="center",
align="center",
className="g-0 flex-nowrap",
)
),
)
if__name__=="__main__":
app.run(debug=True)Dash 3.4 (with bootstrap 2.04):

Dash 4.0:

Dash 4.1:

The cause seems to be extra HTML div that are inserted. One for Dash 4.0 and two for Dash 4.1.
Dash 3.4

Dash 4.0

Dash 4.1
dash_dr_picker.py

When using a daterange picker with
style={"width": "fit-content"}inside a dashbootstrap Row, the layout keeps changing between Dash releases. Biggest change is from Dash 3.4 to Dash 4.0, but Dash 4.0 to 4.1 introduced another layout change.The following example creates 3 different layouts, but under 3.4 it works as expected:
Dash 3.4 (with bootstrap 2.04):

Dash 4.0:

Dash 4.1:

The cause seems to be extra HTML div that are inserted. One for Dash 4.0 and two for Dash 4.1.
Dash 3.4

Dash 4.0

Dash 4.1
dash_dr_picker.py