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

@markcarrrr/react-a11y-accordion

v1.0.8

Published

A ReactJS accessible accordion utilising the HTML details and summary tags for native semantics and accessibility.

Downloads

4

Readme

react-a11y-accordion CI

A ReactJS accessible accordion utilising the HTML <details> and <summary> tags for native semantics and accessibility.

Browser support - Can I use HTML5 <details>: https://caniuse.com/#feat=details

Supports React 16.0.0 or newer.

Installing

yarn add @markcarrrr/react-a11y-accordion

OR

npm install --save @markcarrrr/react-a11y-accordion

Example Usage

import { Accordion, AccordionItem } from '@markcarrrr/react-a11y-accordion';

export default () => (
  <Accordion>
    <AccordionItem header="Accordion header 1">
      Accordion content 1.
    </AccordionItem>
    <AccordionItem header="Accordion header 2">
      Accordion content 2.
    </AccordionItem>
  </Accordion>
);

Props

Required

header

  • type: string
  • default: "react-a11y-accordion"

Pass in text for the accordion header (output within the <summary> tag).

import { Accordion, AccordionItem } from '@markcarrrr/react-a11y-accordion';

export default () => (
  <Accordion>
    <AccordionItem header="Accordion header 1">
      Accordion content 1.
    </AccordionItem>
    <AccordionItem header="Accordion header 2">
      Accordion content 2.
    </AccordionItem>
  </Accordion>
);

Optional

onlyOneOpen

  • type: boolean
  • default: false

Allow only one accordion item to be open at any time. Please note if for any reason multiple open props are added to the <AccordionItem> child components then only the first item with an open prop will be open.

import { Accordion, AccordionItem } from '@markcarrrr/react-a11y-accordion';

export default () => (
  <Accordion onlyOneOpen>
    <AccordionItem header="Accordion header 1">
      Accordion content 1.
    </AccordionItem>
    <AccordionItem header="Accordion header 2">
      Accordion content 2.
    </AccordionItem>
  </Accordion>
);

onSelect

  • type: (isOpen: boolean, currentId: string): void;
  • default: undefined

Callback on accordion item selection. Returns open state and id for selected item.

import { Accordion, AccordionItem } from '@markcarrrr/react-a11y-accordion';

export default () => (
  <Accordion onSelect={() => {})}>
    <AccordionItem header="Accordion header 1">
        Accordion content 1.
    </AccordionItem>
    <AccordionItem header="Accordion header 2">
        Accordion content 2.
    </AccordionItem>
  </Accordion>
);

id

  • type: string
  • default: auto-generated

Pass in an id for the accordion item wrapper (applied on the <details> tag).

import { Accordion, AccordionItem } from '@markcarrrr/react-a11y-accordion';

export default () => (
  <Accordion>
    <AccordionItem header="Accordion header 1" id="accordion-id-1">
      Accordion content 1.
    </AccordionItem>
    <AccordionItem header="Accordion header 2" id="accordion-id-2">
      Accordion content 2.
    </AccordionItem>
  </Accordion>
);

open

  • type: boolean
  • default: false

Add if you want the item open by default (applied on the <details> tag). Please note if onlyOneOpen has been added to <Accordion> and for any reason multiple open props are added to the <AccordionItem> child components then only the first item with an open prop will be open.

import { Accordion, AccordionItem } from '@markcarrrr/react-a11y-accordion';

export default () => (
  <Accordion>
    <AccordionItem header="Accordion header 1" open>
      Accordion content 1.
    </AccordionItem>
    <AccordionItem header="Accordion header 2">
      Accordion content 2.
    </AccordionItem>
  </Accordion>
);

Styling

There is purposfully no styling added allowing you to style as required from a clean state.

The BEM methodology has been used for classnames.

<div class="react-a11y-accordion">
  <details class="react-a11y-accordion__item">
    <summary class="react-a11y-accordion__header">...</summary>
    <div class="react-a11y-accordion__content">...</div>
  </details>
</div>

Development

Initial steps

  1. git clone https://github.com/markcarrrr/react-a11y-accordion.git
  2. yarn install

Scripts

Build code

yarn build

Start local dev server

yarn start

Lint code

yarn lint

Format code

yarn format

Run tests

yarn test

Authors

License

This project is licensed under the ISC License - see the LICENSE.md file for details