Skip to content

Commit 8752631

Browse files
committed
unselect any date in DayPicker if the date in the state is not valid
1 parent a462aac commit 8752631

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/components/widgets/DateTimePicker.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,12 @@ export default class DateTimePicker extends Component {
208208
}
209209

210210
render() {
211-
const JSDate = new Date(this.getAdjustedPlotlyJSDateTime(this.props.value));
212-
const currentYear = JSDate.getFullYear();
211+
const JSDate = new Date(
212+
this.getAdjustedPlotlyJSDateTime(this.state.dateValue + ' ' + testTime)
213+
);
214+
const isValidJSDate = JSDate.toDateString() !== 'Invalid Date';
215+
const currentYear = isValidJSDate ? JSDate.getFullYear() : new Date().getFullYear();
216+
const currentMonth = isValidJSDate ? JSDate.getMonth() : new Date().getMonth();
213217

214218
return (
215219
<div className="datetimepicker-container">
@@ -237,7 +241,7 @@ export default class DateTimePicker extends Component {
237241
<div className="datetimepicker-datepicker-navbar">
238242
<Dropdown
239243
options={this.getMonthOptions()}
240-
value={JSDate.getMonth()}
244+
value={currentMonth}
241245
className="datimepicker-monthpicker"
242246
clearable={false}
243247
onChange={this.onMonthChange}
@@ -252,8 +256,8 @@ export default class DateTimePicker extends Component {
252256
</div>
253257
<DayPicker
254258
className="datepicker-container-rce"
255-
modifiers={{highlighted: JSDate}}
256-
month={JSDate}
259+
modifiers={{highlighted: isValidJSDate ? JSDate : ''}}
260+
month={isValidJSDate ? JSDate : new Date()}
257261
onDayClick={value => {
258262
const plotlyDate = this.toPlotlyJSDate(value).split(' ')[0];
259263
this.onDateChange(plotlyDate);

src/styles/components/widgets/_datetimepicker.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,11 @@
117117
.dropdown-container.datimepicker-yearpicker div div {
118118
border: none;
119119
}
120+
121+
.DayPicker-Day--today {
122+
font-weight: var(--font-weight-normal);
123+
}
124+
125+
.DayPicker-Day--today:not(.DayPicker-Day--highlighted) {
126+
color: var(--color-text-base);
127+
}

0 commit comments

Comments
 (0)