Include search term in title for improved accessibility (#14805)

* Include search term in title for improved accessibility

* Update index.html.erb

* update examples with correct description

Co-authored-by: Michael Kohl <citizen428@forem.com>
This commit is contained in:
Monica Mateiu 2021-09-28 15:18:35 +01:00 committed by GitHub
parent a5e8ed66ee
commit 00c5af783e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -19,7 +19,9 @@
</div>
<div class="block s:flex items-center justify-between">
<h1 class="crayons-title hidden s:block pl-2">Search results</h1>
<h1 class="crayons-title hidden s:block pl-2">
Search results <%= "for #{params[:q]}" unless params[:q].empty? %>
</h1>
<nav id="sorting-option-tabs" aria-label="Search result sort options" class="-mx-3 m:mx-0">
<ul class="crayons-navigation crayons-navigation--horizontal">

View file

@ -6,5 +6,19 @@ RSpec.describe "Stories::ArticlesSearchController", type: :request do
get "/search?q=hello"
expect(response.body).to include("=> Search Results")
end
context "with non-empty query" do
it "renders search term in page title" do
get "/search?q=hello"
expect(response.body).to include("Search results for hello")
end
end
context "with empty query" do
it "renders default page title" do
get "/search?q="
expect(response.body).to include("Search results\s")
end
end
end
end