From 682de55f0d3b62fc5b2c8a7ef850ad747015275d Mon Sep 17 00:00:00 2001 From: Rebecca Hong <34019925+rebeccahongsf@users.noreply.github.com> Date: Wed, 18 Dec 2024 13:56:05 -0800 Subject: [PATCH] SOEOPSFY24-350 | tweak timeline for accessibility (#11) * SOEOPSFY24-350 | tweak timeline for accessibility * save --- components/Timeline/TimelineOverview.tsx | 99 +++++------------------- 1 file changed, 18 insertions(+), 81 deletions(-) diff --git a/components/Timeline/TimelineOverview.tsx b/components/Timeline/TimelineOverview.tsx index 4974754..8307e5d 100644 --- a/components/Timeline/TimelineOverview.tsx +++ b/components/Timeline/TimelineOverview.tsx @@ -9,6 +9,7 @@ import { motion, AnimatePresence } from "framer-motion"; import { useMediaQuery } from "usehooks-ts"; import { TimelineItem as TimelineItemData } from "@/utilities/loadTimelineData"; import { ClipLoader } from "react-spinners"; +import { AnimateInView } from "../Animate"; type TimelineProps = { timelineData: TimelineItemData[]; @@ -18,8 +19,6 @@ type TimelineProps = { const TimelineOverview = ({ timelineData }: TimelineProps) => { const [isMounted, setIsMounted] = useState(false); const [expandedUuid, setExpandedUuid] = useState(null); - const [expandedRowIndex, setExpandedRowIndex] = useState(null); - const [focusedTabIndex, setFocusedTabIndex] = useState(0); // Ensure the component is mounted before running media queries useEffect(() => { @@ -41,55 +40,8 @@ const TimelineOverview = ({ timelineData }: TimelineProps) => { return acc; }, []); - const handleToggle = (uuid: string, rowIndex: number) => { - setExpandedUuid((currentUuid) => { - const isSameRow = rowIndex === expandedRowIndex; - const isSameItem = uuid === currentUuid; - - if (isSameRow) return isSameItem ? null : uuid; - - setExpandedRowIndex(rowIndex); - return uuid; - }); - }; - - const handleKeyDown = ( - event: React.KeyboardEvent, - itemUuid: string, - rowIndex: number, - ) => { - switch (event.key) { - case "Enter": - case " ": - event.preventDefault(); - handleToggle(itemUuid, rowIndex); - break; - case "ArrowRight": - case "ArrowDown": - event.preventDefault(); - setFocusedTabIndex( - (prevIndex) => (prevIndex + 1) % timelineData.length, - ); - break; - case "ArrowLeft": - case "ArrowUp": - event.preventDefault(); - setFocusedTabIndex( - (prevIndex) => - (prevIndex - 1 + timelineData.length) % timelineData.length, - ); - break; - case "Home": - event.preventDefault(); - setFocusedTabIndex(0); - break; - case "End": - event.preventDefault(); - setFocusedTabIndex(timelineData.length - 1); - break; - default: - break; - } + const handleToggle = (uuid: string) => { + setExpandedUuid((currentUuid) => (currentUuid === uuid ? null : uuid)); }; if (!isMounted) { @@ -110,49 +62,35 @@ const TimelineOverview = ({ timelineData }: TimelineProps) => { key={`row-${rowIndex}`} className="odd:children:children:even:rs-pt-6 even:children:children:odd:rs-pt-6" > -
+
{row.map((item, itemIndex) => { const sizePattern: SizeType[] = ["large", "medium", "small"]; const size = sizePattern[itemIndex % sizePattern.length]; const trapezoid = itemIndex % 2 === 0 ? "left" : "right"; - const globalIndex = rowIndex * itemsPerRow + itemIndex; return ( - handleToggle(item.uuid, rowIndex)} - tabIndex={focusedTabIndex === globalIndex ? 0 : -1} - onKeyDown={(e) => handleKeyDown(e, item.uuid, rowIndex)} - ref={(el) => { - if (focusedTabIndex === globalIndex) { - el?.focus(); - } - }} - /> + + handleToggle(item.uuid)} + /> + ); })}
{expandedUuid && - expandedRowIndex === rowIndex && row.some((item) => item.uuid === expandedUuid) && ( { )!} onClose={() => { setExpandedUuid(null); - setExpandedRowIndex(null); }} />