Skip to content

Commit 9d4ab0d

Browse files
committed
Merge pull request #87 from OtaK/feature/textarea-input
Added ability to change <input> to <textarea> from a boolean flag
2 parents 54fc018 + 8ce58bd commit 9d4ab0d

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ Type: `String`
8282

8383
Placeholder text for the typeahead input.
8484

85+
#### props.textarea
86+
87+
Type: `Boolean`
88+
89+
Set to `true` to use a `<textarea>` element rather than an `<input>` element
90+
8591
#### props.inputProps
8692

8793
Type: `Object`

src/typeahead/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var Typeahead = React.createClass({
2828
allowCustomValues: React.PropTypes.number,
2929
defaultValue: React.PropTypes.string,
3030
placeholder: React.PropTypes.string,
31+
textarea: React.PropTypes.bool,
3132
inputProps: React.PropTypes.object,
3233
onOptionSelected: React.PropTypes.func,
3334
onChange: React.PropTypes.func,
@@ -56,6 +57,7 @@ var Typeahead = React.createClass({
5657
allowCustomValues: 0,
5758
defaultValue: "",
5859
placeholder: "",
60+
textarea: false,
5961
inputProps: {},
6062
onOptionSelected: function(option) {},
6163
onChange: function(event) {},
@@ -290,10 +292,12 @@ var Typeahead = React.createClass({
290292
classes[this.props.className] = !!this.props.className;
291293
var classList = classNames(classes);
292294

295+
var InputElement = this.props.textarea ? 'textarea' : 'input';
296+
293297
return (
294298
<div className={classList}>
295299
{ this._renderHiddenInput() }
296-
<input ref="entry" type="text"
300+
<InputElement ref="entry" type="text"
297301
{...this.props.inputProps}
298302
placeholder={this.props.placeholder}
299303
className={inputClassList}

test/typeahead-test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,5 +474,26 @@ describe('Typeahead Component', function() {
474474
});
475475
});
476476
});
477+
478+
context('textarea', function() {
479+
it('should render a <textarea> input', function() {
480+
var component = TestUtils.renderIntoDocument(<Typeahead
481+
options={ BEATLES }
482+
textarea={ true }
483+
/>);
484+
485+
var input = component.refs.entry.getDOMNode();
486+
assert.equal(input.tagName.toLowerCase(), 'textarea');
487+
});
488+
489+
it('should render a <input> input', function() {
490+
var component = TestUtils.renderIntoDocument(<Typeahead
491+
options={ BEATLES }
492+
/>);
493+
494+
var input = component.refs.entry.getDOMNode();
495+
assert.equal(input.tagName.toLowerCase(), 'input');
496+
});
497+
})
477498
});
478499
});

0 commit comments

Comments
 (0)