@@ -13,12 +13,18 @@ let Autocomplete = React.createClass({
13
13
renderItem : React . PropTypes . func . isRequired ,
14
14
menuStyle : React . PropTypes . object ,
15
15
inputProps : React . PropTypes . object ,
16
- labelText : React . PropTypes . string
16
+ labelText : React . PropTypes . string ,
17
+ wrapperProps : React . PropTypes . object ,
18
+ wrapperStyle : React . PropTypes . object
17
19
} ,
18
20
19
21
getDefaultProps ( ) {
20
22
return {
21
23
value : '' ,
24
+ wrapperProps : { } ,
25
+ wrapperStyle : {
26
+ display : 'inline-block'
27
+ } ,
22
28
inputProps : { } ,
23
29
labelText : '' ,
24
30
onChange ( ) { } ,
@@ -81,9 +87,18 @@ let Autocomplete = React.createClass({
81
87
if ( this . keyDownHandlers [ event . key ] )
82
88
this . keyDownHandlers [ event . key ] . call ( this , event )
83
89
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
84
95
this . setState ( {
85
96
highlightedIndex : null ,
86
97
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
87
102
} )
88
103
}
89
104
} ,
@@ -297,8 +312,8 @@ let Autocomplete = React.createClass({
297
312
} )
298
313
}
299
314
300
- return (
301
- < div style = { { display : 'inline-block' } } >
315
+ return (
316
+ < div style = { { ... this . props . wrapperStyle } } { ... this . props . wrapperProps } >
302
317
< input
303
318
{ ...this . props . inputProps }
304
319
role = "combobox"
0 commit comments