Skip to content

Commit 746fef8

Browse files
committed
simplify handleclick
1 parent 53ed7f1 commit 746fef8

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

src/tab-container-element.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,13 @@ export class TabContainerElement extends HTMLElement {
137137
}
138138

139139
#handleClick(event: MouseEvent) {
140+
const tab = (event.target as HTMLElement)?.closest?.('[role=tab]')
141+
if (!tab) return
140142
const tabs = getTabs(this)
141-
142-
if (!(event.target instanceof Element)) return
143-
if (event.target.closest(this.tagName) !== this) return
144-
145-
const tab = event.target.closest('[role="tab"]')
146-
if (!(tab instanceof HTMLElement) || !tab.closest('[role="tablist"]')) {
147-
return
148-
}
149-
150-
const index = tabs.indexOf(tab)
151-
this.selectTab(index)
143+
const index = tabs.indexOf(tab as HTMLElement)
144+
if (index >= 0) this.selectTab(index)
152145
}
153146

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

0 commit comments

Comments
 (0)