Skip to content

Commit 0cc75ed

Browse files
Merge pull request #123 from MITLibraries/gdt-174-mobile-filters
Add toggle for filters on mobile UI
2 parents 1893e51 + ce90688 commit 0cc75ed

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-md) {
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-md) {
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-md {
2+
@media (max-width: $bp-screen-md) {
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-md');
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-md">
23+
<div class="hidden-md">
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)