thednp / bootstrap.native

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

getInstance behavior change between v4.1 and v4.2? #445

Closed jcorporation closed 2 years ago

jcorporation commented 2 years ago

I am in the process of migrating to the v4.2 version and I noticed that some BSN.getInstance calls are returning now NULL instead of the instance.

I noticed this for dropdowns and collapse components. The components itself are working. I only can not get the instance by javascript.

html code:

<div class="btn-group dropup">
  <button data-title-phrase="Outputs" id="volumeMenu" class="btn btn-dark dropdown-toggle px-2 mi" type="button" data-bs-toggle="dropdown">volume_up</button>
  <div id="outputsDropdown" class="dropdown-menu dropdown-menu-dark">
   <!-- content -->
 </div>
</div>

js:

console.log(BSN.Dropdown.getInstance(document.getElementById('volumeMenu')));  // returns the instance
console.log(BSN.Dropdown.getInstance('#volumeMenu')); //returns null

It seems the selector is not working?

thednp commented 2 years ago

The BSN.Component.getInstance haven't changed in v4.2, you only need to make sure to always get instance of a real HTMLElement object, your first line should work:

console.log(BSN.Dropdown.getInstance(document.getElementById('volumeMenu')));  // returns the instance
jcorporation commented 2 years ago

Thanks for clarification. The second line works in v4.1 too.

The documentation describes the second line or I misunderstand something?

// reference the initialization
var myDropdownInit = BSN.Dropdown.getInstance('#myDropdown');
thednp commented 2 years ago

The original library does this while we do this which is pretty much the same thing. Only component initialization can work with selector / HTMLElement.

jcorporation commented 2 years ago

Thanks for clarification.