This is a solution to the FAQ accordion challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Note: Delete this note and update the table of contents based on what sections you keep.
Users should be able to:
- Hide/Show the answer to a question when the question is clicked
- Navigate the questions and hide/show answers using keyboard navigation alone
- View the optimal layout for the interface depending on their device's screen size
- See hover and focus states for all interactive elements on the page
- Solution URL: https://github.com/ofcljaved/faq-accordion
- Live Site URL: https://faq-accordion-ofcljaved.vercel.app/
- Semantic HTML5 markup
- CSS view-transition API
- CSS Grid
- Mobile-first workflow
- Vite - Development library
- TypeScript - TypeScript
- Kevin Powell - Kevin Powell's Youtube
By doing this project I evaluated my developement skills and implemented new view transition api to animate from one view to another smoothly wihtout any hassel and involving any library. This project been a great help to implement and test my skills to it. And with the help of CSS grid it's easy to make layout without any extraa node and typescript assertions helps in error safety which is quite good.
//Browser support is not very great so have to use fallback here
if (!document.startViewTransition) {
listItem.querySelector("p")?.removeAttribute("hidden");
}
document.startViewTransition(() => {
listItem.querySelector("p")?.removeAttribute("hidden");
});
//can't gave them common view transition name otherwise everything will broke
accordionBtn.forEach((btn, idx) => {
btn.addEventListener("click", handleEvent);
let para = btn.nextElementSibling as HTMLParagraphElement;
para.style.viewTransitionName = `accord-${++idx}`;
});
::view-transition-group(root) {
animation-duration: 150ms;
}
- View Transition code of Kevin Powell - This helped me for analyzing the transition.
- Website - ofcljaved
- Frontend Mentor - @Ofcl-Javed
- Twitter - @ofcljaved