Skip to content

Commit 1597ee6

Browse files
committed
Fix clearable button does not call setProps
1 parent 66cfbe0 commit 1597ee6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

components/dash-core-components/src/fragments/DatePickerRange.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ const DatePickerRange = ({
135135
start_date: dateAsStr(internalStartDate),
136136
end_date: dateAsStr(internalEndDate),
137137
});
138+
} else if (!internalStartDate && !internalEndDate) {
139+
// Both dates cleared - send undefined for both
140+
setProps({
141+
start_date: dateAsStr(internalStartDate),
142+
end_date: dateAsStr(internalEndDate),
143+
});
138144
} else if (updatemode === 'singledate' && internalStartDate) {
139145
// Only start changed - send just that one
140146
setProps({start_date: dateAsStr(internalStartDate)});

components/dash-core-components/tests/integration/calendar/test_calendar_props.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,26 @@ def test_cdpr001_date_clearable_true_works(dash_dcc):
1313
[
1414
dcc.DatePickerRange(id="dpr", clearable=True),
1515
dcc.DatePickerSingle(id="dps", clearable=True),
16+
html.Div(id="dpr-output"),
17+
html.Div(id="dps-output"),
1618
]
1719
)
1820

21+
@app.callback(
22+
Output("dpr-output", "children"),
23+
Input("dpr", "start_date"),
24+
Input("dpr", "end_date"),
25+
)
26+
def display_range_dates(start_date, end_date):
27+
return f"Range: {start_date} - {end_date}"
28+
29+
@app.callback(
30+
Output("dps-output", "children"),
31+
Input("dps", "date"),
32+
)
33+
def display_single_date(date):
34+
return f"Single: {date}"
35+
1936
dash_dcc.start_server(app)
2037

2138
# DPR
@@ -26,21 +43,34 @@ def test_cdpr001_date_clearable_true_works(dash_dcc):
2643
"1" in start_date and "28" in end_date
2744
), "both start date and end date should match the selected day"
2845

46+
# Verify callback received the dates
47+
dash_dcc.wait_for_text_to_equal("#dpr-output", f"Range: {start_date} - {end_date}")
48+
2949
close_btn.click()
3050
sleep(0.25)
3151
start_date, end_date = dash_dcc.get_date_range("dpr")
3252
assert not start_date and not end_date, "both start and end dates should be cleared"
3353

54+
# Verify callback received the cleared dates (None)
55+
dash_dcc.wait_for_text_to_equal("#dpr-output", "Range: None - None")
56+
3457
# DPS
3558
selected = dash_dcc.select_date_single("dps", day="1")
3659

3760
assert selected, "single date should get a value"
61+
62+
# Verify callback received the date
63+
dash_dcc.wait_for_text_to_equal("#dps-output", f"Single: {selected}")
64+
3865
close_btn = dash_dcc.wait_for_element("#dps-wrapper .dash-datepicker-clear")
3966
close_btn.click()
4067
sleep(0.25)
4168
(single_date,) = dash_dcc.get_date_range("dps")
4269
assert not single_date, "date should be cleared"
4370

71+
# Verify callback received the cleared date (None)
72+
dash_dcc.wait_for_text_to_equal("#dps-output", "Single: None")
73+
4474
assert dash_dcc.get_logs() == []
4575

4676

0 commit comments

Comments
 (0)