@financial-times/o-autocomplete 2.1.0 → 2.2.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,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.2.0](https://github.com/Financial-Times/origami/compare/o-autocomplete-v2.1.0...o-autocomplete-v2.2.0) (2026-01-12)
4
+
5
+
6
+ ### Features
7
+
8
+ * Add o-autocomplete showNoOptionsFound option ([a869a04](https://github.com/Financial-Times/origami/commit/a869a04ffc045d526bb1facf7c89215c4933754f))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Add o-autocomplete clear button post-click logic ([67f4fed](https://github.com/Financial-Times/origami/commit/67f4fed14380e8e7b12d3d36156604e0a51e6446))
14
+
3
15
  ## [2.1.0](https://github.com/Financial-Times/origami/compare/o-autocomplete-v2.0.0...o-autocomplete-v2.1.0) (2025-11-13)
4
16
 
5
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/o-autocomplete",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "An origami component for autocomplete inputs",
5
5
  "keywords": [
6
6
  "autocomplete",
@@ -209,6 +209,7 @@ class Autocomplete {
209
209
  if (opts.onConfirm) {
210
210
  this.options.onConfirm = opts.onConfirm;
211
211
  }
212
+ this.options.showNoOptionsFound = opts.showNoOptionsFound || false;
212
213
  if (opts.suggestionTemplate) {
213
214
  this.options.suggestionTemplate = opts.suggestionTemplate;
214
215
  }
@@ -247,7 +248,33 @@ class Autocomplete {
247
248
  * @returns {void}
248
249
  */
249
250
  this.options.source = (query, populateOptions) => {
250
- showLoadingPane(this);
251
+ // One way this function can be invoked is following a clearButton click event.
252
+
253
+ // The consumer-provided `customSource()` function can be wrapped in `debounce()`, creating the potential
254
+ // for a user-defined delay between the invocation of the `customSource()` and `callback()` functions.
255
+ // This delay could be longer than the 100ms frequency at which accessible-autocomplete polls the value of the input.
256
+
257
+ // The following code blocks accommodate the coincident of these circumstances.
258
+
259
+ // A clearButton click event will hide the loading pane and set the input value as an empty string.
260
+ if (query) {
261
+ // Therefore only show the loading pane if a `query` (i.e. input) value is present
262
+ // so as to avoid temporarily re-showing the loading pane prior to this function's callback hiding it once again.
263
+ showLoadingPane(this);
264
+ }
265
+
266
+ // A clearButton click event will blur the input field, resulting in the listbox of options becoming hidden
267
+ // (but without de-populating the options).
268
+ if (!query) {
269
+ // If the accessible-autocomplete poll occurs after a clearButton click event
270
+ // but before this function's callback is invoked then the listbox and its options will be re-displayed.
271
+ // When the callback eventually runs, it will de-populate the options, consequently re-hiding the listbox.
272
+ // To prevent this, in the event of no `query` value being present
273
+ // (where, logically, there will be no corresponding options),
274
+ // immediately de-populate the options rather than waiting for the callback to do so.
275
+ populateOptions([]);
276
+ }
277
+
251
278
  /**
252
279
  * @param {Array<string>} options - The options which match the rext which was typed into the autocomplete by the user
253
280
  * @returns {void}
@@ -285,7 +312,7 @@ class Autocomplete {
285
312
  cssNamespace: 'o-autocomplete',
286
313
  displayMenu: 'overlay',
287
314
  defaultValue: this.options.defaultValue || '',
288
- showNoOptionsFound: false,
315
+ showNoOptionsFound: this.options.showNoOptionsFound,
289
316
  autoselect: this.options.autoselect || false,
290
317
  templates: {
291
318
  /**
@@ -381,7 +408,7 @@ class Autocomplete {
381
408
  placeholder: '',
382
409
  cssNamespace: 'o-autocomplete',
383
410
  displayMenu: 'overlay',
384
- showNoOptionsFound: false,
411
+ showNoOptionsFound: this.options.showNoOptionsFound,
385
412
  templates: {
386
413
  suggestion: this.suggestionTemplate.bind(this)
387
414
  }