Sidebar Navigation
Definition
The sidebar component is a user interface element that provides navigation or supplementary content, typically positioned on the side of a webpage or application layout.
Description
The sidebar component offers a flexible and customizable solution for organizing and displaying navigation links, widgets, or additional content within a webpage or application. It enhances user experience and facilitates easy access to relevant information.
Accessibility Considerations
When implementing the sidebar component, it is important to consider accessibility guidelines to ensure that it is usable for all users, including those with disabilities. Some accessibility considerations for the sidebar component include:
- Providing proper keyboard navigation and focus management for interactive elements within the sidebar.
- Ensuring sufficient color contrast between text and background to improve readability.
- Adding appropriate ARIA roles and attributes to enhance screen reader compatibility.
- Testing the sidebar component with assistive technologies to identify and address any potential accessibility issues.
Sidebar Header
The header is a prominent section located at the top of the sidebar navigation component. It is optional and serves the purpose of providing context and additional information related to the navigation menu and links within the sidebar.
Example: Sidebar Header
Variants
The sidebar component supports the following variants:
Full Height
The full-height variant is best used when there is only a header above it and a footer below. The sidebar is left positioned in the viewport and takes the full height of the content to the right of it. This variant provides a visually impactful and immersive layout.
Implementation
Place the .sidebarnav
within a Bootstrap 5 .container-fluid>.row
with the following utility classes...
col-md-3 col-xl-2 col-12 ps-md-0 pt-md-0 pt-2
Place the main content of the web page to the right of it with the
following utility classes and a id="skipto"
identifier so that
keyboard users can skip to important content.
<div id="skipto" class="col-12 col-md-9
pb-5">
The Full Height variant is conveniently implemented on this page.
Contained
The contained variant is best used when there is page content above or below the sidebar. The sidebar's height is determined by its own content and is placed within a container with gutters, blending seamlessly with the flow of content above and below it. The main content is positioned to the right of the sidebar.
Adding the class .fit-content
to the sidebar will make it adjust
its height based on the content inside, rather than taking the full height of
it's column.
Implementation
Place the .sidbarnav
within a .container>.row
with the following utility classes...
col-12 col-md-4 col-lg-3
Place main content accordingly...
<div id="skipto" class="col-12 col-md-8">
Example: Contained
Tab
The tab variant allows the sidebar to toggle the visibility of content to the right of it instead of navigating to different pages. This variant is useful when you want to present multiple sets of related content and provide an intuitive way for users to switch between them. Implementing this variant requires additional JavaScript to handle the toggling functionality and cannot be done with BS5's standard JavaScript.
Example: Tab
Anchored
The Anchored variant has the sidebar stuck the to the left side of the page
with a fixed width, and content in a .container
element. As the
page is decreased, the sidebar pushes the contained content over, with the content
staying centered.
Implementation
<section class="main-content sidebar-anchored">
<aside>
<nav class="nav sidebarnav" aria-label="Group Form Navigation">
...
</nav>
</aside>
<main class="container">
...
</main>
</section>
Example: Anchored
Variables
Custom variables were implemented for the anchored sidebar implementation
// Sass variable
$anchored-sidebarnav-width: 15rem;
// CSS custom property to override in-browser
--anchored-sidebarnav-width: $anchored-sidebarnav-width;