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.

search: Allow closed searchbox to have keyboard focus to open.

Evy Kassirer87dea8aa92c2
diff --git a/web/src/search.ts b/web/src/search.ts
index 50821722eac..949fead7f0f 100644
--- a/web/src/search.ts
+++ b/web/src/search.ts
@@ -163,6 +163,24 @@ export function initialize(opts: {on_narrow_search: OnNarrowSearch}): void {
$("#searchbox-input-container").toggleClass("focused", false);
});
+ $("#searchbox-input-container").on("keydown", (e) => {
+ if (e.key === "Enter" && $("#searchbox .navbar-search.expanded").length === 0) {
+ // Prevent propagation, and wait for the keyup to open search, because
+ // we also need to prevent propagation there to not have the event caught
+ // by the typeahead event handlers.
+ e.preventDefault();
+ e.stopPropagation();
+ }
+ });
+
+ $("#searchbox-input-container").on("keyup", (e) => {
+ if (e.key === "Enter" && $("#searchbox .navbar-search.expanded").length === 0) {
+ initiate_search();
+ e.preventDefault();
+ e.stopPropagation();
+ }
+ });
+
search_pill_widget = search_pill.create_pills($pill_container);
search_pill_widget.onPillRemove(() => {
search_input_has_changed = true;
diff --git a/web/styles/search.css b/web/styles/search.css
index 5b44116bddb..0fa95686041 100644
--- a/web/styles/search.css
+++ b/web/styles/search.css
@@ -13,6 +13,10 @@
z-index: 1;
}
+ .navbar-search:has(#searchbox-input-container:focus-visible) {
+ outline: 2px solid var(--color-outline-focus);
+ }
+
.search_icon {
grid-area: search-icon;
align-self: center;
diff --git a/web/templates/navbar.hbs b/web/templates/navbar.hbs
index 215bfa736e6..cb38eb003d3 100644
--- a/web/templates/navbar.hbs
+++ b/web/templates/navbar.hbs
@@ -24,7 +24,7 @@
</div>
<div id="searchbox">
<form id="searchbox_form" class="navbar-search">
- <div id="searchbox-input-container" class="input-append pill-container">
+ <div id="searchbox-input-container" class="input-append pill-container" tabindex="0">
<i class="search_icon zulip-icon zulip-icon-search"></i>
<div class="search-input-and-pills">
<div class="search-input input" id="search_query" type="text" data-placeholder-text="{{t 'Search' }}"