All Projects → michu2k → Accordion

michu2k / Accordion

Licence: mit
Accordion module created in pure javascript & CSS. Very useful to create FAQ lists on your website.

Programming Languages

javascript
184084 projects - #8 most used programming language
es6
455 projects

Projects that are alternatives of or similar to Accordion

a11y-accordion-tabs
A script for an accessible accordion tabs component
Stars: ✭ 50 (-46.81%)
Mutual labels:  accessibility, a11y, aria, accordion
jquery-accessible-carrousel-aria
jQuery Accessible Carrousel System, using ARIA
Stars: ✭ 40 (-57.45%)
Mutual labels:  accessibility, a11y, aria
aria-collapsible
A lightweight, dependency-free JavaScript module for generating progressively-enhanced collapsible regions using ARIA States and Properties.
Stars: ✭ 25 (-73.4%)
Mutual labels:  accessibility, a11y, aria
A11y tooltips
Accessible Tooltip Component
Stars: ✭ 35 (-62.77%)
Mutual labels:  accessibility, a11y, aria
aria-at
Assistive Technology ARIA Experience Assessment
Stars: ✭ 115 (+22.34%)
Mutual labels:  accessibility, a11y, aria
van11y-accessible-simple-tooltip-aria
ES2015 accessible simple tooltip, using ARIA
Stars: ✭ 22 (-76.6%)
Mutual labels:  accessibility, a11y, aria
jquery-accessible-modal-window-aria
jQuery simple and accessible modal window, using ARIA
Stars: ✭ 61 (-35.11%)
Mutual labels:  accessibility, a11y, aria
Accessible modal window
Accessible modal dialogs
Stars: ✭ 196 (+108.51%)
Mutual labels:  accessibility, a11y, aria
van11y-accessible-hide-show-aria
ES2015 accessible hide-show system (collapsible regions), using ARIA
Stars: ✭ 34 (-63.83%)
Mutual labels:  accessibility, a11y, aria
Js Offcanvas
A lightweight, flexible jQuery off-canvas navigation plugin which lets you create fully accessible sidebar or top/bottom sliding (or push) panels with keyboard interactions and ARIA attributes.
Stars: ✭ 272 (+189.36%)
Mutual labels:  accessibility, a11y, aria
Accessible components
Listing of accessible components & patterns
Stars: ✭ 393 (+318.09%)
Mutual labels:  accessibility, a11y, aria
jquery-accessible-simple-tooltip-aria
jQuery accessible simple tooltip window, using ARIA
Stars: ✭ 22 (-76.6%)
Mutual labels:  accessibility, a11y, aria
Creatability Components
Web components for making creative tools more accessible.
Stars: ✭ 248 (+163.83%)
Mutual labels:  accessibility, a11y, aria
Eslint Plugin Jsx A11y
Static AST checker for a11y rules on JSX elements.
Stars: ✭ 2,609 (+2675.53%)
Mutual labels:  accessibility, a11y, aria
Accessible Html Content Patterns
♿️ The full HTML5 Doctor Element Index as well as common markup patterns for quick reference.
Stars: ✭ 93 (-1.06%)
Mutual labels:  accessibility, a11y, aria
alfa
♿ Suite of open and standards-based tools for performing reliable accessibility conformance testing at scale
Stars: ✭ 75 (-20.21%)
Mutual labels:  accessibility, a11y, aria
Skin
Pure CSS framework designed & developed by eBay for a branded, e-commerce marketplace.
Stars: ✭ 126 (+34.04%)
Mutual labels:  accessibility, a11y, aria
Houdini
A simple, accessible show-and-hide/accordion script.
Stars: ✭ 148 (+57.45%)
Mutual labels:  accessibility, a11y, accordion
enabler
✋ Accessibility analyzer for your frontend.
Stars: ✭ 19 (-79.79%)
Mutual labels:  accessibility, a11y, aria
Van11y Accessible Tab Panel Aria
ES2015 accessible tabs panel system, using ARIA
Stars: ✭ 58 (-38.3%)
Mutual labels:  accessibility, a11y, aria

