Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/_js/examples/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ var MarkdownEditor = React.createClass({\n\
getInitialState: function() {\n\
return {value: 'Type some *markdown* here!'};\n\
},\n\
handleKeyUp: React.autoBind(function() {\n\
handleInput: React.autoBind(function() {\n\
this.setState({value: this.refs.textarea.getDOMNode().value});\n\
}),\n\
render: function() {\n\
return (\n\
<div className=\"MarkdownEditor\">\n\
<h3>Input</h3>\n\
<textarea onKeyUp={this.handleKeyUp} ref=\"textarea\">\n\
<textarea onInput={this.handleInput} ref=\"textarea\">\n\
{this.state.value}\n\
</textarea>\n\
<h3>Output</h3>\n\
Expand Down
2 changes: 1 addition & 1 deletion examples/ballmer-peak/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var BallmerPeakCalculator = React.createClass({
<h4>Compute your Ballmer Peak:</h4>
<p>
If your BAC is{' '}
<input ref="bac" type="text" onKeyUp={this.handleChange} value={this.state.bac} />
<input ref="bac" type="text" onInput={this.handleChange} value={this.state.bac} />
{', '}then <b>{pct}</b> of your lines of code will have bugs.
</p>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/core/ReactEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ function listenAtTopLevel(touchNotMouse) {
trapBubbledEvent(topLevelTypes.topKeyUp, 'keyup', mountAt);
trapBubbledEvent(topLevelTypes.topKeyPress, 'keypress', mountAt);
trapBubbledEvent(topLevelTypes.topKeyDown, 'keydown', mountAt);
trapBubbledEvent(topLevelTypes.topInput, 'input', mountAt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work jumping into the React event subsystem.

We'd still like to support IE8 if possible. Fortunately, our synthetic event system means that we can use keyUp and click to simulate onInput in older browsers such that it works as expected.

However, since users won't expect onInput to work in IE8 anyway, I wonder if it's worth building this into the event plugin.

@jordow -- what do you think? Should we simulate onInput using keyUp and click in some event plugin? I think I'm in favor of it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For comparison, Angular's ng-model directive uses input on modern browsers and IE10+ and a combination of the keydown change paste cut events on IE8 and IE9.

https://github.com/angular/angular.js/blob/master/src/ng/directive/input.js#L411-L444

(Note that they have hasEvent('input') return false in IE9: https://github.com/IgorMinar/angular.js/blob/master/src/ng/sniffer.js#L53-L56.)

trapBubbledEvent(topLevelTypes.topChange, 'change', mountAt);
trapBubbledEvent(
topLevelTypes.topDOMCharacterDataModified,
Expand Down
1 change: 1 addition & 0 deletions src/event/EventConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var topLevelTypes = keyMirror({
topDOMCharacterDataModified: null,
topDoubleClick: null,
topFocus: null,
topInput: null,
topKeyDown: null,
topKeyPress: null,
topKeyUp: null,
Expand Down
7 changes: 7 additions & 0 deletions src/eventPlugins/SimpleEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ var SimpleEventPlugin = {
captured: keyOf({onKeyDownCapture: true})
}
},
input: {
phasedRegistrationNames: {
bubbled: keyOf({onInput: true}),
captured: keyOf({onInputCapture: true})
}
},
focus: {
phasedRegistrationNames: {
bubbled: keyOf({onFocus: true}),
Expand Down Expand Up @@ -220,6 +226,7 @@ SimpleEventPlugin.topLevelTypesToAbstract = {
topKeyUp: SimpleEventPlugin.abstractEventTypes.keyUp,
topKeyPress: SimpleEventPlugin.abstractEventTypes.keyPress,
topKeyDown: SimpleEventPlugin.abstractEventTypes.keyDown,
topInput: SimpleEventPlugin.abstractEventTypes.input,
topFocus: SimpleEventPlugin.abstractEventTypes.focus,
topBlur: SimpleEventPlugin.abstractEventTypes.blur,
topScroll: SimpleEventPlugin.abstractEventTypes.scroll,
Expand Down