Skip to content
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

Fix debounce by updating popover returnFocus #496

Merged
merged 4 commits into from
Jan 31, 2025

Conversation

AnnMarieW
Copy link
Collaborator

closes #495

When debounce=True, the value is updated when the input loses focus.

In a recent Mantine update, they changed the default popover prop returnFocus to false, which meant that the Input wasn't focused after the dates were selected. This broke the debounce because it wasn't possible to update the value when the input loses focus.

import dash_mantine_components as dmc
from dash import Dash, _dash_renderer, Input, Output, html, callback
_dash_renderer._set_react_version("18.2.0")

app = Dash(external_stylesheets=dmc.styles.ALL)

from datetime import datetime, date, timedelta


component = html.Div(
    [
        dmc.DatePickerInput(
            id="date-picker-input-multiple",
            label="Pick dates",
            description="Pick one or more dates",
            minDate=date(2020, 8, 5),
            value=[datetime.now().date(), datetime.now().date() + timedelta(days=5)],
            w=400,
            type="multiple",
            placeholder="Pick dates",
            maw=300,
            clearable=True,
            debounce=True,
        #    popoverProps={"returnFocus": True}   # this was required in order for the debounce to work in 0.15.2
        ),
        dmc.Space(h=10),
        dmc.Text(id="selected-date-input-multiple"),
    ]
)


@callback(
    Output("selected-date-input-multiple", "children"),
    Input("date-picker-input-multiple", "value"),
)
def update_output(dates):
    return str(dates)

app.layout = dmc.MantineProvider(
    component
)

if __name__ == "__main__":
    app.run(debug=True)


Copy link

Test Environment for snehilvj/dash-mantine-components-496
Updated on: 2025-01-28 22:06:25 UTC

oelhammouchi pushed a commit to oelhammouchi/dash-mantine-components that referenced this pull request Jan 29, 2025
Comment on lines 104 to 105
popoverProps={{returnFocus: true}}
{...others}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we want to merge this with any popoverProps you provide explicitly? ie pull popoverProps out of props, then here:

popoverProps={{returnFocus: true, ...popoverProps}}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nice catch - yes, that's how it should work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That needs to be applied to #471 too

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃

@AnnMarieW AnnMarieW merged commit 1b4524a into snehilvj:master Jan 31, 2025
1 check passed
@AnnMarieW AnnMarieW deleted the fix-debounce-focus-trap branch January 31, 2025 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Debounce stopped working in DatePickerInput in 0.15.2
2 participants