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.

overlays: Trap keyboard focus in informational overlays.

Ayush Sinhaabba58eeab92
diff --git a/web/src/overlays.ts b/web/src/overlays.ts
index c693e80320c..fce0a0744c5 100644
--- a/web/src/overlays.ts
+++ b/web/src/overlays.ts
@@ -297,4 +297,30 @@ export function trap_focus_for_settings_overlay(): void {
}
}
});
+
+ $(".overlay[data-overlay='informationalOverlays']").on("keydown", (e) => {
+ if (e.key !== "Tab") {
+ return;
+ }
+
+ const $overlay = $(e.currentTarget);
+ const visible_focusable_elements =
+ overlay_util.get_visible_focusable_elements_in_overlay_container($overlay);
+
+ if (visible_focusable_elements.length === 0) {
+ return;
+ }
+
+ if (e.shiftKey) {
+ if (document.activeElement === visible_focusable_elements[0]) {
+ e.preventDefault();
+ visible_focusable_elements.at(-1)!.focus();
+ }
+ } else {
+ if (document.activeElement === visible_focusable_elements.at(-1)) {
+ e.preventDefault();
+ visible_focusable_elements[0]!.focus();
+ }
+ }
+ });
}