|
67 | 67 | const selectedContent = writable(undefined); |
68 | 68 |
|
69 | 69 | let refTabList = null; |
| 70 | + let refRoot = null; |
70 | 71 |
|
71 | 72 | /** |
72 | 73 | * @type {(data: { id: string; label: string; disabled: boolean }) => void} |
|
175 | 176 |
|
176 | 177 | tabs.update((currentTabs) => { |
177 | 178 | const tabsMap = new Map(currentTabs.map((tab) => [tab.id, tab])); |
178 | | -
|
179 | 179 | const reorderedTabs = domIds |
180 | | - .map((id) => tabsMap.get(id)) |
181 | | - .filter((tab) => tab !== undefined) |
182 | | - .map((tab, index) => ({ ...tab, index })); |
| 180 | + .map((id, index) => { |
| 181 | + const tab = tabsMap.get(id); |
| 182 | + return tab ? { ...tab, index } : undefined; |
| 183 | + }) |
| 184 | + .filter(Boolean); |
183 | 185 |
|
184 | 186 | return reorderedTabs; |
185 | 187 | }); |
186 | 188 | } |
187 | 189 |
|
188 | | - const contentElements = Array.from( |
189 | | - document.querySelectorAll("[role='tabpanel']"), |
190 | | - ); |
| 190 | + const contentElements = refRoot?.parentElement |
| 191 | + ? Array.from(refRoot.parentElement.querySelectorAll("[role='tabpanel']")) |
| 192 | + : []; |
191 | 193 | const contentIds = contentElements.map((el) => el.id); |
192 | 194 |
|
193 | 195 | content.update((currentContent) => { |
194 | 196 | const contentMap = new Map(currentContent.map((c) => [c.id, c])); |
195 | | -
|
196 | 197 | const reorderedContent = contentIds |
197 | | - .map((id) => contentMap.get(id)) |
198 | | - .filter((c) => c !== undefined) |
199 | | - .map((c, index) => ({ ...c, index })); |
| 198 | + .map((id, index) => { |
| 199 | + const c = contentMap.get(id); |
| 200 | + return c ? { ...c, index } : undefined; |
| 201 | + }) |
| 202 | + .filter(Boolean); |
200 | 203 |
|
201 | 204 | return reorderedContent; |
202 | 205 | }); |
|
233 | 236 | </script> |
234 | 237 |
|
235 | 238 | <div |
| 239 | + bind:this={refRoot} |
236 | 240 | role="navigation" |
237 | 241 | class:bx--tabs={true} |
238 | 242 | class:bx--tabs--container={type === "container"} |
|
0 commit comments