Skip to content

Commit f5ef3a2

Browse files
committed
style: improve code structure and enhance rendering of tab panel children
1 parent e3115a8 commit f5ef3a2

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/components/Markdown.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ const options: HTMLReactParserOptions = {
216216
}
217217
}
218218

219-
// Default tabs variant
220219
const tabs = attributes.tabs
221220
const id =
222221
attributes.id || `tabs-${Math.random().toString(36).slice(2, 9)}`
@@ -230,9 +229,11 @@ const options: HTMLReactParserOptions = {
230229
child instanceof Element && child.name === 'md-tab-panel',
231230
)
232231

233-
const children = panelElements?.map((panel) =>
234-
domToReact(panel.children as any, options),
235-
)
232+
const children = panelElements?.map((panel) => {
233+
const result = domToReact(panel.children as any, options)
234+
// Wrap in fragment to ensure it's a single React node
235+
return <>{result}</>
236+
})
236237

237238
return <Tabs id={id} tabs={tabs} children={children as any} />
238239
}

src/components/Tabs.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@ export function Tabs({
2929
const framework = params?.framework ?? undefined
3030

3131
const [internalActiveSlug, setInternalActiveSlug] = React.useState(() => {
32-
const match = framework ? tabsProp.find((tab) => tab.slug === framework) : undefined
32+
const match = framework
33+
? tabsProp.find((tab) => tab.slug === framework)
34+
: undefined
3335
return match?.slug ?? tabsProp[0]?.slug ?? ''
3436
})
3537

3638
const activeSlug = controlledActiveSlug ?? internalActiveSlug
3739
const setActiveSlug = React.useCallback(
3840
(slug: string) => {
3941
if (onTabChange) {
40-
onTabChange(slug);
42+
onTabChange(slug)
4143
} else {
42-
setInternalActiveSlug(slug);
44+
setInternalActiveSlug(slug)
4345
}
4446
},
4547
[onTabChange],

src/utils/markdown/plugins/transformTabsComponent.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ function extractFrameworkData(node: HastNode): FrameworkExtraction | null {
234234

235235
for (const child of children) {
236236
if (isHeading(child)) {
237-
238237
currentFramework = toString(child as any)
239238
.trim()
240239
.toLowerCase()

0 commit comments

Comments
 (0)