Skip to content

Commit

Permalink
SOEOPSFY24-350 | add keyboard and voiceover accessibility to timeline (
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahongsf committed Dec 18, 2024
1 parent 682de55 commit d3af5a1
Show file tree
Hide file tree
Showing 40 changed files with 84 additions and 63 deletions.
27 changes: 24 additions & 3 deletions components/Timeline/TimelineOverview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useState, useEffect } from "react";
import { useState, useEffect, useRef } from "react";
import { Container } from "@/components/Container";
import { TimelineItem } from "./TimelineItem";
import { TimelineDetails } from "./TimelineDetails";
Expand All @@ -20,11 +20,22 @@ const TimelineOverview = ({ timelineData }: TimelineProps) => {
const [isMounted, setIsMounted] = useState(false);
const [expandedUuid, setExpandedUuid] = useState<string | null>(null);

// Reference to the TimelineItems and TimelineDetails for accessibility focus management
const itemRefs = useRef<{ [key: string]: HTMLButtonElement | null }>({});
const detailsRef = useRef<HTMLDivElement>(null);

// Ensure the component is mounted before running media queries
useEffect(() => {
setIsMounted(true);
}, []);

// Focus on the TimelineDetails when it is expanded
useEffect(() => {
if (expandedUuid && detailsRef.current) {
detailsRef.current.focus();
}
}, [expandedUuid]);

// Define breakpoints using useMediaQuery hook
const isLg = useMediaQuery("(min-width: 1024px)");
const isMd = useMediaQuery("(min-width: 768px)");
Expand Down Expand Up @@ -72,14 +83,16 @@ const TimelineOverview = ({ timelineData }: TimelineProps) => {
<AnimateInView key={item.uuid}>
<TimelineItem
{...item}
id={`tab-${item.uuid}`}
role="tab"
id={item.uuid}
aria-expanded={expandedUuid === item.uuid}
aria-controls={`drawer-${item.uuid}`}
isExpanded={expandedUuid === item.uuid}
size={size}
trapezoid={trapezoid}
onClick={() => handleToggle(item.uuid)}
ref={(el) => {
itemRefs.current[item.uuid] = el;
}}
/>
</AnimateInView>
);
Expand All @@ -96,12 +109,20 @@ const TimelineOverview = ({ timelineData }: TimelineProps) => {
animate={{ opacity: 1, height: "auto" }}
exit={{ opacity: 0, height: 0 }}
transition={{ duration: 0.5 }}
ref={detailsRef}
tabIndex={-1}
>
<TimelineDetails
{...timelineData.find(
(item) => item.uuid === expandedUuid,
)!}
onClose={() => {
if (expandedUuid) {
const itemButton = itemRefs.current[expandedUuid];
if (itemButton) {
itemButton.focus();
}
}
setExpandedUuid(null);
}}
/>
Expand Down
2 changes: 1 addition & 1 deletion out/404.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions out/_next/static/chunks/404-3f89025a9bf572ee.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d3af5a1

Please sign in to comment.