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.

recent_view: Supress focus outline till first user keypress.

Aman Agrawal0f9a01834be5
diff --git a/templates/zerver/app/index.html b/templates/zerver/app/index.html
index f9df8c9519c..3f69bbf4bc0 100644
--- a/templates/zerver/app/index.html
+++ b/templates/zerver/app/index.html
@@ -194,7 +194,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1943053 -->
</div>
<div class="column-middle">
<div class="column-middle-inner">
- <div id="recent_view">
+ <div id="recent_view" class="no-visible-focus-outlines">
<div class="recent_view_container">
<div id="recent_view_table"></div>
</div>
diff --git a/web/src/focus_outline_util.ts b/web/src/focus_outline_util.ts
index aeb75fb43b8..56afcf6f8ef 100644
--- a/web/src/focus_outline_util.ts
+++ b/web/src/focus_outline_util.ts
@@ -22,10 +22,7 @@ const NAVIGATION_KEYS = new Set([
* removed (i.e. this is the first navigation keypress), so callers
* can decide whether to skip the normal navigation action.
*/
-export function maybe_show_focus_outlines(
- $container: JQuery,
- input_key: string,
-): boolean {
+export function maybe_show_focus_outlines($container: JQuery, input_key: string): boolean {
if ($container.hasClass("no-visible-focus-outlines") && NAVIGATION_KEYS.has(input_key)) {
$container.removeClass("no-visible-focus-outlines");
return true;
diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.ts
index baf35db512b..343279dcb02 100644
--- a/web/src/recent_view_ui.ts
+++ b/web/src/recent_view_ui.ts
@@ -19,6 +19,7 @@ import * as compose_closed_ui from "./compose_closed_ui.ts";
import * as dialog_widget from "./dialog_widget.ts";
import * as dropdown_widget from "./dropdown_widget.ts";
import type {DropdownWidget} from "./dropdown_widget.ts";
+import * as focus_outline_util from "./focus_outline_util.ts";
import * as folder_dropdown_widget from "./folder_dropdown_widget.ts";
import * as hash_util from "./hash_util.ts";
import {$t, $t_html} from "./i18n.ts";
@@ -1795,6 +1796,19 @@ export function change_focused_element($elt: JQuery, input_key: string): boolean
// preventDefault/stopPropagation; false will let the browser
// handle the key.
+ const is_first_navigation = focus_outline_util.maybe_show_focus_outlines(
+ $("#recent_view"),
+ input_key,
+ );
+
+ if (is_first_navigation && is_table_focused()) {
+ // First navigation keypress after page load / view switch:
+ // just reveal the focus ring on the current row without
+ // moving to a different row.
+ set_table_focus(row_focus, col_focus, true);
+ return true;
+ }
+
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
diff --git a/web/styles/recent_view.css b/web/styles/recent_view.css
index 4eec8f74f1b..c40ac0d0e52 100644
--- a/web/styles/recent_view.css
+++ b/web/styles/recent_view.css
@@ -47,6 +47,16 @@
padding: 0.1875em 0.5em; /* 3px 8px at 16px/1em */
}
+ /* Suppress focus rings when focus was set programmatically
+ (e.g., on page load or sidebar click). The class is removed
+ on the first keyboard navigation, restoring :focus outlines.
+ See focus_outline_util.ts. */
+ &.no-visible-focus-outlines .recent_view_focusable {
+ &:focus {
+ outline: 0;
+ }
+ }
+
.recent_view_focusable {
& > .zulip-icon {
outline: 0;
diff --git a/web/tests/focus_outline_util.test.cjs b/web/tests/focus_outline_util.test.cjs
new file mode 100644
index 00000000000..36cb2fbd88f
--- /dev/null
+++ b/web/tests/focus_outline_util.test.cjs
@@ -0,0 +1,32 @@
+"use strict";
+
+const assert = require("node:assert/strict");
+
+const {zrequire} = require("./lib/namespace.cjs");
+const {run_test} = require("./lib/test.cjs");
+const $ = require("./lib/zjquery.cjs");
+
+const focus_outline_util = zrequire("focus_outline_util");
+
+run_test("removes class on first navigation keypress", () => {
+ const $container = $("#test-container");
+ $container.addClass("no-visible-focus-outlines");
+
+ assert.equal(focus_outline_util.maybe_show_focus_outlines($container, "tab"), true);
+ assert.equal($container.hasClass("no-visible-focus-outlines"), false);
+});
+
+run_test("returns false when class already removed", () => {
+ const $container = $("#test-container");
+ // No class added — simulates second keypress.
+ assert.equal(focus_outline_util.maybe_show_focus_outlines($container, "tab"), false);
+});
+
+run_test("returns false for non-navigation key", () => {
+ const $container = $("#test-container");
+ $container.addClass("no-visible-focus-outlines");
+
+ assert.equal(focus_outline_util.maybe_show_focus_outlines($container, "enter"), false);
+ // Class should not be removed.
+ assert.equal($container.hasClass("no-visible-focus-outlines"), true);
+});