npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

accessible-navbar

v0.0.12

Published

An extensible navigation bar with an accessible mobile menu.

Downloads

3

Readme

accessible-navbar

An extensible navigation bar with an accessible mobile menu.

Storybook examples

Install

yarn add accessible-navbar

and the peers...

yarn add focus-trap-react styled-components prop-types

Usage

import React from "react";
import { Navbar } from "accessible-navbar";

const Example = () => (
  <Navbar applicationNodeId="root">
    <a href="/">Home</a>
    <a href="/about">About</a>
    <a href="/contact">Contact</a>
  </Navbar>
);

Recipes

Take a look at the Storybook.

If you want to test the navbar with a screen reader or see the "The escape key closes the mobile menu" in action you'll have to press the "Open canvas in a new tab" button at the top right of your Storybook screen.

You can see the correct source code if you click the "story" tab in the addons section at the bottom of the screen. The "show info" button doesn't show the render-prop components correctly.

Accessibility ticks

The desktop menu is a <nav /> and the mobile menu is a modal with a <nav /> inside.

  • When the mobile menu is closed we don't render it into the dom.
  • When the mobile menu is open we add it at the end of the body (react portal).
  • The mobile menu has relevant aria attributes (for a modal).
  • The escape key closes the mobile menu.
  • When we open the mobile menu we transfer focus to the close button.
  • The focus is trapped inside the mobile menu, when open.
  • When we close the mobile menu the focus returns to the open button.
  • ~~Clicking outside the mobile menu (if it's not full screen) closes the menu.~~
  • When the mobile menu is open we lock the scroll for the html element.

If you feel something is off, please let me know with an issue.

Available components

Navbar is a render props component that renders by default a DesktopList and a MobileList.

  • Navbar
  • DesktopList
  • DesktopListEmpty
  • MobileList
  • MobileListEmpty

They are all named exports:

import {
  Navbar,
  DesktopList,
  DesktopListEmpty,
  MobileList,
  MobileListEmpty
} from "accessible-navbar";