Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add input onBlur #113

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/js/app-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ var AppBar = React.createClass({

});

module.exports = AppBar;
module.exports = AppBar;
38 changes: 25 additions & 13 deletions src/js/input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@ var Input = React.createClass({
propTypes: {
multiline: React.PropTypes.bool,
required: React.PropTypes.bool,
autocomplete: React.PropTypes.bool,
inlinePlaceholder: React.PropTypes.bool,
min: React.PropTypes.number,
max: React.PropTypes.number,
step: React.PropTypes.number,
rows: React.PropTypes.number,
inputStyle: React.PropTypes.string,
error: React.PropTypes.string,
description: React.PropTypes.string,
placeholder: React.PropTypes.string,
type: React.PropTypes.string,
name: React.PropTypes.string.isRequired,
onChange: React.PropTypes.func
onChange: React.PropTypes.func,
onBlur: React.PropTypes.func
},

mixins: [Classable],

getInitialState: function() {
return {
value: this.props.defaultValue,
rows: 1
rows: this.props.rows
};
},

Expand All @@ -51,22 +55,26 @@ var Input = React.createClass({
'mui-text': this.props.type === 'text',
'mui-error': this.props.error !== undefined && this.props.error !== null
}),
autocomplete = this.props.autocomplete ? "on" : "off",
placeholder = this.props.inlinePlaceholder ? this.props.placeholder : "",
inputElement = this.props.multiline ?
this.props.valueLink ?
<textarea {...this.props} className="mui-input-textarea" placeholder=""
rows={this.state.rows} /> :
<textarea {...this.props} value={this.state.value} className="mui-input-textarea"
placeholder="" rows={this.state.rows} onChange={this._onTextAreaChange} /> :
this.props.valueLink ?
<input {...this.props} ref="input" placeholder="" /> :
<input {...this.props} ref="input" value={this.state.value} placeholder=""
onChange={this._onInputChange} />;
this.props.valueLink ?
<textarea {...this.props} className="mui-input-textarea" placeholder={placeholder}
rows={this.state.rows} autoComplete={autocomplete} /> :
<textarea {...this.props} value={this.state.value} className="mui-input-textarea"
placeholder={placeholder} rows={this.state.rows} onChange={this._onTextAreaChange}
onBlur={this._onInputBlur} autoComplete={autocomplete} /> :
this.props.valueLink ?
<input {...this.props} ref="input" placeholder={placeholder} autoComplete={autocomplete} /> :
<input {...this.props} ref="input" value={this.state.value} placeholder={placeholder}
onChange={this._onInputChange} onBlur={this._onInputBlur} autoComplete={autocomplete} />
placeholderSpan = this.props.inlinePlaceholder ? null : <span className="mui-input-placeholder"
onClick={this._onPlaceholderClick}>{this.props.placeholder}</span>;

return (
<div ref={this.props.ref} className={classes}>
{inputElement}
<span className="mui-input-placeholder"
onClick={this._onPlaceholderClick}>{this.props.placeholder}</span>
{placeholderSpan}
<span className="mui-input-highlight"></span>
<span className="mui-input-bar"></span>
<span className="mui-input-description">{this.props.description}</span>
Expand All @@ -93,6 +101,10 @@ var Input = React.createClass({
if (this.props.onChange) this.props.onChange(e, value);
},

_onInputBlur: function(e) {
if (this.props.onBlur) this.props.onBlur(e);
},

_onPlaceholderClick: function(e) {
this.refs.input.getDOMNode().focus();
},
Expand Down
2 changes: 1 addition & 1 deletion src/less/components/input.less
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
}

::-webkit-input-placeholder {
color: red !important;
//color: red !important;
position: absolute !important;
top: -20px !important;
}