This component comes with a JavaScript part to handle interaction.
You can easily manage the component behavior by passing an object of options to the constructor.
Name | Default value |
---|---|
allowMultiple | false |
<div data-allow-multiple="false">
Instanciate the component based on the element provided and register the instance into .bulmaCollapsible
property of the element.
const bulmaCollapsibleElement = new bulmaCollapsible('#to-collapse');
// Access to the bulmaCollapsible instance from DOM
const collapsibleElement = document.getElementById('#to-collapse');
if (collapsibleElement) {
const collapsibleInstance = collapsibleElement.bulmaCollapsible();
}
Constructor shortcut with possibility to pass a String, a Node or a NodeList as a selector so we can instantciate multiple instances at once. Return an array of all instances. Note that each instance is link to the related DOM node under .bulmaCollapsible property.
// Return an array of bulmaCollapsible instances (empty if no DOM node found)
const bulmaCollapsibleInstances = bulmaCollapsible.attach('.is-collapsible');
// Loop into instances
bulmaCollapsibleInstances.forEach(bulmaCollapsibleInstance => {
// Check if current state is collapsed or not
console.log(bulmaCollapsibleInstance.collapsed());
});
Check if element is collasped or not. Return true
if element is collasped else false
.
// Find DOM node from ID
const bulmaCollapsibleElement = document.getElementById('to-collapse');
if (bulmaCollapsibleElement) {
// Instanciate bulmaCollapsible component on the node
new bulmaCollapsible(bulmaCollapsibleElement);
// Call method directly on bulmaCollapsible instance registered on the node
bulmaCollapsibleElement.bulmaCollapsible('collapsed');
}
Open the collapsed element. If allowMultiple option is set to True then collapse all other bulmaCollapsible elements within the same parent node.
// Find DOM node from ID
const bulmaCollapsibleElement = document.getElementById('to-collapse');
if (bulmaCollapsibleElement) {
// Instanciate bulmaCollapsible component on the node
new bulmaCollapsible(bulmaCollapsibleElement);
// Call method directly on bulmaCollapsible instance registered on the node
bulmaCollapsibleElement.bulmaCollapsible('expand');
}
Shortcut to expand method
Collaspe the element.
// Find DOM node from ID
const bulmaCollapsibleElement = document.getElementById('to-collapse');
if (bulmaCollapsibleElement) {
// Instanciate bulmaCollapsible component on the node
new bulmaCollapsible(bulmaCollapsibleElement);
// Call method directly on bulmaCollapsible instance registered on the node
bulmaCollapsibleElement.bulmaCollapsible('collapse');
}
Shortcut to collapse method
Proceed to component initialization and set initial state (expand or collapse) based on the presence of the is-active
class, initialize parent node to limit multiple expanded elements (accordion-like) and will attach triggerClick listener on each trigger linked to the current collapsible element.
Called on trigger click to toggle bulmaCollapsible element (expand it if collapsed, collapse it if expanded)
You can interact with component instance with events.
Name | Description | Example |
---|---|---|
before:expand |
Before expanding (opening) element |
|
after:expand |
After expanding (opening) element |
|
before:collapse |
Before collapsing (closing)) element |
|
after:collapse |
After collapsing (closing) element |
|