Skip to content

Commit 7f8c0be

Browse files
authored
Merge pull request #424 from yilanboy/change-tab-logic
Change active tab selection logic in TabbedCode component
2 parents b4ae24e + 2fca904 commit 7f8c0be

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

resources/js/Components/TabbedCode.jsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,19 @@ const guessTabType = tabNames => {
1616
const TabbedCode = ({ className, examples, height }) => {
1717
const [codeTabs, setCodeTabs] = useContext(CodeTabContext) || useState({ unknown: 0 })
1818
const tabType = guessTabType(examples.map(example => example.name))
19-
const exampleIndex = examples.findIndex(example => codeTabs[tabType] === example.name)
19+
const exampleIndex = examples.findIndex(example => {
20+
if (codeTabs[tabType] === example.name) {
21+
return true
22+
}
23+
24+
if (
25+
(codeTabs[tabType]?.startsWith('Svelte') && example.name === 'Svelte') ||
26+
(codeTabs[tabType] === 'Svelte' && example.name.startsWith('Svelte'))
27+
) {
28+
// Svelte example are named either 'Svelte', 'Svelte 4', or 'Svelte 5'
29+
return true
30+
}
31+
})
2032
const activeTab = exampleIndex < 0 ? 0 : exampleIndex
2133

2234
return (

0 commit comments

Comments
 (0)