From fed8c2e556a0553643144c97069adb97416bce64 Mon Sep 17 00:00:00 2001 From: Amberroseweeks Date: Wed, 9 Oct 2024 14:44:15 -0400 Subject: [PATCH] adding focus and keyboard accessibility to the cookie consent buttons --- src/components/CookieConsentBanner.tsx | 31 ++++++++++++++++++++++---- src/components/Footer.tsx | 13 ++++++----- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/components/CookieConsentBanner.tsx b/src/components/CookieConsentBanner.tsx index 767d1676..b620a852 100644 --- a/src/components/CookieConsentBanner.tsx +++ b/src/components/CookieConsentBanner.tsx @@ -3,12 +3,15 @@ import { ThemeButton } from "./ThemeButton"; import { Check, X } from "@phosphor-icons/react"; import { useCookieContext } from "@/context/CookieContext"; -import { useEffect, useState } from "react"; +import { useEffect, useState, useRef } from "react"; const CookieConsentBanner = () => { const { shouldShowBanner, setShouldAllowCookies, setShouldShowBanner } = useCookieContext(); + const bannerRef = useRef(null); + const inputRef = useRef(null); + const [isClientSide, setIsClientSide] = useState(false); useEffect(() => { @@ -21,10 +24,24 @@ const CookieConsentBanner = () => { setShouldShowBanner(false); }; + useEffect(() => { + // Focus on the banner when it becomes visible + if (shouldShowBanner && bannerRef.current) { + // Use setTimeout to ensure focus is applied after DOM updates + setTimeout(() => { + bannerRef.current?.focus(); + }, 0); + } + }, [shouldShowBanner]); // Trigger focus when shouldShowBanner changes + if (!isClientSide) return null; return (
{ }`} >
-
Can we store cookies to your browser?
+
- This provides you a nice experience preserving your filtering, your - position on the map and your property saved list. +

+ This provides you a nice experience preserving your filtering, your + position on the map and your property saved list. +

} @@ -49,6 +71,7 @@ const CookieConsentBanner = () => { /> } diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index 9a0ab52c..ba2fa799 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -2,6 +2,7 @@ import { useCookieContext } from "@/context/CookieContext"; import CookieConsentBanner from "./CookieConsentBanner"; +import { ThemeButton } from "./ThemeButton"; import Link from "next/link"; const Footer = () => { @@ -25,12 +26,12 @@ const Footer = () => {
  • - - Cookie Settings - +