Skip to content

Commit 51e7393

Browse files
committed
Add event target to onFocus and onBlur events.
1 parent 1e9a01b commit 51e7393

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/index.jsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,18 @@ export default React.createClass({
198198
this.props.onChange(null);
199199
}
200200
},
201-
handleHide(e){
201+
handleHide(){
202202
if(this.state.inputFocused) {
203203
return;
204204
}
205205
this.setState({
206206
focused: false
207207
});
208208
if(this.props.onBlur) {
209-
this.props.onBlur(e);
209+
const event = document.createEvent('CustomEvent');
210+
event.initEvent("Change Date", true, false);
211+
ReactDOM.findDOMNode(this.refs.hiddenInput).dispatchEvent(event);
212+
this.props.onBlur(event);
210213
}
211214
},
212215
handleKeyDown(e){
@@ -215,7 +218,10 @@ export default React.createClass({
215218
focused: false
216219
});
217220
if(this.props.onBlur) {
218-
this.props.onBlur(e);
221+
const event = document.createEvent('CustomEvent');
222+
event.initEvent("Change Date", true, false);
223+
ReactDOM.findDOMNode(this.refs.hiddenInput).dispatchEvent(event);
224+
this.props.onBlur(event);
219225
}
220226
}
221227
},
@@ -228,7 +234,10 @@ export default React.createClass({
228234
focused: true
229235
});
230236
if(this.props.onFocus) {
231-
this.props.onFocus(e);
237+
const event = document.createEvent('CustomEvent');
238+
event.initEvent("Change Date", true, false);
239+
ReactDOM.findDOMNode(this.refs.hiddenInput).dispatchEvent(event);
240+
this.props.onFocus(event);
232241
}
233242
},
234243
handleBlur(e){
@@ -350,6 +359,7 @@ export default React.createClass({
350359
if(this.props.onBlur) {
351360
const event = document.createEvent('CustomEvent');
352361
event.initEvent("Change Date", true, false);
362+
ReactDOM.findDOMNode(this.refs.hiddenInput).dispatchEvent(event);
353363
this.props.onBlur(event);
354364
}
355365
if(this.props.onChange) {
@@ -377,7 +387,7 @@ export default React.createClass({
377387
</Popover>
378388
</Overlay>
379389
<div ref="overlayContainer" />
380-
<input type="hidden" id={this.props.id} name={this.props.name} value={this.state.value || ''} />
390+
<input ref="hiddenInput" type="hidden" id={this.props.id} name={this.props.name} value={this.state.value || ''} />
381391
<FormControl
382392
onKeyDown={this.handleKeyDown}
383393
value={this.state.inputValue || ''}

test/core.test.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,18 +257,23 @@ describe("Date Picker", function() {
257257
it("should call focus and blur handlers.", co.wrap(function *(){
258258
const id = UUID.v4();
259259
var results = {};
260+
var value = new Date().toISOString();
260261
const App = React.createClass({
261262
getInitialState: function() {
262263
return {
263264
focused: false
264265
}
265266
},
266-
focusHandler: function() {
267+
focusHandler: function(e) {
268+
assert.equal(e.target, document.querySelector("input[type=hidden]"));
269+
assert.equal(e.target.value, value);
267270
this.setState({
268271
focused: true
269272
});
270273
},
271-
blurHandler: function() {
274+
blurHandler: function(e) {
275+
assert.equal(e.target, document.querySelector("input[type=hidden]"));
276+
assert.equal(e.target.value, value);
272277
this.setState({
273278
focused: false
274279
});
@@ -277,7 +282,7 @@ describe("Date Picker", function() {
277282
return <div>
278283
<div id='blurringClickTarget'>Blurring Click Target</div>
279284
{this.state.focused ? <div id="focused">Focused</div> : <div id="blurred">Blurred</div>}
280-
<DatePicker id={id} onBlur={this.blurHandler} onFocus={this.focusHandler} />
285+
<DatePicker id={id} onBlur={this.blurHandler} onFocus={this.focusHandler} value={value} />
281286
</div>;
282287
}
283288
});

0 commit comments

Comments
 (0)