Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add util/tab/enableTabLinksInContent #7

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/util/tab/enableTabLinksInContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Tab } from 'bootstrap'

/**
* Enables the links inside tab panes to be able to switch to different tabs.
* <p>Use a syntax like this to enable the tab links:</p>
* <pre>
* <a href='#tablink-xyz' data-custom-toggle='tab'>Link to tab xyz</a>
* </pre>
* @param element Parent element which contains both the tab links and tab panes
*/
export default function(parent : HTMLElement) : void {
parent.querySelectorAll('a[data-custom-toggle="tab"]').forEach(anchor => {
anchor.addEventListener('click', event => {
event.preventDefault();
const target = anchor.getAttribute('href')
if (target) {
const tabElement = parent.querySelector(target)
if (tabElement) {
new Tab(tabElement).show()
}
}
})
})
}
Loading