Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
popovers: Add keyboard support for stream popovers in left sidebar.
Mohit Gupta2579781a0aed
diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.jsindex 7709c371716..2f984d33f86 100644--- a/frontend_tests/node_tests/hotkey.js+++ b/frontend_tests/node_tests/hotkey.js@@ -210,6 +210,9 @@ run_test("basic_chars", () => {actions_popped: return_false,message_info_popped: return_false,});+ set_global("stream_popover", {+ stream_popped: return_false,+ });set_global("emoji_picker", {reactions_popped: return_false,});diff --git a/static/js/hotkey.js b/static/js/hotkey.jsindex 7abbf08d977..fac33508db2 100644--- a/static/js/hotkey.js+++ b/static/js/hotkey.js@@ -301,6 +301,11 @@ exports.process_enter_key = function (e) {return true;}+ if (stream_popover.stream_popped()) {+ stream_popover.stream_sidebar_menu_handle_keyboard("enter");+ return true;+ }+if (overlays.settings_open()) {// On the settings page just let the browser handle// the Enter key for things like submitting forms.@@ -553,6 +558,11 @@ exports.process_hotkey = function (e, hotkey) {popovers.user_info_popover_handle_keyboard(event_name);return true;}++ if (stream_popover.stream_popped()) {+ stream_popover.stream_sidebar_menu_handle_keyboard(event_name);+ return true;+ }}// The next two sections date back to 00445c84 and are Mac/Chrome-specific,diff --git a/static/js/stream_popover.js b/static/js/stream_popover.jsindex edf719c0368..6c68cb8fb3e 100644--- a/static/js/stream_popover.js+++ b/static/js/stream_popover.js@@ -15,6 +15,25 @@ let current_topic_sidebar_elem;let all_messages_sidebar_elem;let starred_messages_sidebar_elem;+function get_popover_menu_items(sidebar_elem) {+ if (!sidebar_elem) {+ blueslip.error("Trying to get menu items when action popover is closed.");+ return;+ }++ const popover_data = $(sidebar_elem).data("popover");+ if (!popover_data) {+ blueslip.error("Cannot find popover data for stream sidebar menu.");+ return;+ }+ return $("li:not(.divider):visible > a", popover_data.$tip);+}++exports.stream_sidebar_menu_handle_keyboard = (key) => {+ const items = get_popover_menu_items(current_stream_sidebar_elem);+ popovers.popover_items_handle_keyboard(key, items);+};+function elem_to_stream_id(elem) {const stream_id = parseInt(elem.attr("data-stream-id"), 10);diff --git a/static/templates/stream_sidebar_actions.hbs b/static/templates/stream_sidebar_actions.hbsindex 9090392790a..d1587e9450c 100644--- a/static/templates/stream_sidebar_actions.hbs+++ b/static/templates/stream_sidebar_actions.hbs@@ -13,14 +13,15 @@<hr>+ {{! tabindex="0" Makes anchor tag focusable. Needed for keyboard support. }}<li>- <a class="open_stream_settings">+ <a tabindex="0" class="open_stream_settings"><i class="fa fa-cog" aria-hidden="true"></i>{{t "Stream settings" }}</a></li><li>- <a class="pin_to_top">+ <a tabindex="0" class="pin_to_top"><i class="fa fa-thumb-tack stream-pin-icon" aria-hidden="true"></i>{{#if stream.pin_to_top}}{{t "Unpin stream from top"}}@@ -30,13 +31,13 @@</a></li><li>- <a class="mark_stream_as_read">+ <a tabindex="0" class="mark_stream_as_read"><i class="fa fa-book" aria-hidden="true"></i>{{t "Mark all messages as read"}}</a></li><li>- <a class="toggle_stream_muted">+ <a tabindex="0" class="toggle_stream_muted">{{#if stream.is_muted}}<i class="fa fa-bell" aria-hidden="true"></i>{{t "Unmute stream"}}@@ -47,14 +48,14 @@</a></li><li>- <a class="popover_sub_unsub_button" data-name="{{stream.name}}">+ <a tabindex="0" class="popover_sub_unsub_button" data-name="{{stream.name}}"><i class='fa fa-envelope' aria-hidden="true"></i>{{t "Unsubscribe" }}</a></li><li><span class="colorpicker-container"><input stream_id="{{stream.stream_id}}" class="colorpicker" type="text" value="{{stream.color}}" /></span>- <a class="choose_stream_color">+ <a tabindex="0" class="choose_stream_color"><i class="fa fa-eyedropper" aria-hidden="true"></i>{{t "Change color" }}</a>