Skip to content

Commit ef9ece6

Browse files
committed
Fixes ie issues in Hacker0x01#141 by eliminating infinite loop.
This commit does 2 specific things: It makes date_input.jsx properly state-less, reducing complexity. It also upgrades datepicker.jsx to prevent repeated calls clearing the state if it has already been cleared. IE would trigger an onChange every time we set its value to null, causing the clearSelection to bubble up, set state, set the value, and repeat ad nauseam. This also upgrades datepicker.jsx to follow best practices of using setState callbacks to prevent subtle timing bugs.
1 parent 397a8e5 commit ef9ece6

File tree

4 files changed

+30
-52
lines changed

4 files changed

+30
-52
lines changed

dist/react-datepicker.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,13 @@ return /******/ (function(modules) { // webpackBootstrap
155155
},
156156

157157
clearSelected: function clearSelected() {
158-
this.props.onChange(null);
158+
if (this.state.selected === null) return;
159159

160160
this.setState({
161161
selected: null
162-
});
162+
}, (function () {
163+
this.props.onChange(null);
164+
}).bind(this));
163165
},
164166

165167
onInputClick: function onInputClick() {
@@ -675,22 +677,12 @@ return /******/ (function(modules) { // webpackBootstrap
675677
};
676678
},
677679

678-
getInitialState: function getInitialState() {
679-
return {
680-
value: this.safeDateFormat(this.props.date)
681-
};
682-
},
683-
684680
componentDidMount: function componentDidMount() {
685681
this.toggleFocus(this.props.focus);
686682
},
687683

688684
componentWillReceiveProps: function componentWillReceiveProps(newProps) {
689685
this.toggleFocus(newProps.focus);
690-
691-
this.setState({
692-
value: this.safeDateFormat(newProps.date)
693-
});
694686
},
695687

696688
toggleFocus: function toggleFocus(focus) {
@@ -702,15 +694,12 @@ return /******/ (function(modules) { // webpackBootstrap
702694
},
703695

704696
handleChange: function handleChange(event) {
705-
var date = moment(event.target.value, this.props.dateFormat, true);
706-
707-
this.setState({
708-
value: event.target.value
709-
});
697+
var value = event.target.value;
698+
var date = moment(value, this.props.dateFormat, true);
710699

711700
if (date.isValid()) {
712701
this.props.setSelected(new DateUtil(date));
713-
} else if (event.target.value === "") {
702+
} else if (value === "") {
714703
this.props.clearSelected();
715704
}
716705
},
@@ -743,7 +732,7 @@ return /******/ (function(modules) { // webpackBootstrap
743732
ref: "input",
744733
type: "text",
745734
name: this.props.name,
746-
value: this.state.value,
735+
value: this.safeDateFormat(this.props.date),
747736
onClick: this.handleClick,
748737
onKeyDown: this.handleKeyDown,
749738
onFocus: this.props.onFocus,

0 commit comments

Comments
 (0)