Overview
In Page Navigation is a navigation component that helps users navigate between different sections of content on the same page. It’s commonly used for anchor links that scroll to different sections or for client-side routing within a single page application. The component supports both horizontal and vertical orientations, multiple visual variants, and includes automatic scroll management for overflowing navigation items.Installation
Usage
Variants
Default
The default variant displays navigation items with a bottom border.Full Width
Full width variant distributes items evenly across the container width.Inverse
Use the inverse variant for dark backgrounds.Inverse Full Width
Vertical Orientation
With Titles
Use thetitle prop to provide accessible tooltips, especially when text might be truncated.
Without Bottom Border
Props
InPageNavigation
InPageNavigationItem components to display.
Accessible label for the navigation, used as the aria-label.
Visual style variant. Full width variants distribute items evenly across the container.
Layout orientation of the navigation items.
Allows removal of the default bottom margin by setting to ‘space0’.
Hides the bottom border. Use sparingly.
Overrides the default element name to apply unique styles with the Customization Provider.
InPageNavigationItem
The text content to display for the navigation item.
URL or anchor to navigate to when clicked.
Marks this item as the current page, applying active styles and setting
aria-current="page".Accessible title attribute for when content is truncated. Strongly recommended on all items, especially in vertical navigation or when text might truncate.
Overrides the default element name to apply unique styles with the Customization Provider.
Accessibility
- Uses semantic
<nav>element with requiredaria-labelto identify the navigation landmark. - Items are rendered as an unordered list (
<ul>) with proper list item markup. - The current page item has
aria-current="page"to indicate the active state. - External links automatically receive
rel="noreferrer noopener"andtarget="_blank"via thesecureExternalLinkutility. - The component automatically scrolls to show the selected item when it’s out of view.
- Overflow buttons appear when items don’t fit in the container, allowing users to scroll.
- The
titleattribute provides tooltips for truncated text.
Features
Automatic Scroll Management
The component automatically manages scrolling when there are more navigation items than can fit:- Overflow buttons appear on the left and right (or top and bottom for vertical)
- Clicking overflow buttons scrolls to reveal hidden items
- The selected item automatically scrolls into view on mount
- Shadows appear to indicate there’s more content to scroll
Responsive Behavior
- The component listens to window resize events and adjusts overflow buttons accordingly
- Full width variants ensure items fill the available space
- Vertical orientation provides an alternative layout for sidebar navigation
Best Practices
Do
- Use In Page Navigation for navigating between sections on the same page
- Mark the current section with
currentPage - Provide clear, concise labels for each navigation item
- Use
titleattributes when text might be truncated - Use vertical orientation for sidebar navigation
- Use full width variants when you want items to fill the container
Don’t
- Don’t use for primary site navigation (use a different component)
- Don’t nest In Page Navigation components
- Don’t use too many items (consider grouping or a different pattern)
- Don’t forget to provide an
aria-label