(html: string)
| 2 | import { getId } from "./get-id"; |
| 3 | |
| 4 | export const initTabs = (html: string) => { |
| 5 | const root = parse(html); |
| 6 | |
| 7 | const tabs = root.querySelectorAll("[role=tab]").map((tab) => { |
| 8 | return { |
| 9 | id: getId(), |
| 10 | label: tab.getAttribute("data-label"), |
| 11 | tab, |
| 12 | }; |
| 13 | }); |
| 14 | |
| 15 | const content = tabs.map(({ tab, id }, i) => { |
| 16 | const content = tab.querySelector("div"); |
| 17 | |
| 18 | if (!content) { |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | if (i !== 0) { |
| 23 | content.setAttribute("hidden", ""); |
| 24 | } |
| 25 | |
| 26 | content.setAttribute("id", `tab-panel-${id}`); |
| 27 | content.setAttribute("role", `tabpanel`); |
| 28 | content.setAttribute("aria-labelledby", `tab-${id}`); |
| 29 | |
| 30 | return content; |
| 31 | }); |
| 32 | |
| 33 | return { tabs, content }; |
| 34 | }; |
nothing calls this directly
no test coverage detected
searching dependent graphs…