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.

compose: Navigate compose banner via Shift+Tab from recipient dropdown.

Pratik Chandab55ef0feaed5
diff --git a/web/src/compose_recipient.ts b/web/src/compose_recipient.ts
index 6fea73afb32..545cde94ef5 100644
--- a/web/src/compose_recipient.ts
+++ b/web/src/compose_recipient.ts
@@ -406,7 +406,23 @@ export function initialize(): void {
tippy_props: {
offset: [-10, 5],
},
- tab_moves_focus_to_target() {
+ tab_moves_focus_to_target(e: JQuery.KeyDownEvent): string | undefined {
+ if (e.shiftKey) {
+ const $last_banner = $("#compose_banners .main-view-banner").last();
+ if ($last_banner.length === 0) {
+ return undefined;
+ }
+ // The close button is the last element in compose banner, so we return
+ // this if it exists or else check for action buttons.
+ if ($last_banner.find(".main-view-banner-close-button").length > 0) {
+ return "#compose_banners .main-view-banner-close-button:last";
+ }
+ if ($last_banner.find(".main-view-banner-action-button").length > 0) {
+ return "#compose_banners .main-view-banner-action-button:last";
+ }
+ return undefined;
+ }
+
if (compose_state.get_message_type() === "stream") {
return "#stream_message_recipient_topic";
}
diff --git a/web/src/dropdown_widget.ts b/web/src/dropdown_widget.ts
index 4faf1dc459d..46893b096bb 100644
--- a/web/src/dropdown_widget.ts
+++ b/web/src/dropdown_widget.ts
@@ -94,7 +94,7 @@ export type DropdownWidgetOptions = {
// with a keyboard trigger or not.
dropdown_triggered_via_keyboard?: boolean;
// When this is set, pressing tab will move focus to the target element.
- tab_moves_focus_to_target?: string | (() => string);
+ tab_moves_focus_to_target?: (event: JQuery.KeyDownEvent) => string | undefined;
search_placeholder_text?: string;
sort_list_by_filter_value?: (items: Option[], filter_value: string) => Option[];
};
@@ -140,7 +140,7 @@ export class DropdownWidget {
prefer_top_start_placement: boolean;
dropdown_triggered_via_keyboard: boolean;
keep_focus_on_search: boolean;
- tab_moves_focus_to_target: string | (() => string) | undefined;
+ tab_moves_focus_to_target: ((event: JQuery.KeyDownEvent) => string | undefined) | undefined;
current_hover_index: number;
// TODO: This is only used in one widget, with no implementation
@@ -602,15 +602,16 @@ export class DropdownWidget {
case "Tab":
if (this.tab_moves_focus_to_target) {
+ // Prevent focus from leaving the dropdown even when no target
+ // is available.
e.preventDefault();
e.stopPropagation();
- popover_menus.hide_current_popover_if_visible(instance);
- this.current_hover_index = 0;
- const target =
- typeof this.tab_moves_focus_to_target === "function"
- ? this.tab_moves_focus_to_target()
- : this.tab_moves_focus_to_target;
- $(target).trigger("focus");
+ const target = this.tab_moves_focus_to_target(e);
+ if (target !== undefined) {
+ popover_menus.hide_current_popover_if_visible(instance);
+ this.current_hover_index = 0;
+ $(target).trigger("focus");
+ }
} else if (!this.hide_search_box && this.keep_focus_on_search) {
e.preventDefault();
e.stopPropagation();