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.

left_sidebar: Allow keyboard navigation to toggle channel folders.

Evy Kassirer1a6f8789008a
diff --git a/web/src/left_sidebar_tooltips.ts b/web/src/left_sidebar_tooltips.ts
index b77920eb75b..964b85eb48a 100644
--- a/web/src/left_sidebar_tooltips.ts
+++ b/web/src/left_sidebar_tooltips.ts
@@ -16,6 +16,24 @@ import {
import * as unread from "./unread.ts";
import {user_settings} from "./user_settings.ts";
+// Watches the reference element's class for changes while a tooltip is
+// visible, so the content stays accurate when the element is toggled via
+// keyboard (or any other path) without hiding the tooltip first.
+const class_observers = new WeakMap<tippy.Instance, MutationObserver>();
+function observe_toggle_class(instance: tippy.Instance, update: () => void): void {
+ update();
+ const observer = new MutationObserver(update);
+ observer.observe(instance.reference, {
+ attributes: true,
+ attributeFilter: ["class"],
+ });
+ class_observers.set(instance, observer);
+}
+function disconnect_toggle_class(instance: tippy.Instance): void {
+ class_observers.get(instance)?.disconnect();
+ class_observers.delete(instance);
+}
+
export function initialize(): void {
tippy.delegate("body", {
target: ".tippy-left-sidebar-tooltip",
@@ -201,6 +219,26 @@ export function initialize(): void {
},
});
+ tippy.delegate("body", {
+ target: ".folder-toggle-tooltip-target",
+ onShow(instance) {
+ const $toggle = $(instance.reference);
+ observe_toggle_class(instance, () => {
+ if ($toggle.hasClass("rotate-icon-down")) {
+ instance.setContent($t({defaultMessage: "Collapse folder"}));
+ } else {
+ instance.setContent($t({defaultMessage: "Expand folder"}));
+ }
+ });
+ },
+ delay: EXTRA_LONG_HOVER_DELAY,
+ appendTo: () => document.body,
+ onHidden(instance) {
+ disconnect_toggle_class(instance);
+ instance.destroy();
+ },
+ });
+
tippy.delegate("body", {
target: ".header-main .column-left .left-sidebar-toggle-button",
delay: LONG_HOVER_DELAY,
diff --git a/web/src/stream_list.ts b/web/src/stream_list.ts
index 247cb3c5a06..f8353de173b 100644
--- a/web/src/stream_list.ts
+++ b/web/src/stream_list.ts
@@ -1601,6 +1601,17 @@ export function set_event_handlers({
},
);
+ $("#streams_list").on(
+ "keydown",
+ ".stream-list-section-container .stream-list-section-toggle",
+ function (this: HTMLElement, e: JQuery.KeyDownEvent) {
+ if (keydown_util.is_enter_event(e)) {
+ e.stopPropagation();
+ toggle_section_collapse($(this).closest(".stream-list-section-container"));
+ }
+ },
+ );
+
$("#streams_list").on(
"click",
".stream-list-section-container .add-stream-icon-container",
diff --git a/web/styles/left_sidebar.css b/web/styles/left_sidebar.css
index a50b9aa22a5..38418778ee3 100644
--- a/web/styles/left_sidebar.css
+++ b/web/styles/left_sidebar.css
@@ -755,6 +755,16 @@
}
}
+.stream-list-section-toggle {
+ &:focus {
+ outline: 0;
+ }
+
+ &:focus-visible {
+ outline: 2px solid var(--color-outline-focus);
+ }
+}
+
.active-direct-messages-section {
background-color: var(--color-background-active-narrow-filter);
diff --git a/web/templates/stream_list_section_container.hbs b/web/templates/stream_list_section_container.hbs
index 77a5276f806..7f38f332890 100644
--- a/web/templates/stream_list_section_container.hbs
+++ b/web/templates/stream_list_section_container.hbs
@@ -1,6 +1,6 @@
<div id="stream-list-{{id}}-container" data-section-id="{{id}}" class="stream-list-section-container">
<div class="left-sidebar-section-header stream-list-subsection-header">
- <i class="stream-list-section-toggle zulip-icon zulip-icon-heading-triangle-right rotate-icon-down" aria-hidden="true"></i>
+ <i class="stream-list-section-toggle zulip-icon zulip-icon-heading-triangle-right rotate-icon-down folder-toggle-tooltip-target" tabindex="0" role="button"></i>
<h4 class="left-sidebar-title">
{{section_title}}
</h4>