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

Commit 92d818e

Browse files
committed
Updating examples to use new value prop
1 parent c98f038 commit 92d818e

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

examples/async-data/app.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ let App = React.createClass({
66

77
getInitialState () {
88
return {
9+
value: '',
910
unitedStates: getStates(),
1011
loading: false
1112
}
@@ -27,16 +28,17 @@ let App = React.createClass({
2728
labelText="Choose a state from the US"
2829
inputProps={{name: "US state"}}
2930
ref="autocomplete"
31+
value={this.state.value}
3032
items={this.state.unitedStates}
3133
getItemValue={(item) => item.name}
3234
onSelect={(value, item) => {
3335
// set the menu to only the selected item
34-
this.setState({ unitedStates: [ item ] })
36+
this.setState({ value, unitedStates: [ item ] })
3537
// or you could reset it to a default list again
3638
// this.setState({ unitedStates: getStates() })
3739
}}
3840
onChange={(event, value) => {
39-
this.setState({loading: true})
41+
this.setState({ value, loading: true })
4042
fakeRequest(value, (items) => {
4143
this.setState({ unitedStates: items, loading: false })
4244
})

examples/custom-menu/app.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ let App = React.createClass({
66

77
getInitialState () {
88
return {
9+
value: '',
910
unitedStates: getStates(),
1011
loading: false
1112
}
@@ -21,13 +22,14 @@ let App = React.createClass({
2122
letter of the alphabet.
2223
</p>
2324
<Autocomplete
25+
value={this.state.value}
2426
labelText="Choose a state from the US"
2527
inputProps={{name: "US state"}}
2628
items={this.state.unitedStates}
2729
getItemValue={(item) => item.name}
28-
onSelect={() => this.setState({ unitedStates: [] }) }
30+
onSelect={value => this.setState({ value, unitedStates: [] }) }
2931
onChange={(event, value) => {
30-
this.setState({loading: true})
32+
this.setState({ value, loading: true })
3133
fakeRequest(value, (items) => {
3234
this.setState({ unitedStates: items, loading: false })
3335
})

examples/static-data/app.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { getStates, matchStateToTerm, sortStates, styles } from '../../lib/utils
33
import Autocomplete from '../../lib/index'
44

55
let App = React.createClass({
6+
getInitialState() {
7+
return { value: 'Ma' }
8+
},
69
render () {
710
return (
811
<div>
@@ -14,13 +17,15 @@ let App = React.createClass({
1417
</p>
1518

1619
<Autocomplete
17-
initialValue="Ma"
20+
value={this.state.value}
1821
labelText="Choose a state from the US"
1922
inputProps={{name: "US state"}}
2023
items={getStates()}
2124
getItemValue={(item) => item.name}
2225
shouldItemRender={matchStateToTerm}
2326
sortItems={sortStates}
27+
onChange={(event, value) => this.setState({ value })}
28+
onSelect={value => this.setState({ value })}
2429
renderItem={(item, isHighlighted) => (
2530
<div
2631
style={isHighlighted ? styles.highlightedItem : styles.item}

0 commit comments

Comments
 (0)