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.

Can't close a Modal using JS

See original GitHub issue

BS5-modal-hide-issue

As you can see, the backdrop is still there, after the modal gets closed

I could remove the backdrop myself document.querySelector('.modal-backdrop')?.remove() but that feels quite hacky, this internal part should be part of bootstrap API

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
rohit2sharma95commented, Apr 23, 2021

So do you guys want the hide method to work synchronously? 😟 Since the code that you wrote is fine IMO @alpadev

const modal = bootstrap.Modal.getInstance(modalEl);
modal.hide();
modalEl.addEventListener('hidden.bs.modal', () => {
  modal.dispose();
}, { once:true });

/CC @GeoSot

1reaction
alpadevcommented, May 25, 2021

@caub glad if that works for you.

I’d prefer to leave this open tho, so that we can track this and maybe at some point come up with an easier solution. Or maybe we should open a new feature issue for this. 🤔

/CC @GeoSot @rohit2sharma95

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap: can't close modal - Stack Overflow
In the first page i have button connected to a Modal but when is open is not possible to closed it anymore and...
Read more >
modal open with javascript, not close correctly #119 - GitHub
Hey everyone,. When opening the modal with JavaScript, please use the modal.hide(); method by manually adding the event listener to the close ......
Read more >
Problems with modal (can't close it) - Laracasts
Hello! I ran into strange behavior when trying to close my modals. I wrote methods to show and close modal methods: { showModal:...
Read more >
How to close modal in Bootstrap - code helpers
There are few ways to close modal in Bootstrap: click on a backdrop, close icon, or close button. You can also use JavaScript...
Read more >
Can't close modal inside a listview - Retool Forum
I've inserted a button that runs a modal1.close() JS query when clicked, but I am getting this error message when clicking it: modal1.close...
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