Topic: How I can select a specific tab according to page url in MDB5 standard?

Otabek Sadiridinov free asked 3 years ago


Expected behavior: Open a tab according to the hash comes after page address url.

For instance: https://mywebsite.com/about.html#v-how-to-tab. And it just should open the tab with v-how-to-tab id.

Actual behavior: Now it just opens the first or the .active class tab.

Resources (screenshots, code snippets etc.): Just, I have no any screenshots....


Grzegorz Bujański staff answered 3 years ago


By default, this option is not supported. You need to add extra js code to handle this. Use window.location.hash for this purpose. You can do it like this:

if (location.hash === "#my-hash") {
  const triggerEl = document.querySelector('a[href="#my-hash"]');

  if (triggerEl) {
    let instance = mdb.Tab.getInstance(triggerEl)

    if (!instance) {
      instance = new mdb.Tab(triggerEl);
    }

    instance.show();
  }
}


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: 3.2.0
  • Device: Any
  • Browser: Any
  • OS: Any
  • Provided sample code: No
  • Provided link: Yes