Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Improve accessibility for the accordion component #67

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/Home/About.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const About = () => {
</li>
))}
<li className="flex flex-row items-center justify-start space-x-3 mt-5 px-8">
{aboutSocialLinks.map((element) => (
<a
{aboutSocialLinks.map((element, index) => (
<a key={index}
href={element.href}
target="_blank"
className="text-sm uppercase text-white rounded font-bold hover:opacity-80"
Expand Down
17 changes: 14 additions & 3 deletions src/components/Home/AccordionElement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const AccordionElement = ({ accordion, onToggle }) => {
onToggle(accordion.id);
}

const handleKeyDown = (event) => {
if (event.key === 'Enter' || event.key === ' ') {
toggleAcc();
event.preventDefault();
}
};

useEffect(() => {
if (contentHeight.current) {
contentHeight.current.style.maxHeight = accordion.open
Expand All @@ -21,9 +28,13 @@ const AccordionElement = ({ accordion, onToggle }) => {
<div className="flex flex-col space-x-1 items-start justify-between p-2 w-[300] md:w-[550px] bg-[#161616] rounded">
<div
onClick={toggleAcc}
className={`flex flex-row items-center p-1 justify-between w-full text-md min-w-[300px] md:min-w-[550px] h-12 cursor-pointer px-4 py-1 ${
accordion.open ? "font-bold" : ""
}`}
onKeyDown={handleKeyDown}
role="button"
tabIndex={0}
aria-expanded={accordion.open}
aria-controls={`accordion-content-${accordion.id}`}
className={`flex flex-row items-center p-1 justify-between w-full text-md min-w-[300px] md:min-w-[550px] h-12 cursor-pointer px-4 py-1 ${accordion.open ? "font-bold" : ""
}`}
>
<p className="text-lg cursor-pointer text-white">
{accordion.question}
Expand Down