Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Fix #169 : Add event as 3rd parameter #173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ export type ValueLink = {
requestChange(e: Date): void
}

export type DateOnChangeHandlerWithEvent = {
// Event will not emit if it's selected from DatePicker (not typed)
(jsDate: Date, dateString: string, event?: React.ChangeEvent<HTMLInputElement>): void;
}

export type DateOnChangeHandler = {
(jsDate: Date, dateString: string): void;
}

export interface DatePickerInputProps {
value?: Value,
valueLink?: ValueLink,
onChange?: DateOnChangeHandler,
onChange?: DateOnChangeHandlerWithEvent,
onShow?: () => void,
onHide?: () => void,
onClear?: () => void,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"karma-webpack": "^1.7.0",
"mocha": "^2.5.3",
"node-libs-browser": "^1.0.0",
"node-sass": "^3.7.0",
"node-sass": "^4.13.0",
"react": "^0.14",
"react-addons-test-utils": "^0.14.8",
"react-dom": "^0.14",
Expand Down
7 changes: 5 additions & 2 deletions src/DatePickerInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ export default class DatePickerInput extends React.Component {
}
}

onChangeInput = ({ target: { value: dateString } }) => {
onChangeInput = (event) => {
const { target: { value: dateString } } = event;
event.persist();

if (dateString || this.state.date) {
const parsedDate = this.parseInputDateString(dateString);
const date = parsedDate.isValid() ? parsedDate : this.state.date;
Expand All @@ -228,7 +231,7 @@ export default class DatePickerInput extends React.Component {
dateString,
date,
hasValue: parsedDate.isValid()
}, () => this.getValueLink().requestChange(jsDate, returnedDateString));
}, () => this.getValueLink().requestChange(jsDate, returnedDateString, event));
} else if (!dateString) {
this.setState({ dateString });
}
Expand Down