Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
makeup-expander
Advanced tools
Creates the basic interactivity for an element that expands and collapses another element.
Creates the basic interactivity for an element that expands and collapses another element.
This module is still in an experimental state, until it reaches v1.0.0 you must consider all minor releases as breaking changes. Patch releases may introduce new features, but will be backwards compatible.
// via npm
npm install makeup-expander
// via yarn
yarn add makeup-expander
In the most basic use case, the interactive host element is an adjacent sibling of the content that it expands. We leverage the aria-expanded state to hide and show the overlay with CSS.
<div class="expander">
<button class="expander__host">Click for Flyout</button>
<div class="expander__content">
<p>Any kind of HTML control can go inside...</p>
<p>A link: <a id="foo" href="http://www.ebay.com">www.ebay.com</a></p>
<p>A button: <button>Click Me</button></p>
<p>An input: <input type="text" aria-label="Dummy textbox"></p>
<p>A checkbox: <input type="checkbox" aria-label="Dummy checkbox"></p>
</div>
</div>
// import the module
const Expander = require('makeup-expander');
// get an element reference
const widgetEl = document.querySelector('.expander');
// options
const options = {
expandOnClick: true
};
// get widget instance
const widget = new Expander(widgetEl, options);
Clicking the button will now toggle it's aria-expanded state. CSS can be used to display the content accordingly, for example:
.expander__content {
display: none;
}
.expander__host[aria-expanded="true"] ~ .expander__content {
display: block;
}
In this example, the interactive host element and the content that it expands are not siblings. We cannot leverage aria-expanded to hide and show the overlay with CSS. Instead we must leverage a class on the root element of the widget. This class is defined in the widget options.
<div class="widget">
<span class="widget__button">
<button class="expander__host">Click for Flyout</button>
</span>
<div class="expander__content">
<p>Any kind of HTML control can go inside...</p>
<p>A link: <a id="foo" href="http://www.ebay.com">www.ebay.com</a></p>
<p>A button: <button>Click Me</button></p>
<p>An input: <input type="text" aria-label="Dummy textbox"></p>
<p>A checkbox: <input type="checkbox" aria-label="Dummy checkbox"></p>
</div>
</div>
// import the module
const Expander = require('makeup-expander');
// get an element reference
const widgetEl = document.querySelector('.widget');
// options
const options = {
expandOnClick: true,
expandedClass: 'widget--expanded'
};
// get widget instance
const widget = new Expander(widgetEl, options);
Clicking the button will now toggle it's aria-expanded state and toggle the expanded class on the root element. CSS can be used to display the content accordingly, for example:
.expander__content {
display: none;
}
.widget--expanded .expander__content {
display: block;
}
el
: the root widget eloptions.autoCollapse
: applies one or more collapse behaviors (collapseOnClickOut
, collapseOnFocusOut
, collapseOnMouseOut
) based on expand behaviour (default: false)options.collapseOnClickOut
: whether the content should collapse when clicking outside of content (default: false)options.collapseOnFocusOut
: whether the content should collapse when focus leaves the content (default: false)options.collapseOnMouseOut
: whether the content should collapse when mouse leaves the content (default: false)options.contentSelector
: the query selector for the content element in relation to the widget (default: '.expander__content')options.expandOnClick
: whether the host should be click activated (default: false)options.expandOnFocus
: whether the host should be focus activated (default: false)options.expandOnHover
: whether the host should be hover activated (default: false)options.focusManagement
: where focus should go (null, 'content', 'focusable', 'interactive', or ID reference) when click expander is activated with keyboard (default: null)options.hostSelector
: the query selector for the host element in relation to the widget (default: '.expander__host')options.expandedClass
: the class which will be used on the root element to signify expanded state. Example: foo--expanded
; this mirrors the aria-expanded="true"
setting on the host elementoptions.simulateSpacebarClick
: whether to force a click event on spacebar, in the case that the host does not natively trigger one (default: false)Set the following properties to true or false to enable or disable the behaviour.
collapseOnClickOut
collapseOnFocusOut
collapseOnMouseOut
expandOnClick
expandOnFocus
expandOnHover
collapse()
: set state to collapsedexpand()
: set state to expandedisExpanded()
: returns expanded statetoggle()
: toggle expanded/collapsed stateexpander-collapse
expander-expand
npm start
npm test
npm run lint
npm run fix
npm run build
npm run clean
The following hooks exist, and do not need to be invoked manually:
npm prepublish
cleans, lints, tests and builds on every npm publish
commandpre-commit
cleans, lints, tests and builds on every git commit
commandEach test run will generate the following reports:
/reports/coverage
contains Istanbul code coverage report/reports/html
contains HTML test reporthttps://travis-ci.org/makeup-js/makeup-expander
FAQs
Creates the basic interactivity for an element that expands and collapses another element.
We found that makeup-expander demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.