Skip to content

Commit

Permalink
🐛 [bug]fix when scrolling 2 wheels at the same it is possible to set …
Browse files Browse the repository at this point in the history
…a date outside min/maxDate(#27)
  • Loading branch information
lanjingling0510 committed May 17, 2018
1 parent 3f6ef0d commit a6ec20b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion examples/basic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import DatePicker from '../../lib/index';
(function main() {
class App extends React.Component {
state = {
time: new Date(2016, 8, 16, 8, 20, 57),
time: new Date(),
isOpen: false,
theme: 'default',
}
Expand Down Expand Up @@ -75,6 +75,7 @@ import DatePicker from '../../lib/index';
<DatePicker
value={this.state.time}
dateSteps={[1, 1, 5]}
max={new Date()}
dateFormat={['YYYY', ['MM', (month) => monthMap[month]], 'DD']}
theme={this.state.theme}
isOpen={this.state.isOpen}
Expand Down
16 changes: 16 additions & 0 deletions lib/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ class DatePicker extends Component<void, Props, State> {
}
}

/**
* When you swipe two datepickeritems at the same time.
* Prevent dates from going out.
*/
componentDidUpdate() {
const value = this.state.value;
const { min, max } = this.props;
if (value.getTime() > max.getTime()) {
this.setState({ value: max });
}

if (value.getTime() < min.getTime()) {
this.setState({ value: min });
}
}

/**
* Optimization component, Prevents unnecessary rendering
* Only props or state change or value before re-rendering
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
devtool: 'eval-source-map',
devServer: {
historyApiFallback: true,
disableHostCheck: true,
hot: true,
inline: true,
host: '0.0.0.0',
Expand Down

0 comments on commit a6ec20b

Please sign in to comment.