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

Bug: Documentation: Input Fields Example #1910

Closed
gtonussi opened this issue Sep 23, 2023 · 1 comment · Fixed by #1911
Closed

Bug: Documentation: Input Fields Example #1910

gtonussi opened this issue Sep 23, 2023 · 1 comment · Fixed by #1911
Assignees
Labels
docs Documentation only changes

Comments

@gtonussi
Copy link

Bug description

On documentation, on example for Date Picker Dialog with single select, the function "handleDaySelect" has an incorrect interface that causes a typescript error when assigning it to "onSelect" prop on DayPicker component.

To reproduce

1- Copy and paste this code on a React project with dependencies for React DayPicker installed:
https://react-day-picker.js.org/guides/input-fields#example-date-picker-dialog

2- You will notice the following error on "onSelect":

Type '(date: Date) => void' is not assignable to type 'SelectSingleEventHandler'.

Expected behavior

The code should compile with no type errors.

Suggested fix

I kindly suggest that the type of "handleDaySelect" function to be "SelectSingleEventHandler" and that the "date" parameter receives a "Date | undefined". That solved the error for me:

const handleDateSelect: SelectSingleEventHandler = (date: Date | undefined) => {
    setSelected(date);
    if (date) {
      setInputValue(format(date, 'y-MM-dd'));
      closePopper();
    } else {
      setInputValue('');
    }
}

The fix is basically use the same type as Range example for that function, but with correct EventHandler.

If it is a correct fix and doc website is open to contribute, I would be glad to do it.

@gtonussi gtonussi added the bug Bug or Bug fixes label Sep 23, 2023
@gpbl
Copy link
Owner

gpbl commented Sep 23, 2023

Hi @gtonussi. nice find. Yes, your suggestion would fix it!

However, this type error should have been caught by our type-check. I suspect we are not enabling "strict" mode in our website. Let me fix it first!

@gpbl gpbl added docs Documentation only changes and removed bug Bug or Bug fixes labels Sep 23, 2023
@gpbl gpbl self-assigned this Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation only changes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants