Skip to content

Commit

Permalink
Merge pull request mui#328 from cavneb/feature-onEnter
Browse files Browse the repository at this point in the history
Added onEnterKeyDown prop callback for TextField component
  • Loading branch information
hai-cea committed Feb 17, 2015
2 parents aa1dfec + d573b49 commit f7e1c21
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/js/text-field.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var TextField = React.createClass({
onBlur: React.PropTypes.func,
onChange: React.PropTypes.func,
onFocus: React.PropTypes.func,
onKeyDown: React.PropTypes.func,
onEnterKeyDown: React.PropTypes.func,
type: React.PropTypes.string
},

Expand Down Expand Up @@ -102,7 +104,8 @@ var TextField = React.createClass({
className: 'mui-text-field-input',
id: inputId,
onBlur: this._handleInputBlur,
onFocus: this._handleInputFocus
onFocus: this._handleInputFocus,
onKeyDown: this._handleInputKeyDown
};

if (!this.props.hasOwnProperty('valueLink')) {
Expand Down Expand Up @@ -191,6 +194,11 @@ var TextField = React.createClass({
if (this.props.onFocus) this.props.onFocus(e);
},

_handleInputKeyDown: function(e) {
if (e.keyCode === 13 && this.props.onEnterKeyDown) this.props.onEnterKeyDown(e);
if (this.props.onKeyDown) this.props.onKeyDown(e);
},

_handleTextAreaHeightChange: function(e, height) {
var newHeight = height + 24;
if (this.props.floatingLabelText) newHeight += 24;
Expand Down

0 comments on commit f7e1c21

Please sign in to comment.