Skip to content

Commit 2eb2aba

Browse files
committed
Update focus and blue events to take calendar into account. 1.1 Release. #1
1 parent 8d16ac2 commit 2eb2aba

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

example/app.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ const App = React.createClass({
6969
</form>
7070
</Col>
7171
</Row>
72+
<Row>
73+
<Col xs={12}>
74+
<h2>Blur and Focus Events</h2>
75+
</Col>
76+
</Row>
77+
<Row>
78+
<Col sm={6}>
79+
<form>
80+
<DatePicker placeholder="Placeholder" help="Open console to see focus/blur logging." value={this.state.date} onFocus={() => {console.log("Focus")}} onBlur={() => {console.log("Blur")}}/>
81+
</form>
82+
</Col>
83+
</Row>
7284
<Row>
7385
<Col xs={12}>
7486
<h2>Styles</h2>

lib/index.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ var Calendar = _react2.default.createClass({
8888
displayDate: _react2.default.PropTypes.object.isRequired,
8989
onChange: _react2.default.PropTypes.func.isRequired,
9090
dayLabels: _react2.default.PropTypes.array.isRequired,
91-
cellPadding: _react2.default.PropTypes.string.isRequired
91+
cellPadding: _react2.default.PropTypes.string.isRequired,
92+
onUnmount: _react2.default.PropTypes.func.isRequired
93+
},
94+
componentWillUnmount: function componentWillUnmount() {
95+
this.props.onUnmount();
9296
},
9397
handleClick: function handleClick(day) {
9498
var newSelectedDate = new Date(this.props.displayDate);
@@ -232,7 +236,21 @@ exports.default = _react2.default.createClass({
232236
this.props.valueLink.requestChange(null);
233237
}
234238
},
239+
handleHide: function handleHide(e) {
240+
if (document.activeElement === this.refs.input.getInputDOMNode()) {
241+
return;
242+
}
243+
this.setState({
244+
focused: false
245+
});
246+
if (this.props.onBlur) {
247+
this.props.onBlur(e);
248+
}
249+
},
235250
handleFocus: function handleFocus(e) {
251+
if (this.refs.overlay.state.isOverlayShown === true) {
252+
return;
253+
}
236254
this.setState({
237255
focused: true
238256
});
@@ -241,6 +259,9 @@ exports.default = _react2.default.createClass({
241259
}
242260
},
243261
handleBlur: function handleBlur(e) {
262+
if (this.refs.overlay.state.isOverlayShown === true) {
263+
return;
264+
}
244265
this.setState({
245266
focused: false
246267
});
@@ -329,7 +350,7 @@ exports.default = _react2.default.createClass({
329350
var popOver = _react2.default.createElement(
330351
_Popover2.default,
331352
{ id: 'calendar', title: calendarHeader },
332-
_react2.default.createElement(Calendar, { cellPadding: this.props.cellPadding, selectedDate: this.state.selectedDate, displayDate: this.state.displayDate, onChange: this.onChangeDate, dayLabels: this.props.dayLabels })
353+
_react2.default.createElement(Calendar, { cellPadding: this.props.cellPadding, selectedDate: this.state.selectedDate, displayDate: this.state.displayDate, onChange: this.onChangeDate, dayLabels: this.props.dayLabels, onUnmount: this.handleHide })
333354
);
334355
var buttonStyle = this.props.bsStyle === "error" ? "danger" : this.props.bsStyle;
335356
var clearButton = _react2.default.createElement(

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-bootstrap-date-picker",
33
"keywords": ["react", "react-component", "react-bootstrap", "bootstrap", "date picker", "calendar", "date", "picker"],
44
"main": "lib/index.js",
5-
"version": "1.0.2",
5+
"version": "1.1.0",
66
"description": "React-Bootstrap based date picker.",
77
"directories": {
88
"test": "test"

src/index.jsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ const Calendar = React.createClass({
5656
displayDate: React.PropTypes.object.isRequired,
5757
onChange: React.PropTypes.func.isRequired,
5858
dayLabels: React.PropTypes.array.isRequired,
59-
cellPadding: React.PropTypes.string.isRequired
59+
cellPadding: React.PropTypes.string.isRequired,
60+
onUnmount: React.PropTypes.func.isRequired
61+
},
62+
componentWillUnmount(){
63+
this.props.onUnmount();
6064
},
6165
handleClick(day) {
6266
const newSelectedDate = new Date(this.props.displayDate);
@@ -187,7 +191,21 @@ export default React.createClass({
187191
this.props.valueLink.requestChange(null);
188192
}
189193
},
194+
handleHide(e){
195+
if(document.activeElement === this.refs.input.getInputDOMNode()) {
196+
return;
197+
}
198+
this.setState({
199+
focused: false
200+
});
201+
if(this.props.onBlur) {
202+
this.props.onBlur(e);
203+
}
204+
},
190205
handleFocus(e){
206+
if(this.refs.overlay.state.isOverlayShown === true) {
207+
return;
208+
}
191209
this.setState({
192210
focused: true
193211
});
@@ -196,6 +214,9 @@ export default React.createClass({
196214
}
197215
},
198216
handleBlur(e){
217+
if(this.refs.overlay.state.isOverlayShown === true) {
218+
return;
219+
}
199220
this.setState({
200221
focused: false
201222
});
@@ -284,7 +305,7 @@ export default React.createClass({
284305
onChange={this.onChangeMonth}
285306
monthLabels={this.props.monthLabels} />;
286307
const popOver = <Popover id="calendar" title={calendarHeader}>
287-
<Calendar cellPadding={this.props.cellPadding} selectedDate={this.state.selectedDate} displayDate={this.state.displayDate} onChange={this.onChangeDate} dayLabels={this.props.dayLabels} />
308+
<Calendar cellPadding={this.props.cellPadding} selectedDate={this.state.selectedDate} displayDate={this.state.displayDate} onChange={this.onChangeDate} dayLabels={this.props.dayLabels} onUnmount={this.handleHide} />
288309
</Popover>;
289310
const buttonStyle = this.props.bsStyle === "error" ? "danger" : this.props.bsStyle;
290311
const clearButton = <Button onClick={this.clear} bsStyle={buttonStyle || "default"} disabled={!this.state.inputValue}>{this.props.clearButtonElement}</Button>;

0 commit comments

Comments
 (0)