I’m not the biggest fun of large front-end frameworks for couple of reasons.
But there are times when frameworks like Foundation can be really helpful.
This time I wanted to test Foundation accordion component. For testing I created a small test plugin.
The key point about testing Foundation accordion was to avoid bloat. How would I get just the Javascript and CSS what I need for accordion?
Well you can do exactly that using custom download. Uncheck everything else and check only accordion.
From the download folder we’re going to need three files:
After that it’s up to you how you’re going to use those components in you plugin or theme.
The main reason why I wanted to test Foundation accordion was accessibility. And I’ll have to say I’m pretty impressed. There are lot’s of accessibility improvements since I last checked.
In Foundation accordion keyboard accessibility is top notch.
Only thing that confuses me is the accordion title and it’s markup. Accordion title is the element that toggles the accordion content.
<a class="accordion-title" href="#">Accordion 1</a>
I can’t change the accordion title markup to <button>
which is kind of odd. But on the other hand there are ARIA markup to help screen reader users.
I have only NVDA screen reader for testing. And I’m not a native screen reader user so I probably don’t even know how to test correctly. Anyways NVDA announced accordion items really well. Like I said before there are ARIA markup that helps screen reader users.
Only thing that bothered me was that also the plus-sign was announced with the accordion title. That comes from the CSS.
.accordion-title::before { content: '+'; position: absolute; right: 1rem; top: 50%; margin-top: -0.5rem; }
But this is minor thing and we could even use animated SVGs instead.
By default it does not. Accordion tabs stays closed if Javascript is not enabled. In my opinion all the accordion tabs should be open when Javascript is disabled or doesn’t load.
I added one line of CSS for make this work:
.js .accordion-content { display: none; }
Now accordion content is hidden only when JS is around. Here is the article how to detect Javascript and adding no-js / js
class in HTML
element.
Here you go:
I was sceptical before testing but I was actually positively surprised.
Foundation accordion does depend on jQuery but that’s a minor issue if we’re using jQuery already in our project. But I can definitely recommend Foundation accordion if you need one. To make testing more useful I should test others accessible accordions. But that’s for another day. Cheers!