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

inline placeholder for input #122

Merged
merged 10 commits into from
Dec 5, 2014
28 changes: 16 additions & 12 deletions src/js/input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var Input = React.createClass({
propTypes: {
multiline: React.PropTypes.bool,
required: React.PropTypes.bool,
inlinePlaceholder: React.PropTypes.bool,
rows: React.PropTypes.number,
min: React.PropTypes.number,
max: React.PropTypes.number,
step: React.PropTypes.number,
Expand All @@ -25,7 +27,7 @@ var Input = React.createClass({
getInitialState: function() {
return {
value: this.props.defaultValue,
rows: 1
rows: this.props.rows
};
},

Expand All @@ -51,22 +53,24 @@ var Input = React.createClass({
'mui-text': this.props.type === 'text',
'mui-error': this.props.error !== undefined && this.props.error !== null
}),
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} /> :
<textarea {...this.props} value={this.state.value} className="mui-input-textarea"
placeholder={placeholder} rows={this.state.rows} onChange={this._onTextAreaChange} /> :
this.props.valueLink ?
<input {...this.props} ref="input" placeholder={placeholder} /> :
<input {...this.props} ref="input" value={this.state.value} placeholder={placeholder}
onChange={this._onInputChange} />
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 Down
2 changes: 1 addition & 1 deletion src/less/components/input.less
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
}

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