Skip to content

Commit 3a125ad

Browse files
committed
make menu responsive on mobile + track aria-expanded status
1 parent d861090 commit 3a125ad

File tree

5 files changed

+72
-44
lines changed

5 files changed

+72
-44
lines changed

src/js/components/filters.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ class Filters {
206206

207207
/* Duplicate the technology dropdowns */
208208
addTechnologySelector(event) {
209-
console.log('add tech selector');
210-
211209
event.preventDefault();
212210

213211
const selectorTemplate = document.getElementById('tech-selector').content.cloneNode(true);

src/js/main.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
const nav = document.querySelector('header nav');
1+
const nav = document.querySelector('#desktop');
22
const mobileNav = document.querySelector('nav#mobile');
3-
const hamburger = document.querySelector('header .hamburger');
3+
const hamburger = document.querySelector('.hamburger');
44

55
if (mobileNav) {
66
if (hamburger) {
77
hamburger.addEventListener('click', (e) => {
8+
const expanded = hamburger.getAttribute('aria-expanded');
89
mobileNav.classList.toggle('active');
10+
hamburger.ariaExpanded = expanded === 'true' ? 'false' : 'true';
911
});
1012
}
1113

static/css/techreport/techreport.css

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
/* ------------------------- */
9999

100100
/* Page header and footer */
101-
body > :is(header, footer) {
101+
body footer {
102102
background-color: var(--color-card-background);
103103
}
104104

@@ -284,6 +284,23 @@ nav {
284284
transform: translateY(-50%);
285285
}
286286

287+
.report-navigation .hamburger {
288+
padding: 1rem;
289+
color: var(--color-text-lighter);
290+
}
291+
292+
.report-navigation .hamburger:is(:hover, :focus-visible) {
293+
color: var(--color-text-darker);
294+
}
295+
296+
.report-navigation .hamburger:focus-visible {
297+
outline: 1px solid var(--color-text-darker);
298+
}
299+
300+
.report-navigation .hamburger svg {
301+
height: 1.75rem;
302+
}
303+
287304
/* Page Filters */
288305
#page-filters {
289306
padding: 1.5rem 1rem;

templates/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
</div>
103103

104104
<div class="col-lg-10 col-md-9 col-sm-9 col-xs-2 clearfix">
105-
<nav class="hidden-xs pull-right text-right" aria-label="Header Menu">
105+
<nav id="desktop" class="hidden-xs pull-right text-right" aria-label="Header Menu">
106106
<ul>
107107
<li>
108108
<span class="dropdown-target" aria-haspopup="true" tabindex="0" role="button" title="Reports menu">

templates/techreport/techreport.html

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,56 @@
1515
<a href="{{ url_for('index') }}">
1616
<img class="logo" src="/static/img/ha.png" width="320" height="160" alt="HTTP Archive"/>
1717
</a>
18-
{% set params = "?geo=ALL&rank=ALL" %}
19-
{% if tech_report_page.params %}
20-
{% set filterObj = tech_report_page.params %}
21-
{% set params = "?geo=" + filterObj.geo + "&rank=" + filterObj.rank %}
22-
{% endif %}
23-
<ul class="navigation-items">
24-
<li class="all-reports"><a href="/reports/"><span>All reports</span></a></li>
25-
<li>
26-
{% set ariaCurrent = "false" %}
27-
{% if active_page == "landing" %}{% set ariaCurrent = "page" %}{% endif %}
28-
<a
29-
href="/reports/techreport/landing"
30-
aria-current="{{ ariaCurrent }}"
31-
>
32-
<span>Home</span>
33-
</a>
34-
</li>
35-
<li>
36-
{% set ariaCurrent = "false" %}
37-
{% if active_page == "technology" or requested_page == "technology" %}{% set ariaCurrent = "page" %}{% endif %}
38-
<a
39-
href="/reports/techreport/tech{{ params }}&tech=ALL"
40-
aria-current="{{ ariaCurrent }}"
41-
>
42-
<span>Technologies</span>
43-
</a>
44-
</li>
45-
<li>
46-
{% set ariaCurrent = "false" %}
47-
{% if active_page == "category" %}{% set ariaCurrent = "page" %}{% endif %}
48-
<a
49-
href="/reports/techreport/category{{ params }}&category=CMS"
50-
aria-current="{{ ariaCurrent }}"
51-
>
52-
<span>Categories</span>
53-
</a>
54-
</li>
55-
</ul>
18+
<div class="hidden-xs">
19+
{% set params = "?geo=ALL&rank=ALL" %}
20+
{% if tech_report_page.params %}
21+
{% set filterObj = tech_report_page.params %}
22+
{% set params = "?geo=" + filterObj.geo + "&rank=" + filterObj.rank %}
23+
{% endif %}
24+
<ul id="desktop" class="navigation-items">
25+
<li class="all-reports"><a href="/reports/"><span>All reports</span></a></li>
26+
<li>
27+
{% set ariaCurrent = "false" %}
28+
{% if active_page == "landing" %}{% set ariaCurrent = "page" %}{% endif %}
29+
<a
30+
href="/reports/techreport/landing"
31+
aria-current="{{ ariaCurrent }}"
32+
>
33+
<span>Home</span>
34+
</a>
35+
</li>
36+
<li>
37+
{% set ariaCurrent = "false" %}
38+
{% if active_page == "technology" or requested_page == "technology" %}{% set ariaCurrent = "page" %}{% endif %}
39+
<a
40+
href="/reports/techreport/tech{{ params }}&tech=ALL"
41+
aria-current="{{ ariaCurrent }}"
42+
>
43+
<span>Technologies</span>
44+
</a>
45+
</li>
46+
<li>
47+
{% set ariaCurrent = "false" %}
48+
{% if active_page == "category" %}{% set ariaCurrent = "page" %}{% endif %}
49+
<a
50+
href="/reports/techreport/category{{ params }}&category=CMS"
51+
aria-current="{{ ariaCurrent }}"
52+
>
53+
<span>Categories</span>
54+
</a>
55+
</li>
56+
</ul>
57+
</div>
58+
<div class="visible-xs">
59+
<button class="hamburger">
60+
<span class="sr-only">Menu</span>
61+
<svg aria-hidden="true" version="1.1" viewBox="0 0 32 32" height="32px" width="32px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
62+
<path d="M4,10h24c1.104,0,2-0.896,2-2s-0.896-2-2-2H4C2.896,6,2,6.896,2,8S2.896,10,4,10z M28,14H4c-1.104,0-2,0.896-2,2 s0.896,2,2,2h24c1.104,0,2-0.896,2-2S29.104,14,28,14z M28,22H4c-1.104,0-2,0.896-2,2s0.896,2,2,2h24c1.104,0,2-0.896,2-2 S29.104,22,28,22z"/>
63+
</svg>
64+
</button>
65+
</div>
5666
</nav>
67+
<nav id="mobile" class="hidden-sm hidden-md hidden-lg" aria-label="Mobile Menu"></nav>
5768
{% endblock %}
5869

5970
{% block main %}

0 commit comments

Comments
 (0)