@financial-times/o-autocomplete 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +1 -37
- package/package.json +1 -1
- package/src/js/autocomplete.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.3.0](https://github.com/Financial-Times/origami/compare/o-autocomplete-v2.2.0...o-autocomplete-v2.3.0) (2026-01-15)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* Add o-autocomplete confirmOnBlur option ([#2322](https://github.com/Financial-Times/origami/issues/2322)) ([ba27a93](https://github.com/Financial-Times/origami/commit/ba27a93fa1c91ce2f8f1d3897095b88ed34ef6cc))
|
|
9
|
+
|
|
3
10
|
## [2.2.0](https://github.com/Financial-Times/origami/compare/o-autocomplete-v2.1.0...o-autocomplete-v2.2.0) (2026-01-12)
|
|
4
11
|
|
|
5
12
|
|
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ An Origami component for autocomplete inputs. This is built on top of the excell
|
|
|
11
11
|
- [JavaScript](#javascript)
|
|
12
12
|
- [dynamic suggestions function](#dynamic-suggestions-function)
|
|
13
13
|
- [mapOptionToSuggestedValue](#mapoptiontosuggestedvalue)
|
|
14
|
+
- [suggestionTemplate](#suggestiontemplate)
|
|
14
15
|
- [onConfirm](#onconfirm)
|
|
15
16
|
- [Keyboard Support](#keyboard-support)
|
|
16
17
|
- [When focus is within the text input](#when-focus-is-within-the-text-input)
|
|
@@ -202,43 +203,6 @@ new oAutocomplete(oAutocompleteElement, {
|
|
|
202
203
|
| ------ | --------------- | ------------------------------------------------ |
|
|
203
204
|
| option | <code>\*</code> | The option to transform into a suggestion string |
|
|
204
205
|
|
|
205
|
-
### onConfirm
|
|
206
|
-
|
|
207
|
-
This function is called when the user selects an option and is called with the option the user selected.
|
|
208
|
-
|
|
209
|
-
#### Example
|
|
210
|
-
|
|
211
|
-
```js
|
|
212
|
-
import oAutocomplete from 'o-autocomplete';
|
|
213
|
-
|
|
214
|
-
async function customSuggestions(query, populateOptions) {
|
|
215
|
-
const suggestions = await getSuggestions(query);
|
|
216
|
-
populateOptions(suggestions);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* @param {{"suggestionText": string}} option - The option to transform into a suggestion string
|
|
221
|
-
* @returns {string} The string to display as the suggestions for this option
|
|
222
|
-
*/
|
|
223
|
-
function mapOptionToSuggestedValue(option) {
|
|
224
|
-
return option.suggestionText;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* @param {{"suggestionText": string}} option - The option the user selected
|
|
229
|
-
*/
|
|
230
|
-
function onConfirm(option) {
|
|
231
|
-
console.log('You selected option: ', option);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const oAutocompleteElement = document.getElementById('my-o-autocomplete-element');
|
|
235
|
-
new oAutocomplete(oAutocompleteElement, {
|
|
236
|
-
onConfirm
|
|
237
|
-
mapOptionToSuggestedValue,
|
|
238
|
-
source: customSuggestions,
|
|
239
|
-
});
|
|
240
|
-
```
|
|
241
|
-
|
|
242
206
|
### suggestionTemplate
|
|
243
207
|
|
|
244
208
|
This function is used to override the default rendering of suggestion items, with a function that returns a custom HTML string for the given option.
|
package/package.json
CHANGED
package/src/js/autocomplete.js
CHANGED
|
@@ -210,6 +210,7 @@ class Autocomplete {
|
|
|
210
210
|
this.options.onConfirm = opts.onConfirm;
|
|
211
211
|
}
|
|
212
212
|
this.options.showNoOptionsFound = opts.showNoOptionsFound || false;
|
|
213
|
+
this.options.confirmOnBlur = opts.confirmOnBlur ?? true;
|
|
213
214
|
if (opts.suggestionTemplate) {
|
|
214
215
|
this.options.suggestionTemplate = opts.suggestionTemplate;
|
|
215
216
|
}
|
|
@@ -308,6 +309,7 @@ class Autocomplete {
|
|
|
308
309
|
this.options.onConfirm(option);
|
|
309
310
|
}
|
|
310
311
|
},
|
|
312
|
+
confirmOnBlur: this.options.confirmOnBlur,
|
|
311
313
|
source: this.options.source,
|
|
312
314
|
cssNamespace: 'o-autocomplete',
|
|
313
315
|
displayMenu: 'overlay',
|