-
Notifications
You must be signed in to change notification settings - Fork 9
Add SkipNav story and tests #473
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
flacoman91
wants to merge
3
commits into
main
Choose a base branch
from
rad-skip-nav
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import type { Meta, StoryObj } from '@storybook/react'; | ||
| import { SkipNav } from '~/src/index'; | ||
|
|
||
| const meta: Meta<typeof SkipNav> = { | ||
| title: 'Components (Draft)/Skip Navigation', | ||
| tags: ['autodocs'], | ||
| component: SkipNav, | ||
| argTypes: {} | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const Default: Story = { | ||
| render: properties => <SkipNav {...properties} />, | ||
| args: { | ||
| href: '#main' | ||
| } | ||
| }; |
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,21 @@ | ||
| import '@testing-library/jest-dom'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import SkipNav from './SkipNav'; | ||
|
|
||
| describe('<SkipNav />', () => { | ||
| it('renders the default link', () => { | ||
| render(<SkipNav />); | ||
| const link = screen.getByRole('link', { name: /skip to main content/i }); | ||
| expect(link).toHaveAttribute('href', '#main'); | ||
| expect(link).toHaveClass('skip-nav__link'); | ||
| }); | ||
|
|
||
| it('receives focus when tabbing', async () => { | ||
| const user = userEvent.setup(); | ||
| render(<SkipNav />); | ||
| await user.tab(); | ||
| const link = screen.getByRole('link', { name: /skip to main content/i }); | ||
| expect(link).toHaveFocus(); | ||
| }); | ||
| }); |
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 |
|---|---|---|
| @@ -1,15 +1,29 @@ | ||
| import type { JSXElement } from '../../types/jsxElement'; | ||
| import './SkipNav.scss'; | ||
| import { Link } from '~/src'; | ||
|
|
||
| export interface SkipNavProperties { | ||
| href?: string; | ||
| } | ||
|
|
||
| /** | ||
| * A SkipNav (skip navigation) link is an accessibility feature, usually hidden | ||
| * until focused, placed at the top of a webpage to allow keyboard and screen | ||
| * reader users to bypass repetitive navigation menus and jump directly to the | ||
| * main content. It acts as an anchor link, enhancing user experience and | ||
| * efficiency. | ||
| */ | ||
| export default function SkipNav({ | ||
| href = '#main', | ||
| text = 'Skip to main content' | ||
| }): JSXElement { | ||
| href = '#main' | ||
| }: SkipNavProperties): JSXElement { | ||
| return ( | ||
| <div className='skip-nav'> | ||
| <a className='skip-nav__link a-btn' href={href}> | ||
| {text} | ||
| </a> | ||
| <Link | ||
| href={href} | ||
| label={'Skip to main content'} | ||
| className={'skip-nav__link'} | ||
| asButton | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
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
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.
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.
i tried to implement this skipnav button in CE and noticed some issues and was unable to use it.
GHE/ConsumerResponse/explorer-app/blob/main/frontend-react/src/components/Common/Buttons/SkipNavButton/SkipNavButton.js
When we specify an anchor tag, clicking the button forces a reload of the page.
In the button in CE we do this for the onClick handler:
This way users won't see a reload, and you can specify where the page should scroll to.
I think if we just specify the ID or tag to scroll to, that would solve the issue that @anselmbradford identified where
skip tocan be used in multiple places on the page.