Skip to content

Commit

Permalink
Treeview accordance
Browse files Browse the repository at this point in the history
  • Loading branch information
danny007in committed Sep 12, 2023
1 parent 51902dc commit 1009867
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/ts/treeview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* --------------------------------------------
* AdminLTE treeview.ts
* License MIT
* @file AdminLTE treeview.ts
* @description Expandable treeview menu for AdminLTE.
* @license MIT
* --------------------------------------------
*/

Expand Down Expand Up @@ -32,11 +33,13 @@ const SELECTOR_TREEVIEW_MENU = '.nav-treeview'
const SELECTOR_DATA_TOGGLE = '[data-lte-toggle="treeview"]'

const Default = {
animationSpeed: 300
animationSpeed: 300,
accordion: true
}

type Config = {
animationSpeed: number;
accordion: boolean;
}

/**
Expand All @@ -56,6 +59,20 @@ class Treeview {
open(): void {
const event = new Event(EVENT_EXPANDED)

if (this._config.accordion) {
const openMenuList = this._element.parentElement?.querySelectorAll(`${SELECTOR_NAV_ITEM}.${CLASS_NAME_MENU_OPEN}`)

openMenuList?.forEach(openMenu => {
if (openMenu !== this._element.parentElement) {
openMenu.classList.remove(CLASS_NAME_MENU_OPEN)
const childElement = openMenu?.querySelector(SELECTOR_TREEVIEW_MENU) as HTMLElement | undefined
if (childElement) {
slideUp(childElement, this._config.animationSpeed)
}
}
})
}

this._element.classList.add(CLASS_NAME_MENU_OPEN)

const childElement = this._element?.querySelector(SELECTOR_TREEVIEW_MENU) as HTMLElement | undefined
Expand Down

0 comments on commit 1009867

Please sign in to comment.