Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
search: Clicking on a search pill should not lose searchbox focus.
Ryan Rehman70b92c7eb303
diff --git a/frontend_tests/node_tests/search.js b/frontend_tests/node_tests/search.jsindex cde906762fc..4e7a7efc981 100644--- a/frontend_tests/node_tests/search.js+++ b/frontend_tests/node_tests/search.js@@ -4,7 +4,6 @@ set_global('page_params', {zrequire('search');zrequire('search_pill');zrequire('Filter', 'js/filter');-zrequire('search_pill_widget');zrequire('tab_bar');const noop = () => {};@@ -19,6 +18,11 @@ set_global('ui_util', {place_caret_at_end: noop,});set_global('narrow', {});+set_global('search_pill_widget', {+ widget: {+ getByID: return_true,+ },+});search_pill.append_search_string = noop;search_pill.get_search_string_for_current_filter = noop;@@ -272,6 +276,13 @@ run_test('initialize', () => {assert(!search_button.prop('disabled'));};+ const search_pill_stub = $.create('.pill');+ search_pill_stub.closest = () => {+ return { data: noop };+ };+ const stub_event = {+ relatedTarget: search_pill_stub,+ };search_query_box.on = (event, callback) => {if (event === 'focus') {search_button.prop('disabled', true);@@ -280,7 +291,7 @@ run_test('initialize', () => {} else if (event === 'blur') {search_query_box.val("test string");narrow_state.search_string = () => 'ver';- callback();+ callback(stub_event);assert.equal(search_query_box.val(), 'test string');}};diff --git a/static/js/input_pill.js b/static/js/input_pill.jsindex 6e429ce28e4..41b299f463c 100644--- a/static/js/input_pill.js+++ b/static/js/input_pill.js@@ -372,6 +372,7 @@ exports.create = function (opts) {appendValue: funcs.appendPill.bind(funcs),appendValidatedData: funcs.appendValidatedData.bind(funcs),+ getByID: funcs.getByID,items: funcs.items,onPillCreate: function (callback) {diff --git a/static/js/search.js b/static/js/search.jsindex a8cd7b4fdb8..86b36a094aa 100644--- a/static/js/search.js+++ b/static/js/search.js@@ -164,7 +164,7 @@ exports.initialize = function () {// more work to re-order everything and make them private.search_query_box.on('focus', exports.focus_search);- search_query_box.on('blur', function () {+ search_query_box.on('blur', function (e) {// The search query box is a visual cue as to// whether search or narrowing is active. If// the user blurs the search box, then we should@@ -180,6 +180,18 @@ exports.initialize = function () {// short enough that the user won't notice (though// really it would be OK if they did).+ if (page_params.search_pills_enabled) {+ const pill_id = $(e.relatedTarget).closest(".pill").data('id');+ const search_pill = search_pill_widget.widget.getByID(pill_id);+ if (search_pill) {+ // The searchbox loses focus while the search+ // pill element gains focus.+ // We do not consider the searchbox to actually+ // lose focus when a pill inside it gets selected+ // or deleted by a click.+ return;+ }+ }setTimeout(function () {exports.update_button_visibility();tab_bar.close_search_bar_and_open_narrow_description();