Skip to content

DayPickerInput.onDayChange wrong type in TypeScript definition? #622

@thomastvedt

Description

@thomastvedt

I'm trying out the DayPickerInput component in TypeScript, but I can't access the modifiers in the onDayChange event. Are the TypeScript typings wrong? Or am I missing something?

From the docs:
http://react-day-picker.js.org/api/DayPickerInput

onDayChange (day: Date, modifiers: Object) ⇒ void
Handler function called when the user types a valid day (according to the format prop) or when a day is clicked on the calendar. If the day is not valid, day and modifiers arguments will be undefined (useful to display validation warnings).

From /types/props.d.ts:
onDayChange?(e: React.FocusEvent<HTMLDivElement>): void;

Should this be instead:
onDayChange?(day: Date | undefined, modifiers: {} | undefined): void;
?

Is there a type for Modifiers btw?

If I try to do this:
<DayPickerInput onDayChange={this.handleDayChange} />

this works:
handleDayChange = (e: any) => { console.log('this works, e is date, not focusevent');}

this should work (?), but does not..:
handleDayChange = (day: Date, modifiers: {} | undefined) => { console.log('error');}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions