-
Notifications
You must be signed in to change notification settings - Fork 463
♿(frontend) add skip to content button for keyboard accessibility #1624
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
Open
Ovgodd
wants to merge
6
commits into
main
Choose a base branch
from
fix/1621-a11y-skip-link
base: main
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
Show all changes
6 commits
Select commit
Hold shift + click to select a range
673b25a
✨(a11y) add skip to content button for keyboard accessibility
Ovgodd 470b4cb
✅(frontend) add e2e test for skiplink and fix broken accessibility test
Ovgodd 9dbd36e
fixup! ✨(a11y) add skip to content button for keyboard accessibility
Ovgodd 706222a
fixup! ✨(a11y) add skip to content button for keyboard accessibility
Ovgodd 1151171
fixup! ✨(a11y) add skip to content button for keyboard accessibility
Ovgodd 6dc9a6b
fixup! ✨(a11y) add skip to content button for keyboard accessibility
Ovgodd 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
63 changes: 63 additions & 0 deletions
63
src/frontend/apps/impress/src/components/SkipToContent.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { Button } from '@openfun/cunningham-react'; | ||
| import { useRouter } from 'next/router'; | ||
| import { useEffect, useState } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| import { MAIN_LAYOUT_ID } from '@/layouts/conf'; | ||
|
|
||
| export const SkipToContent = () => { | ||
| const { t } = useTranslation(); | ||
| const router = useRouter(); | ||
| const [isVisible, setIsVisible] = useState(false); | ||
|
|
||
| // Reset focus after route change so first TAB goes to skip link | ||
| useEffect(() => { | ||
| const handleRouteChange = () => { | ||
| (document.activeElement as HTMLElement)?.blur(); | ||
|
|
||
| document.body.setAttribute('tabindex', '-1'); | ||
| document.body.focus({ preventScroll: true }); | ||
|
|
||
| setTimeout(() => { | ||
| document.body.removeAttribute('tabindex'); | ||
| }, 100); | ||
| }; | ||
|
|
||
| router.events.on('routeChangeComplete', handleRouteChange); | ||
| return () => { | ||
| router.events.off('routeChangeComplete', handleRouteChange); | ||
| }; | ||
| }, [router.events]); | ||
|
|
||
| const handleClick = (e: React.MouseEvent) => { | ||
| e.preventDefault(); | ||
| const mainContent = document.getElementById(MAIN_LAYOUT_ID); | ||
| if (mainContent) { | ||
| mainContent.focus(); | ||
| mainContent.scrollIntoView({ behavior: 'smooth', block: 'start' }); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Button | ||
| href={`#${MAIN_LAYOUT_ID}`} | ||
| onClick={handleClick} | ||
| color="tertiary" | ||
| onFocus={() => setIsVisible(true)} | ||
| onBlur={() => setIsVisible(false)} | ||
| style={{ | ||
| opacity: isVisible ? 1 : 0, | ||
| pointerEvents: isVisible ? 'auto' : 'none', | ||
| transition: 'opacity 0.3s ease-in-out', | ||
| position: 'fixed', | ||
| top: 'var(--c--theme--spacings--2xs)', | ||
| // padding header + logo(32px) + gap(3xs≈4px) + text "Docs"(≈70px) + 12px | ||
| left: 'calc(var(--c--theme--spacings--base) + 32px + var(--c--theme--spacings--3xs) + 70px + 12px)', | ||
| zIndex: 9999, | ||
| whiteSpace: 'nowrap', | ||
| }} | ||
| > | ||
| {t('Go to content')} | ||
| </Button> | ||
| ); | ||
| }; |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.