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

Commit e2ae224

Browse files
committed
Merge master and fix the examples
2 parents 66eb0dd + 3cffb47 commit e2ae224

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

examples/async-data/app.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ let App = React.createClass({
2424
attempt to autocomplete the first one.
2525
</p>
2626

27+
<label htmlFor="states-autocomplete">Choose a state from the US</label>
2728
<Autocomplete
28-
id="state-autocomplete"
29-
labelText="Choose a state from the US"
30-
inputProps={{name: "US state"}}
29+
inputProps={{name: "US state", id: "states-autocomplete"}}
3130
ref="autocomplete"
3231
value={this.state.value}
3332
items={this.state.unitedStates}

examples/custom-menu/app.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ let App = React.createClass({
2121
look as well as the rendering of it. In this case we put headers for each
2222
letter of the alphabet.
2323
</p>
24+
<label htmlFor="states-autocomplete">Choose a state from the US</label>
2425
<Autocomplete
25-
id="state-autocomplete"
2626
value={this.state.value}
27-
labelText="Choose a state from the US"
28-
inputProps={{name: "US state"}}
27+
inputProps={{name: "US state", id: "states-autocomplete"}}
2928
items={this.state.unitedStates}
3029
getItemValue={(item) => item.name}
3130
onSelect={value => this.setState({ value, unitedStates: [] }) }

examples/static-data/app.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ let App = React.createClass({
1616
so <code>Autocomplete</code> has methods baked in to help.
1717
</p>
1818

19+
<label htmlFor="states-autocomplete">Choose a state from the US</label>
1920
<Autocomplete
20-
id="state-autocomplete"
2121
value={this.state.value}
22-
labelText="Choose a state from the US"
23-
inputProps={{name: "US state"}}
22+
inputProps={{name: "US state", id: "states-autocomplete"}}
2423
items={getStates()}
2524
getItemValue={(item) => item.name}
2625
shouldItemRender={matchStateToTerm}

lib/Autocomplete.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ let Autocomplete = React.createClass({
1313
renderItem: React.PropTypes.func.isRequired,
1414
menuStyle: React.PropTypes.object,
1515
inputProps: React.PropTypes.object,
16-
labelText: React.PropTypes.string
16+
labelText: React.PropTypes.string,
17+
wrapperProps: React.PropTypes.object,
18+
wrapperStyle: React.PropTypes.object
1719
},
1820

1921
getDefaultProps () {
2022
return {
2123
value: '',
24+
wrapperProps: {},
25+
wrapperStyle: {
26+
display: 'inline-block'
27+
},
2228
inputProps: {},
2329
labelText: '',
2430
onChange () {},
@@ -81,9 +87,18 @@ let Autocomplete = React.createClass({
8187
if (this.keyDownHandlers[event.key])
8288
this.keyDownHandlers[event.key].call(this, event)
8389
else {
90+
const { selectionStart, value } = event.target
91+
if (value === this.state.value)
92+
// Nothing changed, no need to do anything. This also prevents
93+
// our workaround below from nuking user-made selections
94+
return
8495
this.setState({
8596
highlightedIndex: null,
8697
isOpen: true
98+
}, () => {
99+
// Restore caret position before autocompletion process
100+
// to work around a setSelectionRange bug in IE (#80)
101+
this.refs.input.selectionStart = selectionStart
87102
})
88103
}
89104
},
@@ -298,7 +313,7 @@ let Autocomplete = React.createClass({
298313
}
299314

300315
return (
301-
<div style={{display: 'inline-block'}}>
316+
<div style={{...this.props.wrapperStyle}} {...this.props.wrapperProps}>
302317
<input
303318
{...this.props.inputProps}
304319
role="combobox"

0 commit comments

Comments
 (0)