Skip to content

A platform for community discussion. Free, open, simple.

UX: Close chat search on Escape (#36056)

Jarek Radoszad017d0b1819
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-filter.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel-filter.gjs
index 007b39e43c9..f01e9c908bf 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-filter.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-filter.gjs
@@ -8,6 +8,7 @@ import { service } from "@ember/service";
import { isBlank } from "@ember/utils";
import DButton from "discourse/components/d-button";
import FilterInput from "discourse/components/filter-input";
+import closeOnEscape from "discourse/float-kit/modifiers/close-on-escape";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import discourseDebounce from "discourse/lib/debounce";
@@ -151,6 +152,7 @@ export default class ChatChannelFilter extends Component {
<div>
<FilterInput
{{autoFocus}}
+ {{closeOnEscape (fn @onToggleFilter false)}}
@value={{this.currentChannelFilter}}
placeholder={{i18n "chat.search.title"}}
@filterAction={{this.loadSearchResults}}
diff --git a/plugins/chat/spec/system/chat_channel_search/drawer_spec.rb b/plugins/chat/spec/system/chat_channel_search/drawer_spec.rb
index 9770f6ce953..de85749ac7e 100644
--- a/plugins/chat/spec/system/chat_channel_search/drawer_spec.rb
+++ b/plugins/chat/spec/system/chat_channel_search/drawer_spec.rb
@@ -64,6 +64,15 @@ RSpec.describe "Chat channel search - drawer", type: :system do
expect(channel_page.filter).to be_visible
expect(channel_page.filter).to have_no_state
end
+
+ it "closes the filter on Escape" do
+ drawer_page.visit_channel(channel_1)
+ channel_page.filter.toggle
+ expect(channel_page.filter).to be_visible
+
+ page.send_keys(:escape)
+ expect(channel_page.filter).to be_not_visible
+ end
end
context "when filter is not toggled" do