diff options
Diffstat (limited to 'app/assets/javascripts/main.js')
-rw-r--r-- | app/assets/javascripts/main.js | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index f78b4da181e..efc425a1972 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -116,16 +116,18 @@ function deferredInitialisation() { ); } - const search = document.querySelector('#search'); - if (search) { - search.addEventListener( + const searchInputBox = document.querySelector('#search'); + if (searchInputBox) { + searchInputBox.addEventListener( 'focus', () => { if (gon.features?.newHeaderSearch) { import(/* webpackChunkName: 'globalSearch' */ '~/header_search') .then(async ({ initHeaderSearchApp }) => { - await initHeaderSearchApp(); - document.querySelector('#search').focus(); + // In case the user started searching before we bootstrapped, let's pass the search along. + const initialSearchValue = searchInputBox.value; + await initHeaderSearchApp(initialSearchValue); + searchInputBox.focus(); }) .catch(() => {}); } else { |