Skip to content

Commit

Permalink
Fix: Retain the selected date when changing the time
Browse files Browse the repository at this point in the history
Closes #4268
  • Loading branch information
Balaji Sridharan committed Sep 29, 2023
1 parent 6bbc587 commit 6c9a350
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/inputTime.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ export default class inputTime extends React.Component {

onTimeChange = (time) => {
this.setState({ time });
const date = new Date();

const { date: propDate } = this.props;
const isPropDateValid = propDate instanceof Date && !isNaN(propDate);
const date = isPropDateValid ? propDate : new Date();

date.setHours(time.split(":")[0]);
date.setMinutes(time.split(":")[1]);

this.props.onChange(date);
};

Expand Down

0 comments on commit 6c9a350

Please sign in to comment.