Skip to content

USWDS - Date Picker: prevent focusout out-of-order issue in safari #6450

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

anmazz
Copy link
Contributor

@anmazz anmazz commented Mar 25, 2025

Summary

Fixes Safari issues where clicking the calendar button a second time would not close calendar.

Breaking change

⚠️ This is potentially a breaking change.

Related issue

Closes #6449

Problem statement

The Date Picker in Safari doesn't work properly when trying to close the calendar via the calendar button.

Solution

Sets a "preventFocusOut" flag during the mousedown event to capture the event prior to focusout or click.
The order is as follows in Safari from my testing:

  • User clicks button
  • mousedown fired (set preventFocusOut to true)
  • focusout fired (since preventFocusout is set to true, ignore the calendar toggle)
  • click (reset preventFocusOut)

Adding the mousedown event listener allows for the ability to intercept the click on the button before focusout is fired.
In Chromium browsers/Firefox, the order of events is click and then focusout, which is why those browsers don't have issues. The click toggles the calendar off, and the focusout will try to hide the calendar again, which is fine since it's already closed.

Testing and review

The date picker should be tested with all browsers that clicking the calendar button once opens the calendar, and clicking it again closes it. Clicking outside of the element should close the calendar as well.

It didn't seem as though the calendar button was keyboard accessible, so I'm wondering if there is anything to be done in that regard.

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.

USWDS - Bug: Clicking Date Picker calendar button to close calendar doesn't work
1 participant