Skip to content
Submitted about 11 hours ago

FAQ accordion with the WAI-ARIA button pattern, Sass and TypeScript

sass/scss, typescript
P
LVL 3
Darkmift•359
@Avi-E-Koenig
A solution to the FAQ accordion challenge

Solution retrospective


What are you most proud of, and what would you do differently next time?

Each question is an <h2> holding a <button> with aria-expanded and aria-controls, and each answer is a <section> labelled by its question, so screen-reader users can jump between questions by heading and hear "expanded" or "collapsed". The script only flips aria-expanded and the answer's hidden; the plus or minus icon follows aria-expanded in CSS, so the visuals can't drift from what assistive tech announces. A native button already turns Enter and Space into a click, so one listener covers mouse and keyboard. Positions match the Figma frames exactly at 375px and 1440px, and axe-core reports no violations.

What challenges did you encounter, and how did you overcome them?

On desktop, the mobile 24px gap between question and icon pushed "Can I use Frontend Mentor projects in my portfolio?" onto two lines; Figma's desktop rows have no fixed gap, so it is 16px from 768px up.

At 320px with the browser text size at 200%, the fixed 24px gutters, padding and gaps left about 20px for the question text. Those spaces now use min(1.5rem, 6.4vw) (still 24px at 375px) and long words can wrap.

I built this together with Claude Code as a pair programmer. I chose the stack, the button pattern over <details> and independent answers; Claude read the values from Figma, drafted the code, and ran the layout, keyboard, axe and zoom checks in Chromium, Firefox and WebKit.

What specific areas of your project would you like help with?
  1. Button vs <details>: I picked the WAI-ARIA button pattern so each question can stay an <h2>. Would you have used <details>/<summary> here, and how do you handle headings with it?
  2. Regions: each answer is a <section aria-labelledby>, which makes it a landmark region. With four answers that seemed fine, but would you drop the region role to keep the landmark list short?
Code
Loading...

Please log in to post a comment

Log in

Community feedback

No feedback yet. Be the first to give feedback on Darkmift’s solution.

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord