In brief, I'd like to know what the right way design a mobile navigation toggle that when clicked shows the menu but simultaneously hides the content.
I know normally you would have something like this:
<body>
<button type="button" aria-expanded="false" aria-controls="main-nav">I'm collapsed</button>
<nav id="main-nav">...</nav>
</button>
<body class="mobile-nav-open">
<button type="button" aria-expanded="true" aria-controls="main-nav">I'm expanded</button>
<nav id="main-nav">...</nav>
</button>
#main-nav { display: none; }
.mobile-nav-open #main-nav { display: block }
However, some of peculiarities of this design I've been given require that when mobile nav is open, the rest of the content is hidden. (ie: display: none
)
Let me illustrate what I'm talking about:
This is the desktop layout of my site.
Desktop Layout (sorry can't show inline images because I'm a new user)
Now here's mobile's "nav collapsed" and "nav expanded" states, respectively.
Mobile Collapsed (sorry can't show inline images because I'm a new user)
Mobile Expanded (sorry can't show inline images because I'm a new user)
now I could do some css like this,
.main-nav,
.sidebar-nav,
.footer-nav {
display: none;
}
.mobile-nav-open .content,
.mobile-nav-open .footer {
display: none;
}
.mobile-nav-open .main-nav,
.mobile-nav-open .sidebar-nav,
.mobile-nav-open .footer-nav {
display: block;
}
And pass additional ids to aria-controls
<button type="button" aria-expanded="true" aria-controls="main-nav sidebar-nav footer-nav">I'm expanded</button>
Now that's fine but it doesn't account for the "collapsed"/hidden state of Content and Footer. Adding them to aria-controls
would be incorrect because their "collapsed" state is the inverse of the navigation's "collapsed" state. In some ways this seems kind of like tabbed content where what you display is mutually exclusive, yet that doesn't feel right. It's a single button doing the toggline, not an item for each "tab" and the content being displayed are not related/grouped in the way you usually see in a tab view.
I've searched MDN looking at tablist, listbox, etc but didn't find anything that really fit.
I'd appreciate any insight as to the proper WCAG way to achieve this would be. I suspect because there's not a clear way to describe this in terms of aria attrs that this is a accessibility anti-pattern.. but it's the design I was given :shurg: