Skip to content

Commit da5630c

Browse files
committed
DRY up reflecting attributes into shadow
1 parent 55cf4d6 commit da5630c

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/tab-container-element.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ export class TabContainerElement extends HTMLElement {
209209
if (index >= 0) this.selectTab(index)
210210
}
211211

212+
#reflectAttributeToShadow(name: string, node: Element) {
213+
if (this.hasAttribute(name)) {
214+
node.setAttribute(name, this.getAttribute(name)!)
215+
this.removeAttribute(name)
216+
}
217+
}
218+
212219
selectTab(index: number): void {
213220
if (!this.#setupComplete) {
214221
const tabListSlot = this.#tabListSlot
@@ -221,14 +228,8 @@ export class TabContainerElement extends HTMLElement {
221228
tabListSlot.style.display = 'block'
222229
}
223230
const tabList = this.#tabList
224-
if (this.hasAttribute('aria-description')) {
225-
tabList.setAttribute('aria-description', this.getAttribute('aria-description')!)
226-
this.removeAttribute('aria-description')
227-
}
228-
if (this.hasAttribute('aria-label')) {
229-
tabList.setAttribute('aria-label', this.getAttribute('aria-label')!)
230-
this.removeAttribute('aria-label')
231-
}
231+
this.#reflectAttributeToShadow('aria-description', tabList)
232+
this.#reflectAttributeToShadow('aria-label', tabList)
232233
if (this.vertical) {
233234
this.#tabList.setAttribute('aria-orientation', 'vertical')
234235
}

0 commit comments

Comments
 (0)