Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@degjs/expander

Package Overview
Dependencies
Maintainers
10
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@degjs/expander

A plugin to handle functionality and accessibility for expanding elements.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
10
Created
Source

expander

Run Tests

A re-usable plugin to manage functionality and accessibility of expanding elements

Install

expander is an ES6 module. Consequently, you'll need an ES^ transpiler (Babel is a nice one) as part of your Javascript workflow.

If you're already using NPM for your project, you can install expander with the following command:

$ npm install @degjs/expander

Usage

The expander plugin will handle listening and responding to click events on a trigger button. It also handles accessibility associated with this (see accessibility section below). Finally, there is built-in support for animation when expanding or collapsing. It will dispatch custom events that the application can listen and respond to.

Note: the expander plugin exports a variable called events to help standardize event names that the app can listen for.

import expander, { events } from '@degjs/expander';

let expanderInst;

const init = () => {
    expanderInst = expander(containerEl);

    containerEl.addEventListener(events.beforeExpand, onBeforeExpand);
};

const destroy = () => {
    expanderInst.destroy();
};

Options

Property NameTypeDefaultDescription
isExpandedBooleanfalseDescribes if the content is expanded on init
toggleSelectorString"button"The selector string to find the toggle trigger element
controlsIdStringnullThe id of the content element that is controlled by the toggle button
expandingCssClassString"is-expanding"The css class to be added when and element is in the process of expanding
collapsingCssClassString"is-collapsing"The css class to be added when and element is in the process of collapsing
expandedCssClassString"is-expanded"The css class to be added when and element is fully expanded
collapsedCssClassString"is-collapsed"The css class to be added when and element is fully collapsed
animationTargetElElementnullThe element to add the animation classes to
animationEventString"animationend"The animation event name to listen for. When it is fired, the expand or collapse action will commence

Methods

getElement()

The getElement method returns the container element used by expander.

Returns
TypeDescription
Elementthe element that contains the trigger and content for expander

expand()

A way to manually trigger the expand functionality of expander.

collapse()

A way to manually trigger the collapse functionality of expander.

getOptions()

The getOptions method returns the current expander settings.

Returns
TypeDescription
Objectthe current settings for expander (defaults and user-set options combined)

setOptions(newOptions)

The setOptions method allows changes to the current expander settings. This method performs a merge of the original settings and the new ones.

Arguments
TypeDescription
Objectnew settings for the expander plugin
Returns

Nothing

destroy()

This method removes any aria-attributes it created and cleans up any event listeners it created.

Accessibility Features

aria-controls

The aria-controls attribute details a relationships between two elements in the DOM. In this module, the aria-controls attribute is added to the toggle element if an element id is provided in the expander options.

It is recommended that the controlsId is passed as an option if the element shown/hidden by the toggle does not immediately follow the toggle in DOM order.

aria-expanded

The aria-expanded attribute details whether a collapsible region is expanded or collapsed.

The expander module will set the aria-expanded attribute to the appropriate value whenever content is expanded or collapsed.

Browser Support

expander depends on the following browser APIs:

To support legacy browsers, you'll need to include polyfills for the above APIs.

Keywords

FAQs

Package last updated on 07 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc