Skip to content

[BUG] Daterange picker layout changes Dash 3.4 to 4.0 to 4.1 #3784

@ghaarsma

Description

@ghaarsma

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:

from datetime import datetime, timedelta, UTC

from dash import Dash, dcc, html
import dash_bootstrap_components as dbc

end_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):
Image

Dash 4.0:
Image

Dash 4.1:
Image

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
Image

Dash 4.0
Image

Dash 4.1

dash_dr_picker.py

Image

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions