question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to add listeners directly to objects like Modals/Collapse/etc

See original GitHub issue

How about a public method to add listener(s) to an object, something like:

class Modal {
    //...

    on(event, callback) {
        this._element.addEventListener(`${event}${EVENT_KEY}`, callback);

        return this;
    }

    //...
}

This will allows us to do something like:

var myModal = new bootstrap.Modal(document.getElementById('myModal'));

myModal
    .on('shown', function (e) {
        // do something...
    })
    .on('hidden', function (e) {
        // do something...
    });

Instead of:

var myModal = new bootstrap.Modal(document.getElementById('myModal'));

myModal._element.addEventListener('shown.bs.modal', function (e) {
    // do something...
});
myModal._element.addEventListener('hidden.bs.modal', function (e) {
    // do something...
});

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:13
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
alecplcommented, Jun 25, 2021

I would love if that supported chaining. E.g.

let modal = new Modal(element)
    .on('shown', e => {  })
    .show()
0reactions
arcanedev-maroccommented, Nov 17, 2020

Hi @XhmikosR, i’ve created a PR: #32184

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Modal] Adding tests · twbs/bootstrap@1591420 · GitHub
Ability to add listeners directly to objects like Modals/Collapse/etc Ability to add listeners directly to objects like Modals/Collapse/etc. CSS (node-sass) # ...
Read more >
Multi-Modal Perception - Noba Project
Multimodal phenomena concern stimuli that generate simultaneous (or nearly simultaneous) information in more than one sensory modality. As discussed above, ...
Read more >
Accessible Rich Internet Applications (WAI-ARIA) 1.1 - W3C
It clarifies semantics to assistive technologies when authors create new types of objects, via style and script, that are not yet directly ......
Read more >
Menus - Android Developers
This method passes you the Menu object as it currently exists so you can modify it, such as add, remove, or disable items....
Read more >
Fallacies | Internet Encyclopedia of Philosophy
That is, informal fallacies are errors of reasoning that cannot easily be expressed in our system of formal logic (such as symbolic, deductive,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found