thednp / bootstrap.native

Bootstrap components build with Typescript
http://thednp.github.io/bootstrap.native/
MIT License
1.7k stars 177 forks source link

modal.dispose can cause issues if used in hidden.bs.modal #442

Closed lekoala closed 2 years ago

lekoala commented 2 years ago

if I dispose the modal after it is hidden (in hidden.bs.modal), I get the following issue

modal-native.js:151 Uncaught TypeError: Cannot read properties of null (reading 'style')
    at Mr (modal-native.js:151:11)
    at HTMLDivElement.<anonymous> (modal-native.js:212:41)
    at HTMLDivElement.a (emulateTransitionEnd.js:25:17)

Somehow, the element in afterModalHide are already null. It seems due to modal.dispose(). If i simply remove the element (without using dispose) it's working fine, even though it is called after (which is really odd). Not sure what is happening here

Sample code:

let button3 = document.querySelector(".bsn-modal");
button3.addEventListener("click", (ev) => {
  console.log("click");
  var myModalInstance = new BSN.Modal("#myModal", {
    backdrop: "static",
    keyboard: false
  });
  myModalInstance.show();
  document.querySelector("#myModal").addEventListener("hidden.bs.modal", (ev) => {
    myModalInstance.dispose();
  });
});

using the example of the docs

lekoala commented 2 years ago

example here, click bsn modal dispose https://codepen.io/lekoalabe/pen/wvPygrg

lekoala commented 2 years ago

this seems fixed on master

lekoala commented 2 years ago

actually it's a bit tricky. if i dispose of the element like this, the element has everything set to null in aftermodalhide except the element. not sure that is the intended behaviour?

thednp commented 2 years ago

Yes

lekoala commented 2 years ago

then it's fine :)