Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

search: Fix blur event handler for `search_query_box`.

Ryan Rehman63643c9d9d92
diff --git a/frontend_tests/node_tests/search.js b/frontend_tests/node_tests/search.js
index cb9acc73ff2..cde906762fc 100644
--- a/frontend_tests/node_tests/search.js
+++ b/frontend_tests/node_tests/search.js
@@ -74,7 +74,6 @@ run_test('initialize', () => {
const search_query_box = $('#search_query');
const searchbox_form = $('#searchbox_form');
const search_button = $('.search_button');
- const searchbox = $('#searchbox');
searchbox_form.on = (event, func) => {
assert.equal(event, 'compositionend');
@@ -181,6 +180,7 @@ run_test('initialize', () => {
search.is_using_input_method = true;
_setup('stream:Verona');
+ search_query_box.is = return_true;
assert.equal(opts.updater('stream:Verona'), 'stream:Verona');
assert(!is_blurred);
@@ -285,18 +285,6 @@ run_test('initialize', () => {
}
};
- searchbox.on = (event, callback) => {
- if (event === 'focusin') {
- searchbox.css({"box-shadow": "unset"});
- callback();
- assert.deepEqual(searchbox.css(), {"box-shadow": "inset 0px 0px 0px 2px hsl(204, 20%, 74%)"});
- } else if (event === 'focusout') {
- searchbox.css({"box-shadow": "inset 0px 0px 0px 2px hsl(204, 20%, 74%)"});
- callback();
- assert.deepEqual(searchbox.css(), {"box-shadow": "unset"});
- }
- };
-
search.initialize();
});
diff --git a/frontend_tests/node_tests/search_legacy.js b/frontend_tests/node_tests/search_legacy.js
index c32eadfd3c5..5ebd1169c6b 100644
--- a/frontend_tests/node_tests/search_legacy.js
+++ b/frontend_tests/node_tests/search_legacy.js
@@ -9,7 +9,7 @@ const return_true = () => true;
const return_false = () => false;
set_global('$', global.make_zjquery());
-set_global('narrow_state', {});
+set_global('narrow_state', {filter: return_false});
set_global('search_suggestion', {});
set_global('ui_util', {
change_tab_to: noop,
diff --git a/static/js/search.js b/static/js/search.js
index 93fb1794775..a8cd7b4fdb8 100644
--- a/static/js/search.js
+++ b/static/js/search.js
@@ -91,7 +91,15 @@ exports.initialize = function () {
if (page_params.search_pills_enabled) {
search_pill.append_search_string(search_string,
search_pill_widget.widget);
- return search_query_box.val();
+ if (search_query_box.is(':focus')) {
+ // We usually allow the user to continue
+ // typing until the enter key is pressed.
+ // But we narrow when the user clicks on a
+ // typeahead suggestion. This change in behaviour
+ // is a workaround to be able to display the
+ // navbar every time search_query_box loses focus.
+ return search_query_box.val();
+ }
}
return exports.narrow_or_search_for_term(search_string);
},
@@ -167,25 +175,17 @@ exports.initialize = function () {
// selecting something in the typeahead menu causes
// the box to lose focus a moment before.
//
- // The workaround is to check 100ms later -- long
+ // The workaround is to check 300ms later -- long
// enough for the search to have gone through, but
// short enough that the user won't notice (though
// really it would be OK if they did).
setTimeout(function () {
exports.update_button_visibility();
- }, 100);
- });
-
- if (page_params.search_pills_enabled) {
- // Uses jquery instead of pure css as the `:focus` event occurs on `#search_query`,
- // while we want to add box-shadow to `#searchbox`. This could have been done
- // with `:focus-within` CSS selector, but it is not supported in IE or Opera.
- searchbox.on('focusout', function () {
tab_bar.close_search_bar_and_open_narrow_description();
searchbox.css({"box-shadow": "unset"});
- });
- }
+ }, 300);
+ });
};
exports.focus_search = function () {