-
Notifications
You must be signed in to change notification settings - Fork 4
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
Calendar Modal Fix - Multiple Selections Display #471
base: master
Are you sure you want to change the base?
Conversation
|
[diff-counting] Significant lines: 47. |
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.
Works on my machine but have few suggestions
@@ -33,6 +33,7 @@ const Icon = () => ( | |||
|
|||
const MiniCal = () => { | |||
const { curDate, setCurDate } = useDate(); | |||
const datePickerRef = React.useRef<any>(null); |
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.
We can extend the types via
declare module 'react-datepicker' {
export default class ReactDatePicker {
setPreSelection?: (date: Date) => void;
}
}
to be able to do
const datePickerRef = React.useRef<any>(null); | |
const datePickerRef = React.useRef<DatePicker>(null); |
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.
imo we don't want to introduce more any
s into the system if we don't have to
if (datePickerRef.current) { | ||
datePickerRef.current.setSelected(today); | ||
} |
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.
Optional chaining works with function calls too; also setPreSelection
seems more appropriate than setSelected
here (likely less overhead). It's also what's used in react-datepicker
's native implementation of the "Today" button.
if (datePickerRef.current) { | |
datePickerRef.current.setSelected(today); | |
} | |
datePickerRef.current?.setPreSelection?.(today); |
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.
Great work on this PR Desmond! I think the changes look good, I tested them on different browsers and it seems to work properly. Because the CustomInput function does not have an internal state, it can be converted to a functional component to make the code a bit shorter, but it is not needed.
…into dka34/mini_cal
Summary
This pull request fixes the bug displayed on the Mini Calendar when selecting dates using the Today and Tomorrow buttons. Also addresses closing the modal when a date is selected (ideally not the intended behavior)
Test Plan
Choose dates using the Today and Tomorrow buttons when other dates are selected to identify behavior
Notes
Initial behavior
Screen.Recording.2023-10-22.at.13.25.08.mov
Fixed behavior
Screen.Recording.2023-10-22.at.13.23.53.mov
Breaking Changes
None