Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
recent_topics: Focus on first table row after first render.
Aman Agrawal8d398ddd5475
diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.jsindex 283565ca033..b42a8067962 100644--- a/frontend_tests/node_tests/recent_topics.js+++ b/frontend_tests/node_tests/recent_topics.js@@ -313,6 +313,7 @@ function verify_topic_data(all_topics, stream, topic, last_msg_id, participated)}let rt = reset_module("recent_topics");+rt.set_default_focus();function stub_out_filter_buttons() {// TODO: We probably want more direct tests that make sure@@ -401,6 +402,7 @@ run_test("test_filter_all", () => {expected.search_val = "topic-1";row_data = generate_topic_data([[1, "topic-1", 0, false, true]]);i = row_data.length;+ rt.set_default_focus();assert.equal(rt.inplace_rerender("1:topic-1"), true);});@@ -428,6 +430,7 @@ run_test("test_filter_unread", () => {rt = reset_module("recent_topics");rt.is_visible = () => true;+ rt.set_default_focus();stub_templates(() => "<recent_topics table stub>");stub_out_filter_buttons();@@ -494,6 +497,7 @@ run_test("test_filter_participated", () => {rt = reset_module("recent_topics");rt.is_visible = () => true;+ rt.set_default_focus();stub_templates(() => "<recent_topics table stub>");stub_out_filter_buttons();rt.process_messages(messages);@@ -552,6 +556,7 @@ run_test("basic assertions", () => {rt = reset_module("recent_topics");stub_out_filter_buttons();rt.is_visible = () => true;+ rt.set_default_focus();rt.set_filter("all");rt.process_messages(messages);let all_topics = rt.get();diff --git a/static/js/recent_topics.js b/static/js/recent_topics.jsindex eedc3327d68..50a14bbb0de 100644--- a/static/js/recent_topics.js+++ b/static/js/recent_topics.js@@ -24,7 +24,7 @@ const MAX_AVATAR = 4;// So, we use table as a grid system and// track the coordinates of the focus element via// `row_focus` and `col_focus`.-let current_focus_elem;+let current_focus_elem = "table";let row_focus = 0;// Start focus on the topic column, so Down+Enter works to visit a topic.let col_focus = 1;@@ -55,6 +55,8 @@ function set_default_focus() {current_focus_elem.trigger("focus");}+exports.set_default_focus = set_default_focus;+function set_table_focus(row, col) {const topic_rows = $("#recent_topics_table table tbody tr");if (topic_rows.length === 0 || row < 0 || row >= topic_rows.length) {