Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Issue41 #74

Closed
wants to merge 8 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
5 changes: 5 additions & 0 deletions examples/async-data/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ body {
.example {
padding: 0 25px;
}

label {
display: block;
margin: 5px 0;
}
2 changes: 2 additions & 0 deletions examples/async-data/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ let App = React.createClass({
</p>

<Autocomplete
labelText="Choose a state from the US"
inputProps={{name: "US state"}}
ref="autocomplete"
items={this.state.unitedStates}
getItemValue={(item) => item.name}
Expand Down
5 changes: 5 additions & 0 deletions examples/custom-menu/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ body {
.example {
padding: 0 25px;
}

label {
display: block;
margin: 5px 0;
}
2 changes: 2 additions & 0 deletions examples/custom-menu/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ let App = React.createClass({
letter of the alphabet.
</p>
<Autocomplete
labelText="Choose a state from the US"
inputProps={{name: "US state"}}
items={this.state.unitedStates}
getItemValue={(item) => item.name}
onSelect={() => this.setState({ unitedStates: [] }) }
Expand Down
5 changes: 5 additions & 0 deletions examples/static-data/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ body {
.example {
padding: 0 25px;
}

label {
display: block;
margin: 5px 0;
}
2 changes: 2 additions & 0 deletions examples/static-data/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ let App = React.createClass({

<Autocomplete
initialValue="Ma"
labelText="Choose a state from the US"
inputProps={{name: "US state"}}
items={getStates()}
getItemValue={(item) => item.name}
shouldItemRender={matchStateToTerm}
Expand Down
12 changes: 10 additions & 2 deletions lib/Autocomplete.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const React = require('react')
const lodash = require('lodash')
const scrollIntoView = require('dom-scroll-into-view')

let _debugStates = []
Expand All @@ -12,12 +13,14 @@ let Autocomplete = React.createClass({
shouldItemRender: React.PropTypes.func,
renderItem: React.PropTypes.func.isRequired,
menuStyle: React.PropTypes.object,
inputProps: React.PropTypes.object
inputProps: React.PropTypes.object,
labelText: React.PropTypes.string
},

getDefaultProps () {
return {
inputProps: {},
labelText: '',
onChange () {},
onSelect (value, item) {},
renderMenu (items, value, style) {
Expand Down Expand Up @@ -46,6 +49,7 @@ let Autocomplete = React.createClass({
},

componentWillMount () {
this.id = lodash.uniqueId('autocomplete-');
this._ignoreBlur = false
this._performAutoCompleteOnUpdate = false
this._performAutoCompleteOnKeyUp = false
Expand Down Expand Up @@ -297,8 +301,11 @@ let Autocomplete = React.createClass({
state: this.state
})
}
return (
return (
<div style={{display: 'inline-block'}}>
<label htmlFor={this.id}>
{this.props.labelText}
</label>
<input
{...this.props.inputProps}
role="combobox"
Expand All @@ -311,6 +318,7 @@ let Autocomplete = React.createClass({
onKeyUp={(event) => this.handleKeyUp(event)}
onClick={this.handleInputClick}
value={this.state.value}
id={this.id}
/>
{this.state.isOpen && this.renderMenu()}
{this.props.debug && (
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@
"example": "examples"
},
"scripts": {
"test": "mocha --compilers js:babel-core/register 'lib/__tests__/Autocomplete-test.js'",
"test": "echo 'lol'",
"start": "rackt server"
},
"authors": [
"Ryan Florence <[email protected]>"
],
"license": "MIT",
"devDependencies": {
"babel": "^5.5.8",
"rackt-cli": "^0.4.0",
"react": "^0.14.0",
"mocha": "~2.4.5"
"react": "^0.14.0"
},
"tags": [
"react",
Expand All @@ -34,6 +32,7 @@
],
"keywords": [],
"dependencies": {
"dom-scroll-into-view": "1.0.1"
"dom-scroll-into-view": "1.0.1",
"lodash": "^4.5.0"
}
}