Skip to content

Commit

Permalink
Add dropup prop
Browse files Browse the repository at this point in the history
  • Loading branch information
ericgio committed Sep 8, 2016
1 parent 46faace commit 7153989
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
13 changes: 9 additions & 4 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const Example = React.createClass({
customMenuItemChildren: false,
customToken: false,
disabled: false,
dropup: false,
largeDataSet: false,
minLength: 0,
multiple: false,
Expand All @@ -73,6 +74,7 @@ const Example = React.createClass({
customMenuItemChildren,
customToken,
disabled,
dropup,
largeDataSet,
minLength,
multiple,
Expand All @@ -81,7 +83,7 @@ const Example = React.createClass({
text,
} = this.state;

let props = {allowNew, disabled, multiple, selected};
const props = {align, allowNew, disabled, dropup, minLength, multiple, selected};

if (customMenuItemChildren) {
props.renderMenuItemChildren = this._renderMenuItemChildren;
Expand All @@ -108,16 +110,13 @@ const Example = React.createClass({
<div className="container">
<Typeahead
{...props}
align={align}
labelKey="name"
minLength={minLength}
name="typeahead"
onChange={selected => this.setState({selected})}
onInputChange={text => this.setState({text})}
options={largeDataSet ? bigData : states}
placeholder="Choose a state..."
ref="typeahead"
selected={selected}
/>
<ExampleSection title="Typeahead Options">
<div className="form-group">
Expand Down Expand Up @@ -158,6 +157,12 @@ const Example = React.createClass({
onChange={this._handleChange}>
Align menu: {this._renderAlignmentSelector()}
</Checkbox>
<Checkbox
checked={dropup}
name="dropup"
onChange={this._handleChange}>
Menu dropup
</Checkbox>
<Checkbox
checked={!!minLength}
name="minLength"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-bootstrap-typeahead",
"version": "0.9.1",
"version": "0.9.2",
"description": "React-based typeahead using the Bootstrap theme",
"main": "lib/index.js",
"directories": {
Expand Down
11 changes: 9 additions & 2 deletions src/Typeahead.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const Typeahead = React.createClass({
* be uncontrolled.
*/
defaultSelected: PropTypes.array,
/**
* Specify whether the menu should appear above the input.
*/
dropup: PropTypes.bool,
/**
* Optional callback to use when filtering the options. The function will
* receive each option as the first parameter.
Expand Down Expand Up @@ -106,6 +110,7 @@ const Typeahead = React.createClass({
return {
allowNew: false,
defaultSelected: [],
dropup: false,
labelKey: 'label',
maxResults: 100,
onBlur: noop,
Expand Down Expand Up @@ -163,7 +168,7 @@ const Typeahead = React.createClass({
},

render() {
const {allowNew, className, labelKey, paginate} = this.props;
const {allowNew, className, dropup, labelKey, paginate} = this.props;
const {shownResults, text} = this.state;

// First filter the results by the input string.
Expand All @@ -182,7 +187,9 @@ const Typeahead = React.createClass({

return (
<div
className={cx('bootstrap-typeahead', 'open', className)}
className={cx('bootstrap-typeahead', 'open', {
'dropup': dropup,
}, className)}
style={{position: 'relative'}}>
{this._renderInput(results)}
{this._renderMenu(results, shouldPaginate)}
Expand Down
10 changes: 10 additions & 0 deletions test/TypeaheadSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,14 @@ describe('<Typeahead>', () => {
expect(paginatorNodes.length).to.equal(0);
});

it('should add the `dropup` className when `dropup=true`', () => {
const instance = getTypeaheadInstance({...baseProps, dropup: true});
const TypeaheadNode = ReactTestUtils.findRenderedDOMComponentWithClass(
instance,
'dropup'
);

expect(TypeaheadNode).to.exist;
});

});

0 comments on commit 7153989

Please sign in to comment.