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: Offer to expand search to all topics.

Evy Kassirer5cfe686dd2f3
diff --git a/web/src/sidebar_ui.ts b/web/src/sidebar_ui.ts
index c4fae014e0b..0d543cbee6e 100644
--- a/web/src/sidebar_ui.ts
+++ b/web/src/sidebar_ui.ts
@@ -573,12 +573,19 @@ function all_rows(): JQuery {
"#streams_list.is_searching .stream-list-toggle-inactive-or-muted-channels.bottom_left_row",
);
+ // Exclude the topic-search hint row when it's hidden; when shown,
+ // it should be a navigable row.
+ const $hidden_topic_search_hint_row = $(
+ "#left-sidebar-topic-search-hint.hidden .left-sidebar-topic-search-hint-link",
+ );
+
const $filtered_rows = $all_rows
.not($inactive_or_muted_rows)
.not($collapsed_views)
.not($collapsed_channels)
.not($hidden_topic_rows)
- .not($toggle_inactive_or_muted_channels_row);
+ .not($toggle_inactive_or_muted_channels_row)
+ .not($hidden_topic_search_hint_row);
// With a "topic:" prefix search, keyboard navigation only lands on
// topic rows, not channel header rows.
@@ -589,6 +596,25 @@ function all_rows(): JQuery {
return $filtered_rows;
}
+const TOPIC_SEARCH_HINT_MIN_LENGTH = 2;
+
+function should_show_topic_search_hint(search_term: string): boolean {
+ // Once the user is already searching with the "topic:" prefix,
+ // topic-search results are visible and the hint is no longer
+ // useful. Otherwise, surface the hint as soon as the user has
+ // typed enough that they might want to expand the search.
+ return search_term.length >= TOPIC_SEARCH_HINT_MIN_LENGTH && !ui_util.is_topic_search();
+}
+
+function initiate_topic_search(): void {
+ const $search_input = $<HTMLInputElement>("input.left-sidebar-search-input").expectOne();
+ const current_value = ($search_input.val() ?? "").trim();
+ const new_value = ui_util.TOPIC_SEARCH_PREFIX + " " + current_value;
+ $search_input.val(new_value);
+ util.the($search_input).setSelectionRange(new_value.length, new_value.length);
+ $search_input.trigger("focus").trigger("input");
+}
+
class LeftSidebarListCursor extends ListCursor<JQuery> {
override adjust_scroll($li: JQuery): void {
$li[0]!.scrollIntoView({
@@ -612,6 +638,14 @@ export function initialize_left_sidebar_cursor(): void {
return undefined;
}
const $non_header_rows = $all_rows.not($(get_header_rows_selectors()));
+ // Prefer landing on a real result row first; fall
+ // back to the topic-search hint only when there are
+ // no other matches, so the hint never steals initial
+ // highlight from matching channels or topics.
+ const $non_hint_rows = $non_header_rows.not(".left-sidebar-topic-search-hint-link");
+ if ($non_hint_rows.length > 0) {
+ return $non_hint_rows.first();
+ }
return $non_header_rows.first();
},
next_key($key) {
@@ -670,6 +704,13 @@ function actually_update_left_sidebar_for_search(): void {
stream_list.update_streams_sidebar();
resize.resize_page_components();
+ const show_topic_search_hint = should_show_topic_search_hint(search_value);
+ if (show_topic_search_hint) {
+ $(".left-sidebar-topic-search-hint-label").text(
+ $t({defaultMessage: "Search all topics for ‘{query}’"}, {query: search_value}),
+ );
+ }
+ $("#left-sidebar-topic-search-hint").toggleClass("hidden", !show_topic_search_hint);
left_sidebar_cursor.reset();
$("#left-sidebar-empty-list-message").toggleClass(
"hidden",
@@ -834,6 +875,11 @@ export function set_event_handlers(): void {
return;
}
+ if ($row.hasClass("left-sidebar-topic-search-hint-link")) {
+ initiate_topic_search();
+ return;
+ }
+
if ($row[0]!.id === "views-label-container") {
$row.find("#toggle-top-left-navigation-area-icon").trigger("click");
return;
@@ -902,6 +948,12 @@ export function set_event_handlers(): void {
// Handle arrow key navigation when a sidebar element has Tab
// focus, so that Tab and arrow key navigation stay in sync.
$("#left-sidebar").on("keydown", handle_left_sidebar_arrow_navigation);
+
+ $("body").on("click", ".left-sidebar-topic-search-hint-link", (e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ initiate_topic_search();
+ });
}
export function initiate_search(): void {
diff --git a/web/src/ui_util.ts b/web/src/ui_util.ts
index 73e235bd04c..81387af0285 100644
--- a/web/src/ui_util.ts
+++ b/web/src/ui_util.ts
@@ -350,7 +350,7 @@ export function rewire_get_left_sidebar_search_term(
get_left_sidebar_search_term = value;
}
-const TOPIC_SEARCH_PREFIX = "topic:";
+export const TOPIC_SEARCH_PREFIX = "topic:";
export function get_left_sidebar_topic_search_term(): string | undefined {
const search_term = get_left_sidebar_search_term();
diff --git a/web/styles/left_sidebar.css b/web/styles/left_sidebar.css
index acc2c9dd277..c8761755801 100644
--- a/web/styles/left_sidebar.css
+++ b/web/styles/left_sidebar.css
@@ -978,6 +978,60 @@
}
}
+#left-sidebar-topic-search-hint {
+ /* Match the outer spacing used by #subscribe-to-more-streams so
+ icon and label align with that row's icon and label. */
+ margin-right: var(--left-sidebar-right-margin);
+}
+
+.left-sidebar-topic-search-hint-link {
+ /* Padding on the link (which fills the row) keeps the focus ring
+ spanning the full row width. */
+ padding-left: var(--left-sidebar-toggle-width-offset);
+ display: grid;
+ grid-template:
+ "icon . text" minmax(var(--line-height-sidebar-row-prominent), auto)
+ / var(--left-sidebar-icon-column-width)
+ var(--left-sidebar-icon-content-gap)
+ minmax(0, 1fr);
+ align-items: center;
+ border-radius: 4px;
+ cursor: pointer;
+
+ /* Override the global a:hover / a:focus rule in zulip.css that
+ adds underline and changes the color to the generic link color. */
+ &,
+ &:hover,
+ &:focus {
+ color: var(--color-text-sidebar-row);
+ text-decoration: none;
+ }
+
+ &:hover {
+ background-color: var(--color-background-hover-narrow-filter);
+ }
+
+ /* Match the inset outline used by .highlighted_row so Tab and
+ arrow key focus look identical and don't clip outside the row. */
+ &:focus-visible {
+ outline: 2px solid var(--color-outline-focus);
+ outline-offset: -2px;
+ }
+
+ .zulip-icon {
+ grid-area: icon;
+ justify-self: center;
+ opacity: 0.7;
+ }
+
+ .left-sidebar-topic-search-hint-label {
+ grid-area: text;
+ overflow: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
+ }
+}
+
#stream_filters .narrow-filter,
#direct-messages-list .bottom_left_row {
a.stream-name:focus,
diff --git a/web/templates/left_sidebar.hbs b/web/templates/left_sidebar.hbs
index 938512650ef..1e07506ca1e 100644
--- a/web/templates/left_sidebar.hbs
+++ b/web/templates/left_sidebar.hbs
@@ -15,6 +15,12 @@
empty_list_message=(t "No matches.")
}}
</ul>
+ <div id="left-sidebar-topic-search-hint" class="hidden">
+ <a tabindex="0" role="button" class="bottom_left_row left-sidebar-topic-search-hint-link">
+ <i class="zulip-icon zulip-icon-search" aria-hidden="true"></i>
+ <span class="left-sidebar-topic-search-hint-label"></span>
+ </a>
+ </div>
<div id="left-sidebar-navigation-area" class="left-sidebar-navigation-area">
<div id="views-label-container" class="left-sidebar-section-header showing-expanded-navigation{{#if is_spectator}} remove-pointer-for-spectator{{/if}}">
<i id="toggle-top-left-navigation-area-icon" class="zulip-icon zulip-icon-heading-triangle-right sidebar-heading-icon rotate-icon-down views-tooltip-target hidden-for-spectators" aria-hidden="true" tabindex="0" role="button"></i>