From d43d8ba1276087fffa5cdc6b69129fb62fa912da Mon Sep 17 00:00:00 2001 From: evykassirer Date: Wed, 24 May 2023 17:08:16 -0700 Subject: [PATCH] typeahead: Add openInputFieldOnKeyUp option. --- web/third/bootstrap-typeahead/typeahead.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/web/third/bootstrap-typeahead/typeahead.js b/web/third/bootstrap-typeahead/typeahead.js index 67e0fa7a50..679c67944a 100644 --- a/web/third/bootstrap-typeahead/typeahead.js +++ b/web/third/bootstrap-typeahead/typeahead.js @@ -104,7 +104,14 @@ * append to, where before it could only be appended to `body`. * Since it's in the right part of the DOM, we don't need to do * the manual positioning in the show() function. - * + * + * 11. Add `openInputFieldOnKeyUp` option: + * + * If the typeahead isn't shown yet, the `lookup` call in the keyup + * handler will open it. Here we make a callback to the input field + * before we open the lookahead in case it needs to make UI changes first + * (e.g. widening the search bar). + * * ============================================================ */ import {insert} from "text-field-edit"; @@ -495,6 +502,13 @@ import {get_string_diff} from "../../src/util"; hideOnEmpty = true; } } + if (this.options.openInputFieldOnKeyUp !== null && !this.shown) { + // If the typeahead isn't shown yet, the `lookup` call will open it. + // Here we make a callback to the input field before we open the + // lookahead in case it needs to make UI changes first (e.g. widening + // the search bar). + this.options.openInputFieldOnKeyUp(); + } this.lookup(hideOnEmpty) } @@ -584,6 +598,7 @@ import {get_string_diff} from "../../src/util"; , stopAdvance: false , dropup: false , advanceKeyCodes: [] + , openInputFieldOnKeyUp: null } $.fn.typeahead.Constructor = Typeahead