[ts/treeview]: Add logic to parse data attributes on treeview plugin

pull/5859/head
Diego Smania 2025-06-19 17:58:23 -03:00
parent 1a52342ff6
commit 7b77a56963
1 changed files with 12 additions and 1 deletions

View File

@ -119,13 +119,24 @@ onDOMContentLoaded(() => {
const target = event.target as HTMLElement
const targetItem = target.closest(SELECTOR_NAV_ITEM) as HTMLElement | undefined
const targetLink = target.closest(SELECTOR_NAV_LINK) as HTMLAnchorElement | undefined
const lteToggleElement = event.currentTarget as HTMLElement
if (target?.getAttribute('href') === '#' || targetLink?.getAttribute('href') === '#') {
event.preventDefault()
}
if (targetItem) {
const data = new Treeview(targetItem, Default)
// Read data attributes
const accordionAttr = lteToggleElement.dataset.accordion
const animationSpeedAttr = lteToggleElement.dataset.animationSpeed
// Build config from data attributes, fallback to Default
const config: Config = {
accordion: accordionAttr === undefined ? Default.accordion : accordionAttr === 'true',
animationSpeed: animationSpeedAttr === undefined ? Default.animationSpeed : Number(animationSpeedAttr)
}
const data = new Treeview(targetItem, config)
data.toggle()
}
})