Skip to content

Commit c570cd3

Browse files
Add toggle for filters on mobile UI
** Why are these changes being introduced: * The result filters are awkward on a mobile display, and may only be needed for some users. Rather than having them display by default, and take up space that is very precious, we want to only show a UI control to expose them when needed. ** Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/gdt-174 ** How does this address that need: * This adds a button above the filters panel markup, and adds a few classes to the existing markup at the top of the filters panel. * With CSS, we hide the filters panel on the smallest screens using a new hidden-sm class. This class is then toggled via javascript when the user clicks on the UI button. * The javascript is part of a new file - app/javascript/filters.js - which is loaded by the filters partial. ** Document any side effects to this change: * I'm not sure where best to add the .hidden-sm class to this codebase. For now I'm adding it to a new _layouts module. * During initial testing, it feels awkward to have competing scroll bars in the filter UI by imposing a maximum height on the panels. Because the user has now chosen explicitly to show the filters, it feels better to just have them take up the space they need, rather than making the user navigate overlapping scroll bars on a linear display. So this overrides the maximum filter panel height.
1 parent 1893e51 commit c570cd3

File tree

5 files changed

+76
-3
lines changed

5 files changed

+76
-3
lines changed

app/assets/stylesheets/application.css.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@import "partials/_alerts";
99
@import "partials/_filters";
1010
@import "partials/_global_alerts";
11+
@import "partials/_layouts";
1112
@import "partials/_local_nav";
1213
@import "partials/_pagination";
1314
@import "partials/_panels";

app/assets/stylesheets/partials/_filters.scss

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
overflow-y: scroll;
3333
scrollbar-gutter: auto;
3434
scroll-behavior: auto;
35+
36+
@media (max-width: $bp-screen-sm) {
37+
max-height: inherit;
38+
}
3539
}
3640
}
3741
&.expanded:after {
@@ -107,3 +111,49 @@
107111
}
108112
}
109113
}
114+
115+
button#filter-toggle {
116+
align-items: center;
117+
background: none;
118+
border: none;
119+
color: blue;
120+
display: flex;
121+
justify-content: start;
122+
margin-bottom: 0.5em;
123+
width: 100%;
124+
text-align: left;
125+
126+
@media (min-width: $bp-screen-sm) {
127+
display: none;
128+
}
129+
130+
&::before {
131+
content: '\f0b0';
132+
font-family: FontAwesome;
133+
font-size: 150%;
134+
margin-right: 0.5em;
135+
}
136+
137+
&:hover,
138+
&:focus {
139+
background: blue;
140+
color: white;
141+
}
142+
143+
.filter-toggle-name {
144+
display: block;
145+
}
146+
.filter-toggle-hide {
147+
display: none;
148+
}
149+
150+
&.expanded {
151+
.filter-toggle-name {
152+
display: none;
153+
}
154+
.filter-toggle-hide {
155+
display: block;
156+
}
157+
}
158+
}
159+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.hidden-sm {
2+
@media (max-width: $bp-screen-sm) {
3+
display: none;
4+
}
5+
}

app/javascript/filters.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// These elements aren't loaded with the initial DOM, they appear later.
2+
function initFilterToggle() {
3+
var filter_toggle = document.getElementById('filter-toggle');
4+
var filter_panel = document.getElementById('filters');
5+
filter_toggle.addEventListener('click', event => {
6+
filter_panel.classList.toggle('hidden-sm');
7+
filter_toggle.classList.toggle('expanded');
8+
9+
});
10+
}
11+
12+
initFilterToggle();

app/views/search/results.html.erb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
<div class="<%= @filters.present? ? 'layout-1q3q' : 'layout-3q1q' %> layout-band top-space">
1919
<% if @filters.present? %>
2020
<aside class="col1q filter-container">
21-
<div id="filters">
22-
<h2 class="hd-3">Filter your results</h2>
23-
<h3 class="hd-4"><em><%= results_summary(@pagination[:hits]) %></em></h3>
21+
<button id="filter-toggle"><span class="filter-toggle-name">Filter your results: <%= results_summary(@pagination[:hits]) %></span><span class="filter-toggle-hide">Hide filters</span></button>
22+
<div id="filters" class="hidden-sm">
23+
<div class="hidden-sm">
24+
<h2 class="hd-3">Filter your results</h2>
25+
<h3 class="hd-4"><em><%= results_summary(@pagination[:hits]) %></em></h3>
26+
</div>
2427
<% @filters&.each_with_index do |(category, values), index| %>
2528
<% if index == 0 %>
2629
<%= render(partial: 'search/filter', locals: { category: category, values: values, first: true }) %>
@@ -53,3 +56,5 @@
5356
<%= render partial: 'shared/ask', locals: { display: 'view-md' } %>
5457
<% end %>
5558
</div>
59+
60+
<%= javascript_include_tag "filters" %>

0 commit comments

Comments
 (0)