Topic: Dynamic add of tab
morgan497 priority asked 1 year ago
Expected behavior I would like to add a new tab to an existing nav-tabs clicking on a button. It would show a popup to ask for the name of the tab and then create the tab.
Resources (screenshots, code snippets etc.)
morgan497 priority answered 1 year ago
Thanks a lot for your help.
I made more or less the same code than you but cloned a hidden tab instead of addind a raw html string as inner html and the result is quite the same.
Thank you for that part.
Then I tried to add an event listener for the 'shown' event but it doesn't work.
Here are part of code lines to add my new tab :
tabBarUl.insertBefore(clonedTabLi, addNode); // addNode is a button at the end of tabs
const tabTrigger = new mdb.Tab(clonedTabLi);
clonedTabA is inside clonedTabLi but that does not trigger the event 'shown.mdb.tab'. I also tried to reverse the last two lines but with no success.
Michał Duszak staff commented 1 year ago
Could you reproduce it in a snippet? I see you are creating an instance on an element of clonetTabLi, and you are trying to listen on a clonedTabA. That might be the case.
Michał Duszak staff answered 1 year ago
MDB doesn't have such a feature. You have to go full custom, here's a snippet I prepared. You can use it as a reference:
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
- User: Priority
- Premium support: Yes
- Technology: MDB Standard
- MDB Version: MDB5 3.9.0
- Device: Desktop
- Browser: Chrome
- OS: Windows 10
- Provided sample code: No
- Provided link: No