Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
recent_view: Let browser handle tab hotkey.
Aman Agrawal2bf3191ddffc
diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.tsindex 57811f1a15c..a773a9d0008 100644--- a/web/src/recent_view_ui.ts+++ b/web/src/recent_view_ui.ts@@ -743,6 +743,7 @@ function format_conversation(conversation_data: ConversationData): ConversationCother_sender_names_html: displayed_other_names.map((name) => _.escape(name)).join("<br />"),last_msg_url: hash_util.by_conversation_and_time_url(last_msg),is_spectator: page_params.is_spectator,+ column_indexes: COLUMNS,};if (is_private) {assert(dm_context !== undefined);@@ -1528,6 +1529,40 @@ export function change_focused_element($elt: JQuery, input_key: string): boolean// preventDefault/stopPropagation; false will let the browser// handle the key.+ if (input_key === "tab" || input_key === "shift_tab") {+ // Tabbing should be handled by browser but to keep the focus element same+ // when we update recent view or user uses other hotkeys, we need to track+ // the current focused element.+ setTimeout(() => {+ const post_tab_focus_elem = document.activeElement;+ if (!(post_tab_focus_elem instanceof HTMLElement)) {+ return;+ }++ if (+ post_tab_focus_elem.id === "recent_view_search" ||+ post_tab_focus_elem.classList.contains("btn-recent-filters") ||+ post_tab_focus_elem.classList.contains("dropdown-widget-button")+ ) {+ $current_focus_elem = $(post_tab_focus_elem);+ }++ if ($(post_tab_focus_elem).parents("#recent-view-content-table").length) {+ $current_focus_elem = "table";+ const topic_row_index = $(post_tab_focus_elem).closest("tr").index();+ const col_index = $(post_tab_focus_elem)+ .closest(".recent_view_focusable")+ .attr("data-col-index");+ if (!col_index) {+ return;+ }+ col_focus = Number.parseInt(col_index, 10);+ row_focus = topic_row_index;+ }+ }, 0);+ return false;+ }+if ($elt.attr("id") === "recent_view_search") {// Since the search box a text area, we want the browser to handle// Left/Right and selection within the widget; but if the user@@ -1551,18 +1586,12 @@ export function change_focused_element($elt: JQuery, input_key: string): booleancase "vim_up":case "open_recent_view":return false;- case "shift_tab":- $current_focus_elem = filter_buttons().last();- break;case "left_arrow":if (start !== 0 || is_selected) {return false;}$current_focus_elem = filter_buttons().last();break;- case "tab":- $current_focus_elem = filter_buttons().first();- break;case "right_arrow":if (end !== text_length || is_selected) {return false;@@ -1594,7 +1623,6 @@ export function change_focused_element($elt: JQuery, input_key: string): booleancase "click":$current_focus_elem = $elt;return true;- case "shift_tab":case "vim_left":case "left_arrow":if (filter_buttons().first()[0] === $elt[0]) {@@ -1603,7 +1631,6 @@ export function change_focused_element($elt: JQuery, input_key: string): boolean$current_focus_elem = $elt.prev();}break;- case "tab":case "vim_right":case "right_arrow":if (filter_buttons().last()[0] === $elt[0]) {@@ -1638,12 +1665,10 @@ export function change_focused_element($elt: JQuery, input_key: string): booleancase "open_recent_view":set_default_focus();return true;- case "shift_tab":case "vim_left":case "left_arrow":left_arrow_navigation(row_focus, col_focus);break;- case "tab":case "vim_right":case "right_arrow":right_arrow_navigation(row_focus, col_focus);diff --git a/web/templates/recent_view_row.hbs b/web/templates/recent_view_row.hbsindex 7d04a57ab49..1f7ebb5749c 100644--- a/web/templates/recent_view_row.hbs+++ b/web/templates/recent_view_row.hbs@@ -1,7 +1,7 @@<tr id="recent_conversation:{{conversation_key}}" class="{{#if unread_count}}unread_topic{{/if}} {{#if is_private}}private_conversation_row{{/if}}"><td class="recent_topic_stream"><div class="flex_container flex_container_pm">- <div class="left_part recent_view_focusable">+ <div class="left_part recent_view_focusable" data-col-index="{{ column_indexes.stream }}">{{#if is_private}}<span class="fa fa-envelope"></span><a href="{{pm_url}}">{{t "Direct messages" }}</a>@@ -30,7 +30,7 @@</td><td class="recent_topic_name"{{#if (not is_spectator) }} colspan="2"{{/if}}><div class="flex_container">- <div class="left_part recent_view_focusable line_clamp">+ <div class="left_part recent_view_focusable line_clamp" data-col-index="{{ column_indexes.topic }}">{{#if is_private}}<a href="{{pm_url}}">{{{rendered_pm_with}}}</a>{{else}}@@ -40,12 +40,12 @@<div class="right_part">{{#if is_private}}<div class="recent_topic_actions">- <div class="recent_view_focusable">+ <div class="recent_view_focusable" data-col-index="{{ column_indexes.read }}"><span class="unread_count unread_count_pm {{#unless unread_count}}unread_hidden{{/unless}} tippy-zulip-tooltip on_hover_topic_read" data-user-ids-string="{{user_ids_string}}" data-tippy-content="{{t 'Mark as read' }}" role="button" tabindex="0" aria-label="{{t 'Mark as read' }}">{{unread_count}}</span></div></div><div class="recent_topic_actions dummy_action_button">- <div class="recent_view_focusable">+ <div class="recent_view_focusable" data-col-index="{{ column_indexes.read }}">{{!-- Invisible icon, used only for alignment of unread count. --}}<i class="zulip-icon zulip-icon-mute on_hover_topic_unmute recipient_bar_icon"></i></div>@@ -54,13 +54,13 @@<span class="unread_mention_info tippy-zulip-tooltip {{#unless mention_in_unread}}unread_hidden{{/unless}}"data-tippy-content="{{t 'You have mentions'}}">@</span><div class="recent_topic_actions">- <div class="recent_view_focusable hidden-for-spectators">+ <div class="recent_view_focusable hidden-for-spectators" data-col-index="{{ column_indexes.read }}"><span class="unread_count {{#unless unread_count}}unread_hidden{{/unless}} tippy-zulip-tooltip on_hover_topic_read" data-stream-id="{{stream_id}}" data-topic-name="{{topic}}" data-tippy-content="{{t 'Mark as read' }}" role="button" tabindex="0" aria-label="{{t 'Mark as read' }}">{{unread_count}}</span></div></div><div class="recent_topic_actions"><div class="hidden-for-spectators">- <span class="recent_view_focusable change_visibility_policy hidden-for-spectators" data-stream-id="{{stream_id}}" data-topic-name="{{topic}}">+ <span class="recent_view_focusable change_visibility_policy hidden-for-spectators" data-stream-id="{{stream_id}}" data-topic-name="{{topic}}" data-col-index="{{ column_indexes.mute }}">{{#if (eq visibility_policy all_visibility_policies.FOLLOWED)}}<i class="zulip-icon zulip-icon-follow recipient_bar_icon" data-tippy-content="{{t 'You follow this topic'}}"role="button" tabindex="0" aria-haspopup="true" aria-label="{{t 'You follow this topic' }}"></i>diff --git a/web/tests/recent_view.test.js b/web/tests/recent_view.test.jsindex 2686b0197b2..d2fb2fa93bd 100644--- a/web/tests/recent_view.test.js+++ b/web/tests/recent_view.test.js@@ -413,6 +413,7 @@ function generate_topic_data(topic_info_array) {visibility_policy,all_visibility_policies,is_spectator: page_params.is_spectator,+ column_indexes: rt.COLUMNS,});}return data;