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

[date-picker] Selecting today doesn't always update the selected day indicator #7438

Open
juuso-vaadin opened this issue May 23, 2024 · 5 comments
Labels
needs discussion No decision yet, discussion needed needs research More information needed to estimate UX User experience issue vaadin-date-picker

Comments

@juuso-vaadin
Copy link
Contributor

Description

When current day is scrolled away from the view and "Today" button is clicked, the visual indicator for selected day isn't updated even though the value on the field is.

DatePicker_today.mov

Expected outcome

Selected day indicator in calendar should always match the value in the input.

Minimal reproducible example

Component demo in docs

Steps to reproduce

  1. Open date picker overlay
  2. Scroll current date out of view
  3. Click "Today"

Environment

Vaadin version(s): 24

Browsers

Chrome

@juuso-vaadin juuso-vaadin changed the title [date-picker] Selecting today doesn't always visually update the selected item [date-picker] Selecting today doesn't always update the selected day indicator May 23, 2024
@rolfsmeds rolfsmeds added the bug Something isn't working label May 24, 2024
@rolfsmeds
Copy link
Contributor

So, the way the DatePicker calendar works is that when you click Today, if the today-date is currently in the calendar's viewport, it selects it and closes the overlay, but if the today-date is not currently in the calendar's viewport, it will instead focus the date and scrolls it into the viewports calendar.

This seems to have been a design decision back when the DatePicker was created. The question now is if we should change that decision so that the behavior of the Today button would be more consistent.

@juuso-vaadin , @jouni do you have opinions on this?

@rolfsmeds rolfsmeds added waiting for author Further information is requested UX User experience issue and removed bug Something isn't working labels May 24, 2024
@juuso-vaadin
Copy link
Contributor Author

if the today-date is not currently in the calendar's viewport, it will instead focus the date and scrolls it into the viewports calendar.

It doesn't only focus the current date. Clicking Today will always set the value. To me this is a bug as the active value and visualization don't stay in sync.

@rolfsmeds
Copy link
Contributor

Ah, indeed, but it's not just the Today button: focusing a date (manually by keyboard) also selects it (albeit without committing it to the field and closing the overlay). Observe the value in the field changing as you select:

Screen.Recording.2024-05-27.at.9.08.44.mov

In the DP calendar, focusing a date actually selects that date in the overlay, and that selection is committed to the field when you click outside the overlay or press enter. This means that

  • The focus ring matches the date currently selected in the overlay and displayed in the field
  • The blue background state actually means the date currently committed to the field (which may not be what is currently shown in the field in case another date has been focused)
  • Clicking Today when today's date is outside the viewport focuses today's date, which also selects it in the overlay (but does not commit it to the field).

So, the visual indication that happens when you click Today is consistent with how the calendar overlay behaves in general, but that behavior may be rather unintuitive and should probably be reconsidered.

@rolfsmeds rolfsmeds added needs research More information needed to estimate needs discussion No decision yet, discussion needed and removed waiting for author Further information is requested labels May 27, 2024
@juuso-vaadin
Copy link
Contributor Author

Ok, I missed the difference between selecting and committing. Overall I haven't heard the current behavior being an issue. Now it just seems a bit unexpected when reviewed critically.

I originally started looking into the Today button as a customer was asking why it sometimes closes the overlay but not always. Seems that if the overlay is scrolled even slightly, first click on Today will center to current date and second click will close overlay. Maybe the expectation would be to close the overlay on click of Today if the current date is already within view area.

@web-padawan
Copy link
Member

Here's the logic in the overlay content where we detect whether to select and close, or scroll into view:

if (Math.abs(this._monthScroller.position - this._differenceInMonths(today, this._originDate)) < 0.001) {
// Select today only if the month scroller is positioned approximately
// at the beginning of the current month
this._selectDate(today);
this._close();
} else {
this._scrollToCurrentMonth();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs discussion No decision yet, discussion needed needs research More information needed to estimate UX User experience issue vaadin-date-picker
Projects
None yet
Development

No branches or pull requests

3 participants