Skip to content

Commit 402af61

Browse files
committed
Auto select dates upon expanding date pickers
1 parent 4837ab9 commit 402af61

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

WooCommerce/Classes/Bookings/BookingFilters/BookingDateTimeFilterView.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ struct BookingDateTimeFilterView: View {
5858
.background(Color(.listBackground))
5959
.onChange(of: fromDate) { _, newValue in
6060
selectedFromDate = newValue
61-
onSelection(selectedFromDate, selectedToDate)
6261
}
6362
.onChange(of: toDate) { _, newValue in
6463
selectedToDate = newValue
65-
onSelection(selectedFromDate, selectedToDate)
64+
65+
}
66+
.onChange(of: selectedFromDate) { _, newValue in
67+
onSelection(newValue, selectedToDate)
68+
}
69+
.onChange(of: selectedToDate) { _, newValue in
70+
onSelection(selectedFromDate, newValue)
6671
}
6772
}
6873
}
@@ -73,6 +78,15 @@ private extension BookingDateTimeFilterView {
7378
Button {
7479
withAnimation {
7580
expandedPicker = expandedPicker == type ? nil : type
81+
/// auto selects dates upon expanding the date picker
82+
if selectedDate == nil {
83+
switch type {
84+
case .fromDate, .fromTime:
85+
selectedFromDate = displayedDate.wrappedValue
86+
case .toDate, .toTime:
87+
selectedToDate = displayedDate.wrappedValue
88+
}
89+
}
7690
}
7791
} label: {
7892
HStack {

0 commit comments

Comments
 (0)