@financial-times/o-autocomplete 1.8.1 → 1.9.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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.9.0](https://github.com/Financial-Times/origami/compare/o-autocomplete-v1.8.1...o-autocomplete-v1.9.0) (2023-09-08)
4
+
5
+
6
+ ### Features
7
+
8
+ * Add an `autoselect` option ([c414db4](https://github.com/Financial-Times/origami/commit/c414db4780e8f74bffb25e9a04004c4d450077f4))
9
+
3
10
  ## [1.8.1](https://github.com/Financial-Times/origami/compare/o-autocomplete-v1.8.0...o-autocomplete-v1.8.1) (2023-08-25)
4
11
 
5
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/o-autocomplete",
3
- "version": "1.8.1",
3
+ "version": "1.9.0",
4
4
  "description": "An origami component for autocomplete inputs",
5
5
  "keywords": [
6
6
  "autocomplete",
@@ -184,6 +184,7 @@ function initClearButton(instance) {
184
184
  * @property {MapOptionToSuggestedValue} [mapOptionToSuggestedValue] - Function which transforms a suggestion before rendering.
185
185
  * @property {onConfirm} [onConfirm] - Function which is called when the user selects an option
186
186
  * @property {SuggestionTemplate} [suggestionTemplate] - Function to override how a suggestion item is rendered.
187
+ * @property {boolean} [autoselect] - Boolean to specify whether first option in suggestions list is highlighted.
187
188
  */
188
189
 
189
190
  class Autocomplete {
@@ -211,6 +212,9 @@ class Autocomplete {
211
212
  if (opts.suggestionTemplate) {
212
213
  this.options.suggestionTemplate = opts.suggestionTemplate;
213
214
  }
215
+ if (opts.autoselect) {
216
+ this.options.autoselect = opts.autoselect;
217
+ }
214
218
 
215
219
  const container = document.createElement('div');
216
220
  container.classList.add('o-autocomplete__listbox-container');
@@ -281,6 +285,7 @@ class Autocomplete {
281
285
  displayMenu: 'overlay',
282
286
  defaultValue: this.options.defaultValue || '',
283
287
  showNoOptionsFound: false,
288
+ autoselect: this.options.autoselect || false,
284
289
  templates: {
285
290
  /**
286
291
  * Used when rendering suggestions, the return value of this will be used as the innerHTML for a single suggestion.
@@ -360,7 +365,7 @@ class Autocomplete {
360
365
  this.options.onConfirm(option);
361
366
  }
362
367
  },
363
- autoselect: false,
368
+ autoselect: this.options.autoselect || false,
364
369
  // To fallback with JS an enhanced element's default value should
365
370
  // be set using static html.
366
371
  defaultValue: '',