Skip to content

Commit

Permalink
add skip nav link
Browse files Browse the repository at this point in the history
  • Loading branch information
jackiequach committed Feb 22, 2024
1 parent 640452e commit cc9d2b8
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cypress/integration/multi-pdf/navigations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Multi PDF navigation', () => {
it('should navigate forward and backwards with page buttons', () => {
cy.findByText('Anthropology without Informants').should('be.visible');
cy.findByRole('button', { name: 'Next Page' }).click();
cy.get('#iframe-wrapper')
cy.get('#mainContent')
.find('div[class="react-pdf__Page__textContent"]')
.children()
.should('have.length', 0);
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Cypress.Commands.add(
},
});
cy.wait('@pdf', { timeout: 50000 });
cy.get('#iframe-wrapper')
cy.get('#mainContent')
.find('div[class="react-pdf__Page__textContent"]', { timeout: 10000 })
.should('have.attr', 'style');
}
Expand Down
1 change: 0 additions & 1 deletion cypress/support/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export const IFRAME_SELECTOR = '#html-reader-iframe';
export const SCALE_STEP = 0.1;
5 changes: 2 additions & 3 deletions src/HtmlReader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import LoadingSkeleton from '../ui/LoadingSkeleton';
import {
DEFAULT_HEIGHT,
DEFAULT_SHOULD_GROW_WHEN_SCROLLING,
MAIN_CONTENT_ID,
} from '../constants';
import {
fetchAsTxt,
Expand All @@ -28,8 +29,6 @@ import useUpdateCSS from './useUpdateCSS';
import useIframeLinkClick from './useIframeLinkClick';
import useUpdateLocalStorage from '../utils/localstorage';

export const IFRAME_ID_SELECTOR = 'html-reader-iframe';

export default function useHtmlReader(args: ReaderArguments): ReaderReturn {
const {
webpubManifestUrl,
Expand Down Expand Up @@ -254,7 +253,7 @@ export default function useHtmlReader(args: ReaderArguments): ReaderReturn {
content: (
<>
<iframe
id={IFRAME_ID_SELECTOR}
id={MAIN_CONTENT_ID}
onLoad={() => dispatch({ type: 'IFRAME_LOADED' })}
ref={setIframe}
// as="iframe"
Expand Down
11 changes: 3 additions & 8 deletions src/PdfReader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@ import ChakraPage from './ChakraPage';
import ScrollPage from './ScrollPage';
// Required CSS in order for links to be clickable in PDFs
import './pdf.css';
import { HEADER_HEIGHT, FOOTER_HEIGHT } from '../constants';
import { HEADER_HEIGHT, FOOTER_HEIGHT, MAIN_CONTENT_ID } from '../constants';
import {
DEFAULT_HEIGHT,
DEFAULT_SHOULD_GROW_WHEN_SCROLLING,
} from '../constants';
import LoadingSkeleton from '../ui/LoadingSkeleton';
import {
getResourceUrl,
IFRAME_WRAPPER_ID,
loadResource,
SCALE_STEP,
} from './lib';
import { getResourceUrl, loadResource, SCALE_STEP } from './lib';
import { makePdfReducer } from './reducer';

/**
Expand Down Expand Up @@ -322,7 +317,7 @@ export default function usePdfReader(args: ReaderArguments): ReaderReturn {
justifyContent="center"
alignItems="center"
tabIndex={-1}
id={IFRAME_WRAPPER_ID}
id={MAIN_CONTENT_ID}
ref={containerRef}
height={finalHeight}
>
Expand Down
1 change: 0 additions & 1 deletion src/PdfReader/lib.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { WebpubManifest } from '../types';
import { ReadiumLink } from '../WebpubManifestTypes/ReadiumLink';

export const IFRAME_WRAPPER_ID = 'iframe-wrapper';
export const SCALE_STEP = 0.1;
export const START_QUERY = 'start';

Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ export const FONT_DETAILS = {
// local storage keys
export const LOCAL_STORAGE_SETTINGS_KEY = 'web-reader-settings';
export const LOCAL_STORAGE_LOCATIONS_KEY = 'web-reader-locations';

export const MAIN_CONTENT_ID = 'mainContent';
2 changes: 2 additions & 0 deletions src/ui/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SettingsCard from './SettingsButton';
import TableOfContent from './TableOfContent';
import useColorModeValue from '../ui/hooks/useColorModeValue';
import useFullscreen from './hooks/useFullScreen';
import SkipNavigation from './SkipNavigation';

export const DefaultHeaderLeft = (): React.ReactElement => {
const linkColor = useColorModeValue('gray.700', 'gray.100', 'gray.700');
Expand Down Expand Up @@ -69,6 +70,7 @@ export default function Header(

return (
<HeaderWrapper bg={mainBgColor}>
<SkipNavigation />
{headerLeft ?? <DefaultHeaderLeft />}
<HStack ml="auto" spacing={0}>
<TableOfContent
Expand Down
21 changes: 21 additions & 0 deletions src/ui/SkipNavigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Box, Link, useStyleConfig } from '@chakra-ui/react';
import React from 'react';

/**
* SkipNavigation is a component that is used to provide a link
* used to skip to the main content of the page using the `#mainContent`
* id. This link is visually hidden but can be read by screenreaders.
*/
export const SkipNavigation = (): React.ReactElement => {
const styles = useStyleConfig('SkipNavigation');

return (
<Box as="nav" aria-label="Skip to Main Content" __css={styles}>
<Link href="#mainContent" textDecoration="none">
Skip to Main Content
</Link>
</Box>
);
};

export default SkipNavigation;
25 changes: 25 additions & 0 deletions src/ui/theme/components/skipNavigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const SkipNavigation = {
baseStyle: {
// Don't display links by default...
a: {
backgroundColor: 'ui.white',
height: '1px',
left: '-10000px',
overflow: 'hidden',
position: 'absolute',
top: 'auto',
width: '1px',
// Only display when the user focuses on the links.
_focus: {
height: 'auto',
left: '2',
paddingX: '2',
paddingY: '1',
top: '2',
width: 'auto',
},
},
},
};

export default SkipNavigation;
2 changes: 2 additions & 0 deletions src/ui/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { extendTheme } from '@chakra-ui/react';
import Alert from './components/alert';
import Text from './components/text';
import SkipNavigation from './components/skipNavigation';
import colors from './foundations/colors';
import typography from './foundations/typography';
import nyplTheme from '../nypl-base-theme';
Expand Down Expand Up @@ -31,6 +32,7 @@ export function getTheme(colorMode: ColorMode = 'day'): Dict<unknown> {
Button: getButtonStyle(getColor(colorMode)),
Text,
Alert,
SkipNavigation,
},
currentColorMode: colorMode,
},
Expand Down

0 comments on commit cc9d2b8

Please sign in to comment.