Skip to content

Commit

Permalink
simplify handleclick
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Feb 16, 2024
1 parent 53ed7f1 commit 746fef8
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/tab-container-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,13 @@ export class TabContainerElement extends HTMLElement {
}

#handleClick(event: MouseEvent) {
const tab = (event.target as HTMLElement)?.closest?.('[role=tab]')
if (!tab) return
const tabs = getTabs(this)

if (!(event.target instanceof Element)) return
if (event.target.closest(this.tagName) !== this) return

const tab = event.target.closest('[role="tab"]')
if (!(tab instanceof HTMLElement) || !tab.closest('[role="tablist"]')) {
return
}

const index = tabs.indexOf(tab)
this.selectTab(index)
const index = tabs.indexOf(tab as HTMLElement)
if (index >= 0) this.selectTab(index)
}


selectTab(index: number): void {
const tabs = getTabs(this)
const panels = Array.from(this.querySelectorAll<HTMLElement>('[role="tabpanel"]')).filter(
Expand Down

0 comments on commit 746fef8

Please sign in to comment.