Skip to content

Commit

Permalink
make menu responsive on mobile + track aria-expanded status
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahfossheim committed Jan 16, 2025
1 parent d861090 commit 3a125ad
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 44 deletions.
2 changes: 0 additions & 2 deletions src/js/components/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ class Filters {

/* Duplicate the technology dropdowns */
addTechnologySelector(event) {
console.log('add tech selector');

event.preventDefault();

const selectorTemplate = document.getElementById('tech-selector').content.cloneNode(true);
Expand Down
6 changes: 4 additions & 2 deletions src/js/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const nav = document.querySelector('header nav');
const nav = document.querySelector('#desktop');
const mobileNav = document.querySelector('nav#mobile');
const hamburger = document.querySelector('header .hamburger');
const hamburger = document.querySelector('.hamburger');

if (mobileNav) {
if (hamburger) {
hamburger.addEventListener('click', (e) => {
const expanded = hamburger.getAttribute('aria-expanded');
mobileNav.classList.toggle('active');
hamburger.ariaExpanded = expanded === 'true' ? 'false' : 'true';
});
}

Expand Down
19 changes: 18 additions & 1 deletion static/css/techreport/techreport.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
/* ------------------------- */

/* Page header and footer */
body > :is(header, footer) {
body footer {
background-color: var(--color-card-background);
}

Expand Down Expand Up @@ -284,6 +284,23 @@ nav {
transform: translateY(-50%);
}

.report-navigation .hamburger {
padding: 1rem;
color: var(--color-text-lighter);
}

.report-navigation .hamburger:is(:hover, :focus-visible) {
color: var(--color-text-darker);
}

.report-navigation .hamburger:focus-visible {
outline: 1px solid var(--color-text-darker);
}

.report-navigation .hamburger svg {
height: 1.75rem;
}

/* Page Filters */
#page-filters {
padding: 1.5rem 1rem;
Expand Down
2 changes: 1 addition & 1 deletion templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
</div>

<div class="col-lg-10 col-md-9 col-sm-9 col-xs-2 clearfix">
<nav class="hidden-xs pull-right text-right" aria-label="Header Menu">
<nav id="desktop" class="hidden-xs pull-right text-right" aria-label="Header Menu">
<ul>
<li>
<span class="dropdown-target" aria-haspopup="true" tabindex="0" role="button" title="Reports menu">
Expand Down
87 changes: 49 additions & 38 deletions templates/techreport/techreport.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,56 @@
<a href="{{ url_for('index') }}">
<img class="logo" src="/static/img/ha.png" width="320" height="160" alt="HTTP Archive"/>
</a>
{% set params = "?geo=ALL&rank=ALL" %}
{% if tech_report_page.params %}
{% set filterObj = tech_report_page.params %}
{% set params = "?geo=" + filterObj.geo + "&rank=" + filterObj.rank %}
{% endif %}
<ul class="navigation-items">
<li class="all-reports"><a href="/reports/"><span>All reports</span></a></li>
<li>
{% set ariaCurrent = "false" %}
{% if active_page == "landing" %}{% set ariaCurrent = "page" %}{% endif %}
<a
href="/reports/techreport/landing"
aria-current="{{ ariaCurrent }}"
>
<span>Home</span>
</a>
</li>
<li>
{% set ariaCurrent = "false" %}
{% if active_page == "technology" or requested_page == "technology" %}{% set ariaCurrent = "page" %}{% endif %}
<a
href="/reports/techreport/tech{{ params }}&tech=ALL"
aria-current="{{ ariaCurrent }}"
>
<span>Technologies</span>
</a>
</li>
<li>
{% set ariaCurrent = "false" %}
{% if active_page == "category" %}{% set ariaCurrent = "page" %}{% endif %}
<a
href="/reports/techreport/category{{ params }}&category=CMS"
aria-current="{{ ariaCurrent }}"
>
<span>Categories</span>
</a>
</li>
</ul>
<div class="hidden-xs">
{% set params = "?geo=ALL&rank=ALL" %}
{% if tech_report_page.params %}
{% set filterObj = tech_report_page.params %}
{% set params = "?geo=" + filterObj.geo + "&rank=" + filterObj.rank %}
{% endif %}
<ul id="desktop" class="navigation-items">
<li class="all-reports"><a href="/reports/"><span>All reports</span></a></li>
<li>
{% set ariaCurrent = "false" %}
{% if active_page == "landing" %}{% set ariaCurrent = "page" %}{% endif %}
<a
href="/reports/techreport/landing"
aria-current="{{ ariaCurrent }}"
>
<span>Home</span>
</a>
</li>
<li>
{% set ariaCurrent = "false" %}
{% if active_page == "technology" or requested_page == "technology" %}{% set ariaCurrent = "page" %}{% endif %}
<a
href="/reports/techreport/tech{{ params }}&tech=ALL"
aria-current="{{ ariaCurrent }}"
>
<span>Technologies</span>
</a>
</li>
<li>
{% set ariaCurrent = "false" %}
{% if active_page == "category" %}{% set ariaCurrent = "page" %}{% endif %}
<a
href="/reports/techreport/category{{ params }}&category=CMS"
aria-current="{{ ariaCurrent }}"
>
<span>Categories</span>
</a>
</li>
</ul>
</div>
<div class="visible-xs">
<button class="hamburger">
<span class="sr-only">Menu</span>
<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">
<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"/>
</svg>
</button>
</div>
</nav>
<nav id="mobile" class="hidden-sm hidden-md hidden-lg" aria-label="Mobile Menu"></nav>
{% endblock %}

{% block main %}
Expand Down

0 comments on commit 3a125ad

Please sign in to comment.