-
Notifications
You must be signed in to change notification settings - Fork 212
[Chakra V3 Upgrade 🎨] Create Skip Nav Components (@W-18507873@) #2757
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
Merged
adamraya
merged 9 commits into
feature/chakra-ui-upgrade-v3
from
W-18507873-create-v3-skipnav
Jul 15, 2025
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
20b7a66
init
adamraya e8a4361
Clean up styles
adamraya 7133064
PR Feedback
adamraya a7c73b8
Use zIndex value
adamraya 4f5921d
Use zIndex default skipNav value
adamraya a966353
PR Feedback
adamraya 8a5bcea
Fix copyright year
adamraya 5cf7965
Use token values instead of px
adamraya b007137
Move styles to base
adamraya 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
200 changes: 200 additions & 0 deletions
200
packages/extension-chakra-storefront/src/components/skip-nav/index.test.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,200 @@ | ||
| /* | ||
| * Copyright (c) 2023, Salesforce, Inc. | ||
| * All rights reserved. | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import React from 'react' | ||
| import {render, screen} from '@testing-library/react' | ||
| import {ChakraProvider} from '@chakra-ui/react' | ||
| import {SkipNavLink, SkipNavContent} from './index' | ||
| import system from '../../theme' | ||
|
|
||
| const TestWrapper = ({children}: {children: React.ReactNode}) => ( | ||
| <ChakraProvider value={system}>{children}</ChakraProvider> | ||
| ) | ||
|
|
||
| describe('SkipNavLink', () => { | ||
| test('renders with default props', () => { | ||
| render( | ||
|
||
| <TestWrapper> | ||
| <SkipNavLink>Skip to Content</SkipNavLink> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| const link = screen.getByRole('link', {name: 'Skip to Content'}) | ||
| expect(link).toBeInTheDocument() | ||
| expect(link).toHaveAttribute('href', '#skip-to-content') | ||
| }) | ||
|
|
||
| test('renders with custom href', () => { | ||
| render( | ||
| <TestWrapper> | ||
| <SkipNavLink href="#main-content">Skip to Main</SkipNavLink> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| const link = screen.getByRole('link', {name: 'Skip to Main'}) | ||
| expect(link).toHaveAttribute('href', '#main-content') | ||
| }) | ||
|
|
||
| test('has correct accessibility attributes', () => { | ||
| render( | ||
| <TestWrapper> | ||
| <SkipNavLink>Skip to Content</SkipNavLink> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| const link = screen.getByRole('link', {name: 'Skip to Content'}) | ||
| expect(link).toHaveAttribute('href', '#skip-to-content') | ||
| }) | ||
|
|
||
| test('has visually hidden styles by default', () => { | ||
| render( | ||
| <TestWrapper> | ||
| <SkipNavLink>Skip to Content</SkipNavLink> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| const link = screen.getByRole('link', {name: 'Skip to Content'}) | ||
|
|
||
| // The link should be focusable (no aria-hidden) but positioned off-screen | ||
| expect(link).not.toHaveAttribute('aria-hidden') | ||
| expect(link).toHaveAttribute('href', '#skip-to-content') | ||
| }) | ||
|
|
||
| test('accepts custom zIndex prop', () => { | ||
| render( | ||
| <TestWrapper> | ||
| <SkipNavLink zIndex={9999}>Skip to Content</SkipNavLink> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| const link = screen.getByRole('link', {name: 'Skip to Content'}) | ||
| expect(link).toBeInTheDocument() | ||
| // Note: Testing the actual zIndex value may require more complex setup | ||
| // as it depends on the Chakra theme system | ||
| }) | ||
| }) | ||
|
|
||
| describe('SkipNavContent', () => { | ||
| test('renders with default props', () => { | ||
| render( | ||
| <TestWrapper> | ||
| <SkipNavContent> | ||
| <div>Main content</div> | ||
| </SkipNavContent> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| const content = screen.getByText('Main content') | ||
| const container = content.parentElement | ||
|
|
||
| expect(container).toHaveAttribute('id', 'skip-to-content') | ||
| expect(container).toHaveAttribute('tabIndex', '-1') | ||
| }) | ||
|
|
||
| test('renders with custom id', () => { | ||
| render( | ||
| <TestWrapper> | ||
| <SkipNavContent id="main-content"> | ||
| <div>Main content</div> | ||
| </SkipNavContent> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| const content = screen.getByText('Main content') | ||
| const container = content.parentElement | ||
|
|
||
| expect(container).toHaveAttribute('id', 'main-content') | ||
| }) | ||
|
|
||
| test('applies custom styles', () => { | ||
| const customStyles = { | ||
| backgroundColor: 'red', | ||
| padding: '10px' | ||
| } | ||
|
|
||
| render( | ||
| <TestWrapper> | ||
| <SkipNavContent style={customStyles}> | ||
| <div>Main content</div> | ||
| </SkipNavContent> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| const content = screen.getByText('Main content') | ||
| const container = content.parentElement | ||
|
|
||
| expect(container).toHaveStyle('background-color: red') | ||
| expect(container).toHaveStyle('padding: 10px') | ||
| }) | ||
|
|
||
| test('renders children correctly', () => { | ||
| render( | ||
| <TestWrapper> | ||
| <SkipNavContent> | ||
| <h1>Main Heading</h1> | ||
| <p>Some content</p> | ||
| </SkipNavContent> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| expect(screen.getByText('Main Heading')).toBeInTheDocument() | ||
| expect(screen.getByText('Some content')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('has correct tabIndex for focus management', () => { | ||
| render( | ||
| <TestWrapper> | ||
| <SkipNavContent> | ||
| <div>Main content</div> | ||
| </SkipNavContent> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| const content = screen.getByText('Main content') | ||
| const container = content.parentElement | ||
|
|
||
| expect(container).toHaveAttribute('tabIndex', '-1') | ||
| }) | ||
| }) | ||
|
|
||
| describe('SkipNav Integration', () => { | ||
| test('link and content work together', () => { | ||
| render( | ||
| <TestWrapper> | ||
| <SkipNavLink href="#main-content">Skip to Content</SkipNavLink> | ||
| <SkipNavContent id="main-content"> | ||
| <div>Main content</div> | ||
| </SkipNavContent> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| const link = screen.getByRole('link', {name: 'Skip to Content'}) | ||
| const content = screen.getByText('Main content') | ||
| const container = content.parentElement | ||
|
|
||
| expect(link).toHaveAttribute('href', '#main-content') | ||
| expect(container).toHaveAttribute('id', 'main-content') | ||
| }) | ||
|
|
||
| test('uses default ids when not specified', () => { | ||
| render( | ||
| <TestWrapper> | ||
| <SkipNavLink>Skip to Content</SkipNavLink> | ||
| <SkipNavContent> | ||
| <div>Main content</div> | ||
| </SkipNavContent> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| const link = screen.getByRole('link', {name: 'Skip to Content'}) | ||
| const content = screen.getByText('Main content') | ||
| const container = content.parentElement | ||
|
|
||
| expect(link).toHaveAttribute('href', '#skip-to-content') | ||
| expect(container).toHaveAttribute('id', 'skip-to-content') | ||
| }) | ||
| }) | ||
87 changes: 87 additions & 0 deletions
87
packages/extension-chakra-storefront/src/components/skip-nav/index.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,87 @@ | ||
| /* | ||
| * Copyright (c) 2023, Salesforce, Inc. | ||
adamraya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * All rights reserved. | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import React from 'react' | ||
| import {Box, Link} from '@chakra-ui/react' | ||
|
|
||
| interface SkipNavLinkProps { | ||
| children: React.ReactNode | ||
| zIndex?: string | number | ||
| href?: string | ||
| } | ||
|
|
||
| interface SkipNavContentProps { | ||
| children: React.ReactNode | ||
| style?: React.CSSProperties | ||
| id?: string | ||
| } | ||
|
|
||
| /** | ||
| * SkipNavLink component provides a skip link for keyboard navigation | ||
| * with initial state screen reader accessible but visually hidden | ||
| */ | ||
| export const SkipNavLink: React.FC<SkipNavLinkProps> = ({ | ||
| children, | ||
| zIndex = 'skipLink', | ||
adamraya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| href = '#skip-to-content', | ||
| ...props | ||
| }) => { | ||
| return ( | ||
| <Link | ||
| href={href} | ||
| position="absolute" | ||
| zIndex={zIndex} | ||
| css={{ | ||
| position: 'absolute', | ||
adamraya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| left: '-10000px', | ||
| top: 'auto', | ||
| width: '1px', | ||
| height: '1px', | ||
| overflow: 'hidden', | ||
| '&:focus, &:focus-visible': { | ||
| position: 'fixed !important', | ||
| top: '6px !important', | ||
| left: '6px !important', | ||
| zIndex: 9999, | ||
| width: 'auto !important', | ||
| height: 'auto !important', | ||
| overflow: 'visible !important', | ||
| padding: '8px', | ||
| backgroundColor: 'white', | ||
| color: 'black', | ||
| textDecoration: 'none', | ||
| border: '2px solid black', | ||
| borderRadius: '4px', | ||
| fontSize: '14px', | ||
| fontWeight: 'bold', | ||
| outline: 'none', | ||
| boxShadow: '0 2px 4px rgba(0, 0, 0, 0.1)', | ||
| whiteSpace: 'nowrap' | ||
| } | ||
| }} | ||
| {...props} | ||
| > | ||
| {children} | ||
| </Link> | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * SkipNavContent component provides the target content area for skip navigation | ||
| */ | ||
| export const SkipNavContent: React.FC<SkipNavContentProps> = ({ | ||
| children, | ||
| style, | ||
| id = 'skip-to-content', | ||
| ...props | ||
| }) => { | ||
| return ( | ||
| <Box id={id} style={style} tabIndex={-1} {...props}> | ||
adamraya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {children} | ||
| </Box> | ||
| ) | ||
| } | ||
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.