DisplayReact
A link that stays out of sight until the keyboard reaches it, and moves the focus past the navigation to the main content when it is activated.
Rendered by React 19.3.1
Installation
npm i @hamur/reactNot on npm yet. The package goes out under the chosen name.
Anatomy
Import the component and assemble its parts:
<SkipNavLink />Examples
Sticky
The same link in a scrolling frame with a sticky header; scroll-margin-top on the target keeps its heading below the header after the jump.
API reference
1 props across 1 parts, in React syntax. className, style, render are listed once, under Shared props.
SkipNavLinkSkipNavLink
A link hidden until it is focused that moves the focus to the main content when activated. Renders an <a>.
| Prop | Type | Default |
|---|---|---|
targetIdThe id of the element that receives focus when it is activated. | string | 'main-content' |
Shared props
Every part that renders an element takes these.
| Prop | Type |
|---|---|
classNameCSS class applied to the element, or a function that
returns a class based on the component's state. | string | ((state: State) => string | undefined) |
styleStyle applied to the element, or a function that
returns a style object based on the component's state. | React.CSSProperties | ((state: State) => React.CSSProperties | undefined) |
renderAllows you to replace the component's HTML element
with a different tag, or compose it with another component. | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, State> |
Keyboard and accessibility
Keyboard
| Keys | Does | Part |
|---|---|---|
| Tab | Reaches the link as the first stop of the page and reveals it | SkipNavLink |
| Enter | Moves the focus to the target, scrolls it to the start and leaves the URL | SkipNavLink |
Accessibility
| Part | Sets | So that |
|---|---|---|
| SkipNavLink | href, the hidden style until revealed, data-revealed while revealed; no role and no ARIA | the link is a link in the tab order that a keyboard user sees when it has focus |
Focus order
- The link is the first stop; it is the first focusable element in
body. - After Enter, the target holds the focus, and the next Tab goes to the first control inside it, not to the header again.
- A focusable control inside the target keeps its own focus ring; only a target made focusable for the jump hides it.