Accordion

Lightweight and accessible accordion module with an extensible API. With the module you can create accordion on your website, useful especially for creating FAQ lists.

Version

3.1.1

Installation

npm

Install the package & import files

npm install accordion-js
import Accordion from 'accordion-js';
import 'accordion-js/dist/accordion.min.css';
CDN

Include files using CDN.

https://unpkg.com/[email protected]/dist/accordion.min.css
https://unpkg.com/[email protected]/dist/accordion.min.js
<link rel="stylesheet" href="[CDN CSS URL]">
<script src="[CDN JS URL]"></script>
Github

You can also download files from Github and attach them manually to your project.
Note: On production use files (JS and CSS) only from dist/ folder.

Usage

Include files

See the section above.

Create HTML layout

This is just an example of a layout. You can create your own HTML structure.

<div class="accordion-container">
  <div class="ac">
    <h2 class="ac-header">
      <button class="ac-trigger">Lorem ipsum dolor sit amet.</button>
    </h2>
    <div class="ac-panel">
      <p class="ac-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </div>
  </div>

  <div class="ac">
    <h2 class="ac-header">
      <button class="ac-trigger">Lorem ipsum dolor sit amet.</button>
    </h2>
    <div class="ac-panel">
      <p class="ac-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </div>
  </div>

  <div class="ac">
    <h2 class="ac-header">
      <button class="ac-trigger">Lorem ipsum dolor sit amet.</button>
    </h2>
    <div class="ac-panel">
      <p class="ac-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </div>
  </div>
</div>
Initialize the module
<script>
  new Accordion('.accordion-container');
</script>

API

Examples

new Accordion(container, options)

  • container - string | HTMLElement (required), selector of accordion container
  • options - object (optional), accordion options
// Default options
new Accordion('.container-first');

// User options
new Accordion('.container-second', {
  duration: 400,
  showMultiple: true,
  onOpen: function(currentElement) {
    console.log(currentElement);
  }
});

// Define several accordions with the same options (pass an array with selectors)
new Accordion(['.container-first', '.container-second'], {});

// or pass an array with HTMLElements
const accordions = Array.from(document.querySelectorAll('.accordion-container'));
new Accordion(accordions, {});

// Detach events
const accordion = new Accordion('.container-first');
accordion.detachEvents();
Options
Option Type Default value Description
duration number 600 Animation duration in ms
ariaEnabled boolean true Add ARIA elements to the HTML structure
collapse boolean true Allow collapse expanded panel
showMultiple boolean false Show multiple elements at the same time
openOnInit array [] Show accordion elements during initialization
elementClass string 'ac' Element class
triggerClass string 'ac-trigger' Trigger class
panelClass string 'ac-panel' Panel class
activeClass string 'is-active' Active element class
beforeOpen function - Calls before the item is opened.
beforeOpen: (currElement) => {}
onOpen function - Calls when the item is opened.
onOpen: (currElement) => {}
beforeClose function - Calls before the item is closed.
beforeClose: (currElement) => {}
onClose function - Calls when the item is closed.
onClose: (currElement) => {}
Methods
Option Description Arguments
attachEvents() Attach events -
detachEvents() Detach events -
open() Open the accordion element with the given idx
E.g. acc.open(1)
idx - element index
close() Close the accordion element with the given idx
E.g. acc.close(1)
idx - element index
toggle() Toggle the accordion element with the given idx
E.g. acc.toggle(1)
idx - element index
openAll() Open all accordion elements -
closeAll() Close all accordion elements -
destroy() Destroy accordion instance:
Open elements, remove events, IDs & ARIA
-

v3 Release Info

There have been a lot of changes to the API in version 3.0.0, so if you are using previous versions of the accordion (2.8.0 and below), I recommend updating the package to the latest version with new structure and options.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].