zuramai / mazer

Free and Open-source Bootstrap 5 Admin Dashboard Template and Landing Page
http://zuramai.github.io/mazer
MIT License
2.77k stars 782 forks source link

TypeError: Cannot read properties of null (reading 'getBoundingClientRect') #278

Closed mogottsch closed 1 year ago

mogottsch commented 1 year ago

I get this error message with the newest version when trying to render the sidebar without any active elements:

TypeError: Cannot read properties of null (reading 'getBoundingClientRect')

I think the issue is in the isElementInViewport function. If el is undefined this line fails:

    var rect = el.getBoundingClientRect();

It seems like the issue exists since this commit.

This fix works for me:

    // Scroll into active sidebar
    setTimeout(() => {
      const activeSidebarItem = document.querySelector(".sidebar-item.active");
      if (activeSidebarItem) {
        this.forceElementVisibility(activeSidebarItem);
      }
    }, 300);
mogottsch commented 1 year ago

I can create a PR if the fix is fine for you.

alfianchii commented 1 year ago

I can create a PR if the fix is fine for you.

Yup, please :)

mogottsch commented 1 year ago

I created a PR here :)

mocfaisal commented 1 year ago

Whoaa, great 👍 thanks for fixing it mate, I had the same issue