-
Notifications
You must be signed in to change notification settings - Fork 60
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
adding focus and keyboard accessibility to the cookie consent buttons #945
Open
Amberroseweeks
wants to merge
1
commit into
CodeForPhilly:staging
Choose a base branch
from
Amberroseweeks:amberroseweeks-859-cookie-consent-keyboard-a11y
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<HTMLDivElement>(null); | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
const [isClientSide, setIsClientSide] = useState(false); | ||
|
||
useEffect(() => { | ||
|
@@ -21,34 +24,54 @@ 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 ( | ||
<div | ||
role="region" | ||
tabIndex={-1} // Make the div focusable | ||
ref={bannerRef} // Attach the ref to the banner | ||
aria-labelledby="cookie_heading" | ||
className={`${ | ||
shouldShowBanner | ||
? "md:flex fixed inset-x-0 bottom-0 z-20 justify-between bg-blue-200 p-4 sm:p-6" | ||
: "hidden" | ||
}`} | ||
> | ||
<div> | ||
<div className="heading-md">Can we store cookies to your browser?</div> | ||
<h2 className="heading-md" id="cookie_heading"> | ||
Can we store cookies to your browser? | ||
</h2> | ||
<div className="body-sm"> | ||
This provides you a nice experience preserving your filtering, your | ||
position on the map and your property saved list. | ||
<p> | ||
This provides you a nice experience preserving your filtering, your | ||
position on the map and your property saved list. | ||
</p> | ||
</div> | ||
</div> | ||
|
||
<div className="flex justify-end gap-2 pt-4 sm:pt-0"> | ||
<div className="flex flex-none items-center gap-x-2"> | ||
<ThemeButton | ||
tabIndex={1} | ||
color="tertiary" | ||
label="Decline" | ||
startContent={<X />} | ||
onPress={() => onClickButton(false)} | ||
/> | ||
|
||
<ThemeButton | ||
tabIndex={2} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is one of those exceptions to the rule that I think is okay. |
||
color="primary" | ||
label="Accept" | ||
startContent={<Check />} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you have a couple of small conflicts that need to be resolved with main.