4.2.2 • Published 2 years ago

@springernature/global-expander v4.2.2

Weekly downloads
221
License
MIT
Repository
-
Last release
2 years ago

Global Expander

Click a trigger element to toggle the display of a unique target element.

Usage

import {expander} from 'global-expander/js';

expander(options);
<button id="button1" data-expander data-expander-target="#target1">Expander 1</button>
<div id="target1">Target 1</div>

JavaScript

For more flexibility you can use the Expander class directly:

const trigger = document.querySelector('.my-trigger');
const target = document.querySelector('.my-target');

const myExpander = new Expander(trigger, target, options);

myExpander.init();

You can also manually open and close any instance of expander with:

expander.open();
expander.close();

Options

OptionDefault ValueTypeDescription
TARGET_HIDE_CLASS'u-js-hide'StringHTML class to be toggled on the target
TRIGGER_OPEN_CLASS-StringHTML class to be toggled to the trigger
TRIGGER_OPEN_LABEL-StringText to set on the trigger when open
CLOSE_ON_FOCUS_OUTtrueBooleanCloses when you click or tab outside of the target
AUTOFOCUSnullStringMoves focus to an element when hitting trigger:
firstTabbable will find the first tabbable element inside the target (will highlight text if appropriate, e.g. input with value).
target will set focus on target element
OPEN_EVENTfalseBooleanDispatch custom event on trigger once Global Expander has completed it's Open method
DEFAULT_OPENfalseBooleanSet the expander to be open by default

The data attribute options are the same, but are lowercase and hyphenated (and strings where the option is a boolean):

  • data-expander-target-hide-class
  • data-expander-trigger-open-class
  • data-expander-trigger-open-label
  • data-expander-close-on-focus-out
  • data-expander-autofocus
  • data-expander-open-event
  • data-expander-default-open

Note: data attribute options will take precedence over any options set during initialisation.

Polyfills / Babel plugins required

4.2.2

2 years ago

4.2.1

3 years ago

4.2.0

3 years ago

4.1.0

3 years ago

4.0.2

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.0

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago