Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored online content toggle for accessibility #1493

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 50 additions & 3 deletions app/assets/stylesheets/modules/toc.scss
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,53 @@
}
}

.toggle {
position: relative;
display: inline-block;
max-width: 20px;
min-width: 20px;
height: 12px;
}
.toggle input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
background-color: #ccc;
top: 0;
left: 0;
right: 0;
bottom: 0;
transition: .4s;
-webkit-transition: .4s;
border-radius: 12px;
}
.slider:before {
position: absolute;
content: "";
height: 8px;
width: 8px;
left: 2px;
bottom: 2px;
background-color: white;
transition: .4s;
-webkit-transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: #397339;
}
input:checked + .slider:before {
transform: translateX(8px);
-webkit-transform: translateX(8px);
}
input:focus + .slider {
box-shadow: 0 0 1px #397339;
}

.toc-online-toggle {
padding: 10px 10px;
background-color: $background-gray;
Expand All @@ -101,11 +148,11 @@
.blacklight-icon-online {
margin-right: 10px;
}
& svg {
fill: #397339 !important;
}
label {
margin-bottom: 0;
display: flex;
gap: 10px;
align-items: center;
&.online-toggle-label {
margin-right: 5px;
}
Expand Down
10 changes: 6 additions & 4 deletions app/views/catalog/_show_collection.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
</div>
<div class="toc-online-toggle al-online-content-icon">
<%= blacklight_icon(:online) %>
<label for="tocOnlineToggle" class="online-toggle-label">Only show materials containing online content</label>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="tocOnlineToggle">
<label class="custom-control-label" for="tocOnlineToggle"></label>
<label for="tocOnlineToggle" class="online-toggle-label">
<span> Only show materials containing online content </span>
<div class="toggle">
<input type="checkbox" id="tocOnlineToggle">
<span class="slider"></span>
</div>
</label>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expected the label tag to close before the toggle div starts, am I mistaken?

</div>
<div id="toc" data-turbolinks-permanent class="collapse show"></div>
<div id="toc-data" data-selected="<%= document.id %>"></div>
Expand Down
10 changes: 6 additions & 4 deletions app/views/catalog/_show_default.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
</div>
<div class="toc-online-toggle al-online-content-icon">
<%= blacklight_icon(:online) %>
<label for="tocOnlineToggle" class="online-toggle-label">Only show materials containing online content</label>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="tocOnlineToggle" <%= "checked" if params[:onlineToggle].to_s == "true" %>>
<label class="custom-control-label" for="tocOnlineToggle"></label>
<label for="tocOnlineToggle" class="online-toggle-label">
Only show materials containing online content
<div class="toggle">
<input type="checkbox" id="tocOnlineToggle">
<span class="slider"><span>
</div>
</label>
</div>
<div id="toc" data-turbolinks-permanent class="collapse show"></div>
<div id="toc-data" data-selected="<%= document.id %>"></div>
Expand Down
7 changes: 7 additions & 0 deletions spec/features/catalog_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@
expect(page).to have_selector "dd.blacklight-collection_bioghist_ssm", text: /Noël Riley Fitch was born on December 24, 1937/
end
end

it "has a toggle switch for showing materials containing online content", js: true do
visit "/catalog/C1491"
expect(page).to have_content "Working Files, 1955-2018"
find(".toggle > span").click
expect(page).not_to have_content "Working Files, 1955-2018"
end
it "shows all the relevant notes" do
visit "/catalog/MC148"

Expand Down