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

Commit 81c6471

Browse files
committed
Merge upstream/master
2 parents a691cec + 3cffb47 commit 81c6471

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

lib/Autocomplete.js

Lines changed: 18 additions & 3 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
},
@@ -297,8 +312,8 @@ let Autocomplete = React.createClass({
297312
})
298313
}
299314

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

0 commit comments

Comments
 (0)