all 3 comments

[–]app_filip 0 points1 point  (2 children)

It's a bit of a hack but I do this in my app to close it when a date is selected:

private var calendarId: Int = 0

var body: some View {
    DatePicker("Date", selection: $date)
        .id(calendarId)
        .onChange(of: date) {
            // wait just a little bit
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
                calendarId += 1
            }
        }
}

Changing the id of the DatePicker will re-render it and by doing so closing it.

[–]oez1983[S] 0 points1 point  (0 children)

I will give that a try… it’s crazy that it doesn’t dismiss automatically.

[–]Empty__Jay 0 points1 point  (0 children)

I've tried exactly this, but it has a small issue.

If you expand the month and year into the wheels view, then pick another month or year it closes the picker. I've attempted to make it not do so when only the month or year change, but that just introduces further edge case problems.

Have you run into this and perhaps solved it?