Skip to content

Commit a6ec20b

Browse files
committedMay 17, 2018
🐛 [bug]fix when scrolling 2 wheels at the same it is possible to set a date outside min/maxDate(#27)
1 parent 3f6ef0d commit a6ec20b

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed
 

‎examples/basic/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import DatePicker from '../../lib/index';
77
(function main() {
88
class App extends React.Component {
99
state = {
10-
time: new Date(2016, 8, 16, 8, 20, 57),
10+
time: new Date(),
1111
isOpen: false,
1212
theme: 'default',
1313
}
@@ -75,6 +75,7 @@ import DatePicker from '../../lib/index';
7575
<DatePicker
7676
value={this.state.time}
7777
dateSteps={[1, 1, 5]}
78+
max={new Date()}
7879
dateFormat={['YYYY', ['MM', (month) => monthMap[month]], 'DD']}
7980
theme={this.state.theme}
8081
isOpen={this.state.isOpen}

‎lib/DatePicker.js

+16
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ class DatePicker extends Component<void, Props, State> {
5050
}
5151
}
5252

53+
/**
54+
* When you swipe two datepickeritems at the same time.
55+
* Prevent dates from going out.
56+
*/
57+
componentDidUpdate() {
58+
const value = this.state.value;
59+
const { min, max } = this.props;
60+
if (value.getTime() > max.getTime()) {
61+
this.setState({ value: max });
62+
}
63+
64+
if (value.getTime() < min.getTime()) {
65+
this.setState({ value: min });
66+
}
67+
}
68+
5369
/**
5470
* Optimization component, Prevents unnecessary rendering
5571
* Only props or state change or value before re-rendering

‎webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121
devtool: 'eval-source-map',
2222
devServer: {
2323
historyApiFallback: true,
24+
disableHostCheck: true,
2425
hot: true,
2526
inline: true,
2627
host: '0.0.0.0',

0 commit comments

Comments
 (0)
Please sign in to comment.