@@ -147,7 +147,7 @@ type ClassNames = Partial<{
147
147
148
148
### ` render `
149
149
150
- > ` (params: { children: VNode, state: AutocompleteState<TItem> , sections: VNode[], createElement: Pragma, Fragment: PragmaFrag }) => void `
150
+ > ` (params: { children: VNode, elements: Elements , sections: VNode[], state: AutocompleteState<TItem> , createElement: Pragma, Fragment: PragmaFrag }) => void `
151
151
152
152
The function that renders the autocomplete panel. This is useful to customize the rendering, for example, using multi-row or multi-column layouts.
153
153
@@ -164,6 +164,70 @@ autocomplete({
164
164
});
165
165
```
166
166
167
+ You can use ` sections ` , which holds the components tree of your autocomplete, to customize the wrapping layout.
168
+
169
+ ``` js
170
+ import { render } from ' preact' ;
171
+
172
+ autocomplete ({
173
+ // ...
174
+ render ({ sections }, root ) {
175
+ render (
176
+ < div className= " aa-PanelLayout aa-Panel--scrollable" > {sections}< / div> ,
177
+ root
178
+ );
179
+ },
180
+ });
181
+ ```
182
+
183
+ If you need to split the content across a more complex layout, you can use ` elements ` instead to pick which source to display based on its [ ` sourceId ` ] ( sources#sourceid ) .
184
+
185
+ ``` js
186
+ import { createQuerySuggestionsPlugin } from ' @algolia/autocomplete-plugin-query-suggestions' ;
187
+ import { createLocalStorageRecentSearchesPlugin } from ' @algolia/autocomplete-plugin-recent-searches' ;
188
+ import algoliasearch from ' algoliasearch' ;
189
+ import { render } from ' preact' ;
190
+
191
+ const searchClient = algoliasearch (
192
+ ' latency' ,
193
+ ' 6be0576ff61c053d5f9a3225e2a90f76'
194
+ );
195
+ const recentSearchesPlugin = createLocalStorageRecentSearchesPlugin ({
196
+ key: ' search' ,
197
+ });
198
+ const querySuggestionsPlugin = createQuerySuggestionsPlugin ({
199
+ searchClient,
200
+ indexName: ' instant_search_demo_query_suggestions' ,
201
+ });
202
+
203
+ autocomplete ({
204
+ // ...
205
+ plugins: [recentSearchesPlugin, querySuggestionsPlugin],
206
+ getSources ({ query }) {
207
+ return [
208
+ {
209
+ sourceId: ' products' ,
210
+ // ...
211
+ },
212
+ ];
213
+ },
214
+ render ({ elements }, root ) {
215
+ const { recentSearchesPlugin , querySuggestionsPlugin , products } = elements;
216
+
217
+ render (
218
+ < div className= " aa-PanelLayout aa-Panel--scrollable" >
219
+ < div>
220
+ {recentSearchesPlugin}
221
+ {querySuggestionsPlugin}
222
+ < / div>
223
+ < div> {products}< / div>
224
+ < / div> ,
225
+ root
226
+ );
227
+ },
228
+ });
229
+ ```
230
+
167
231
### ` renderNoResults `
168
232
169
233
> ` (params: { children: VNode, state: AutocompleteState<TItem>, sections: VNode[], createElement: Pragma, Fragment: PragmaFrag }) => void `
0 commit comments