-
Notifications
You must be signed in to change notification settings - Fork 30
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
fix(components): Keep only one DatePicker open at a time #2397
base: master
Are you sure you want to change the base?
Conversation
Deploying atlantis with
|
Latest commit: |
8da1e03
|
Status: | ✅ Deploy successful! |
Preview URL: | https://29366166.atlantis.pages.dev |
Branch Preview URL: | https://job-116104-job-116904-one-da.atlantis.pages.dev |
@@ -115,7 +117,7 @@ export function DatePicker({ | |||
const datePickerClassNames = classnames(styles.datePicker, { | |||
[styles.inline]: inline, | |||
}); | |||
const { pickerRef } = useEscapeKeyToCloseDatePicker(open, ref); | |||
const { pickerRef } = useEscapeKeyToCloseDatePicker(open); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the ref
removed from here wasn't needed for ESC key functionality; ESC key handler only needs pickerRef
to call setOpen(false)
and doesn't need the wrapper's ref
.
if ( | ||
openDatePickerRef.current && | ||
openDatePickerRef.current !== pickerRef.current | ||
) { | ||
openDatePickerRef.current.setOpen(false); | ||
} | ||
|
||
openDatePickerRef.current = pickerRef.current; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checks if there's already an open picker that's different from the current one and if found, closes the other picker.
Published Pre-release for 8da1e03 with versions:
To install the new version(s) for Web run:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, nice fix 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as well!
As discussed with the team we are going to try a different approach; I'm currently using a global variable which is a React anti-pattern.
Motivations
If an
InputDate
is open and focus is shifted to anotherInputDate
, they will both stay open. This can cause UX confusion & unintended side effects, especially when inputs are very close together. This PR addresses that and makes sure only 1DatePicker
can be open at a time.Changes
Added
Changed
Testing
<InputDate />
for an<InputText />
and when focus goes to theInputText
, the picker closesChanges can be
tested via Pre-release
In Atlantis we use Github's built in pull request reviews.