Skip to content

Commit d8ecf6d

Browse files
committed
add input inline placeholder
1 parent 608282b commit d8ecf6d

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/js/input.jsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var Input = React.createClass({
88
propTypes: {
99
multiline: React.PropTypes.bool,
1010
required: React.PropTypes.bool,
11+
inlinePlaceholder: React.PropTypes.bool,
1112
min: React.PropTypes.number,
1213
max: React.PropTypes.number,
1314
step: React.PropTypes.number,
@@ -52,22 +53,24 @@ var Input = React.createClass({
5253
'mui-text': this.props.type === 'text',
5354
'mui-error': this.props.error !== undefined && this.props.error !== null
5455
}),
56+
placeholder = this.props.inlinePlaceholder ? this.props.placeholder : "",
5557
inputElement = this.props.multiline ?
5658
this.props.valueLink ?
57-
<textarea {...this.props} className="mui-input-textarea" placeholder=""
59+
<textarea {...this.props} className="mui-input-textarea" placeholder={placeholder}
5860
rows={this.state.rows} /> :
5961
<textarea {...this.props} value={this.state.value} className="mui-input-textarea"
60-
placeholder="" rows={this.state.rows} onChange={this._onTextAreaChange} onBlur={this._onInputBlur} /> :
62+
placeholder={placeholder} rows={this.state.rows} onChange={this._onTextAreaChange} onBlur={this._onInputBlur} /> :
6163
this.props.valueLink ?
62-
<input {...this.props} ref="input" placeholder="" /> :
63-
<input {...this.props} ref="input" value={this.state.value} placeholder=""
64-
onChange={this._onInputChange} onBlur={this._onInputBlur} />;
64+
<input {...this.props} ref="input" placeholder={placeholder} /> :
65+
<input {...this.props} ref="input" value={this.state.value} placeholder={placeholder}
66+
onChange={this._onInputChange} onBlur={this._onInputBlur} />
67+
placeholderSpan = this.props.inlinePlaceholder ? null : <span className="mui-input-placeholder"
68+
onClick={this._onPlaceholderClick}>{this.props.placeholder}</span>;
6569

6670
return (
6771
<div ref={this.props.ref} className={classes}>
6872
{inputElement}
69-
<span className="mui-input-placeholder"
70-
onClick={this._onPlaceholderClick}>{this.props.placeholder}</span>
73+
{placeholderSpan}
7174
<span className="mui-input-highlight"></span>
7275
<span className="mui-input-bar"></span>
7376
<span className="mui-input-description">{this.props.description}</span>

0 commit comments

Comments
 (0)