Files
discourse/spec/system/search_shortcut_variation_spec.rb
Martin Brennan 735bef9ea0 UX: Remove Ctrl+F search shortcut (#32281)
This commit removes the Ctrl+F search shortcut, which hijacks the
browser search shortcut in Discourse. We are doing this because there
has been many years of complaints around this behaviour, and now that
we have the new header search it has become even more annoying.

We originally added this because we lazy load posts in a topic, and it
might not have been immediately clear to users that they are not
searching
all the posts in the topic when pressing Ctrl+F. However, that was 10+
years
ago, most people are very familiar with lazy loading now, it doesn't
make sense
to keep this additional hijack for this one topic use case.

Search is still accessible by pressing the `/` shortcut.
2025-04-15 15:14:54 +10:00

123 lines
4.5 KiB
Ruby

# frozen_string_literal: true
describe "Search | Shortcuts for variations of search input", type: :system do
fab!(:current_user) { Fabricate(:user) }
let(:welcome_banner) { PageObjects::Components::WelcomeBanner.new }
let(:search_page) { PageObjects::Pages::Search.new }
before { sign_in(current_user) }
context "when search_experience is search_field" do
before { SiteSetting.search_experience = "search_field" }
context "when enable_welcome_banner is true" do
before { SiteSetting.enable_welcome_banner = true }
it "displays and focuses welcome banner search when / is pressed and hides it when Escape is pressed" do
visit("/")
expect(welcome_banner).to be_visible
page.send_keys("/")
expect(search_page).to have_search_menu
expect(current_active_element[:id]).to eq("welcome-banner-search-input")
page.send_keys(:escape)
expect(search_page).to have_no_search_menu_visible
end
context "when welcome banner is not in the viewport" do
before do
visit("/")
fake_scroll_down_long
end
it "displays and focuses header search when / is pressed and hides it when Escape is pressed" do
expect(welcome_banner).to be_invisible
page.send_keys("/")
expect(search_page).to have_search_menu
expect(current_active_element[:id]).to eq("header-search-input")
page.send_keys(:escape)
expect(search_page).to have_no_search_menu_visible
end
end
end
context "when enable_welcome_banner is false" do
before { SiteSetting.enable_welcome_banner = false }
it "displays and focuses header search when / is pressed and hides it when Escape is pressed" do
visit("/")
expect(welcome_banner).to be_hidden
page.send_keys("/")
expect(search_page).to have_search_menu
expect(current_active_element[:id]).to eq("header-search-input")
page.send_keys(:escape)
expect(search_page).to have_no_search_menu_visible
end
end
end
context "when search_experience is search_icon" do
before { SiteSetting.search_experience = "search_icon" }
context "when enable_welcome_banner is true" do
before { SiteSetting.enable_welcome_banner = true }
it "displays and focuses welcome banner search when / is pressed and hides it when Escape is pressed" do
visit("/")
expect(welcome_banner).to be_visible
page.send_keys("/")
expect(search_page).to have_search_menu
expect(current_active_element[:id]).to eq("welcome-banner-search-input")
page.send_keys(:escape)
expect(search_page).to have_no_search_menu_visible
end
context "when welcome banner is not in the viewport" do
before do
visit("/")
fake_scroll_down_long
end
it "displays and focuses search icon search when / is pressed and hides it when Escape is pressed" do
expect(welcome_banner).to be_invisible
page.send_keys("/")
expect(search_page).to have_search_menu
expect(current_active_element[:id]).to eq("icon-search-input")
page.send_keys(:escape)
expect(search_page).to have_no_search_menu_visible
end
end
end
context "when enable_welcome_banner is false" do
before { SiteSetting.enable_welcome_banner = false }
it "displays and focuses search icon search when / is pressed and hides it when Escape is pressed" do
visit("/")
expect(welcome_banner).to be_hidden
page.send_keys("/")
expect(search_page).to have_search_menu
expect(current_active_element[:id]).to eq("icon-search-input")
page.send_keys(:escape)
expect(search_page).to have_no_search_menu_visible
end
# This search menu only shows within a topic, not in other pages on the site,
# unlike header search which is always visible.
context "when within a topic with 20+ posts" do
fab!(:topic)
fab!(:posts) { Fabricate.times(21, :post, topic: topic) }
it "opens search on first press of /, and closes when Escape is pressed" do
visit "/t/#{topic.slug}/#{topic.id}"
page.send_keys("/")
expect(search_page).to have_search_menu
expect(current_active_element[:id]).to eq("icon-search-input")
page.send_keys(:escape)
expect(search_page).to have_no_search_menu_visible
end
end
end
end
end