@@ -132,6 +132,21 @@ class Autocomplete extends React.Component {
132
132
* will win if it contains a `style` entry.
133
133
*/
134
134
wrapperStyle : PropTypes . object ,
135
+ /**
136
+ * Arguments: `wrapperStyles: Object, wrapperProps: Object,
137
+ * renderedInput: Any, renderedMenu: Any`
138
+ *
139
+ * Invoked to generate the wrapper element. The `wrapperStyles` and
140
+ * `wrapperProps` objects are the corresponding properties of the
141
+ * `<Autocomplete />` component itself.
142
+ * `renderedInput` and `renderedMenu` are the generated input and
143
+ * menu elements.
144
+ * The default implementation uses a div-element as the wrapper with input
145
+ * and menu as direct children. You can use this function to change the
146
+ * wrapper, e.g. by using an inline-element like span or omit it completely
147
+ * by using a fragment (supported from react version 16).
148
+ */
149
+ renderWrapper : PropTypes . func ,
135
150
/**
136
151
* Whether or not to automatically highlight the top match in the dropdown
137
152
* menu.
@@ -175,6 +190,13 @@ class Autocomplete extends React.Component {
175
190
renderMenu ( items , value , style ) {
176
191
return < div style = { { ...style , ...this . menuStyle } } children = { items } />
177
192
} ,
193
+ renderWrapper ( wrapperStyle , wrapperProps , renderedInput , renderedMenu , renderedDebugInfo ) {
194
+ return ( < div style = { { ...wrapperStyle } } { ...wrapperProps } >
195
+ { renderedInput }
196
+ { renderedMenu }
197
+ { renderedDebugInfo }
198
+ </ div > )
199
+ } ,
178
200
menuStyle : {
179
201
borderRadius : '3px' ,
180
202
boxShadow : '0 2px 12px rgba(0, 0, 0, 0.1)' ,
@@ -570,29 +592,29 @@ class Autocomplete extends React.Component {
570
592
571
593
const { inputProps } = this . props
572
594
const open = this . isOpen ( )
573
- return (
574
- < div style = { { ...this . props . wrapperStyle } } { ...this . props . wrapperProps } >
575
- { this . props . renderInput ( {
576
- ...inputProps ,
577
- role : 'combobox' ,
578
- 'aria-autocomplete' : 'list' ,
579
- 'aria-expanded' : open ,
580
- autoComplete : 'off' ,
581
- ref : this . exposeAPI ,
582
- onFocus : this . handleInputFocus ,
583
- onBlur : this . handleInputBlur ,
584
- onChange : this . handleChange ,
585
- onKeyDown : this . composeEventHandlers ( this . handleKeyDown , inputProps . onKeyDown ) ,
586
- onClick : this . composeEventHandlers ( this . handleInputClick , inputProps . onClick ) ,
587
- value : this . props . value ,
588
- } ) }
589
- { open && this . renderMenu ( ) }
590
- { this . props . debug && (
595
+ return this . props . renderWrapper (
596
+ this . props . wrapperStyle ,
597
+ this . props . wrapperProps ,
598
+ this . props . renderInput ( {
599
+ ...inputProps ,
600
+ role : 'combobox' ,
601
+ 'aria-autocomplete' : 'list' ,
602
+ 'aria-expanded' : open ,
603
+ autoComplete : 'off' ,
604
+ ref : this . exposeAPI ,
605
+ onFocus : this . handleInputFocus ,
606
+ onBlur : this . handleInputBlur ,
607
+ onChange : this . handleChange ,
608
+ onKeyDown : this . composeEventHandlers ( this . handleKeyDown , inputProps . onKeyDown ) ,
609
+ onClick : this . composeEventHandlers ( this . handleInputClick , inputProps . onClick ) ,
610
+ value : this . props . value ,
611
+ } ) ,
612
+ open && this . renderMenu ( ) ,
613
+ this . props . debug && (
591
614
< pre style = { { marginLeft : 300 } } >
592
615
{ JSON . stringify ( this . _debugStates . slice ( Math . max ( 0 , this . _debugStates . length - 5 ) , this . _debugStates . length ) , null , 2 ) }
593
616
</ pre >
594
- ) }
595
- </ div >
617
+ )
596
618
)
597
619
}
598
620
}
0 commit comments