Skip to content

Commit 53ed7f1

Browse files
committed
move event handler functions below handleevent
1 parent ca1a73a commit 53ed7f1

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

src/tab-container-element.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,28 @@ export class TabContainerElement extends HTMLElement {
8686
}
8787
}
8888

89+
connectedCallback(): void {
90+
this.addEventListener('keydown', this)
91+
this.addEventListener('click', this)
92+
for (const tab of getTabs(this)) {
93+
if (!tab.hasAttribute('aria-selected')) {
94+
tab.setAttribute('aria-selected', 'false')
95+
}
96+
if (!tab.hasAttribute('tabindex')) {
97+
if (tab.getAttribute('aria-selected') === 'true') {
98+
tab.setAttribute('tabindex', '0')
99+
} else {
100+
tab.setAttribute('tabindex', '-1')
101+
}
102+
}
103+
}
104+
}
105+
106+
handleEvent(event: Event) {
107+
if (event.type === 'click') return this.#handleClick(event as MouseEvent)
108+
if (event.type === 'keydown') return this.#handleKeydown(event as KeyboardEvent)
109+
}
110+
89111
#handleKeydown(event: KeyboardEvent) {
90112
const target = event.target
91113
if (!(target instanceof HTMLElement)) return
@@ -129,27 +151,6 @@ export class TabContainerElement extends HTMLElement {
129151
this.selectTab(index)
130152
}
131153

132-
connectedCallback(): void {
133-
this.addEventListener('keydown', this)
134-
this.addEventListener('click', this)
135-
for (const tab of getTabs(this)) {
136-
if (!tab.hasAttribute('aria-selected')) {
137-
tab.setAttribute('aria-selected', 'false')
138-
}
139-
if (!tab.hasAttribute('tabindex')) {
140-
if (tab.getAttribute('aria-selected') === 'true') {
141-
tab.setAttribute('tabindex', '0')
142-
} else {
143-
tab.setAttribute('tabindex', '-1')
144-
}
145-
}
146-
}
147-
}
148-
149-
handleEvent(event: Event) {
150-
if (event.type === 'click') return this.#handleClick(event as MouseEvent)
151-
if (event.type === 'keydown') return this.#handleKeydown(event as KeyboardEvent)
152-
}
153154

154155
selectTab(index: number): void {
155156
const tabs = getTabs(this)

0 commit comments

Comments
 (0)