fix: correct button override to spread all props and avoid nested buttons

This commit is contained in:
2026-06-01 23:19:25 -05:00
parent fe4261f58f
commit ee791f450c

View File

@@ -106,27 +106,10 @@ export function getMDXComponents(components: MDXComponents): MDXComponents {
details: (props) => <details className="my-4 rounded-lg border border-border p-4" {...props} />,
summary: (props) => <summary className="cursor-pointer font-semibold" {...props} />,
// Buttons (handle onclick string from transformerCopyButton)
button: ({ children, onClick, ...props }: { children?: React.ReactNode; onClick?: string | (() => void); className?: string } & Record<string, unknown>) => {
if (typeof onClick === 'string') {
const className = (props.className as string) ?? '';
return (
<button
dangerouslySetInnerHTML={{
__html: `<button${className ? ` class="${className.replace(/"/g, '&quot;')}"` : ''} onclick="${onClick}">${(children as string) ?? ''}</button>`
}}
suppressHydrationWarning
/>
);
}
return (
<button
{...props}
onClick={typeof onClick === 'function' ? onClick : undefined}
>
{children}
</button>
);
},
button: ({ children, onClick, ...props }) => (
typeof onClick === 'string'
? <button {...props} dangerouslySetInnerHTML={{ __html: children as string }} onclick={onClick} />
: <button {...props} onClick={onClick}>{children}</button>
),
}
}