Hello @jackshelton,
Thank you for reaching out and sharing the details of the issue you’re encountering while translating the React example to Qwik. I appreciate the steps you’ve taken so far, and based on your description, I believe the following solution may resolve the problems you’re facing.
We’ve tested the Custom Tabs component in Qwik using GEN 2 SDK(sdk-qwik) , and it seems to be working as expected. Below is the code for the Tabs component, which you can try implementing in your project:
import { component$, $, useSignal } from '@builder.io/qwik';
import { BuilderBlock, Blocks } from '@builder.io/sdk-qwik';
type Tab = {
label: string;
content: BuilderBlock[];
};
type TabsProps = {
tabs: Tab[];
builderBlock?: {
id: string;
};
};
export const Tabs = component$((props: TabsProps) => {
const activeTab = useSignal(0);
const handleTabClick = $(index => {
activeTab.value = index;
});
return (
<>
<div
style={{
display: 'flex',
overflow: 'auto',
}}
>
{props.tabs.map((item, index) => (
<span
key={index}
style={{
padding: '20px',
color: activeTab.value === index ? 'white' : '#ccc',
}}
onClick$={() => handleTabClick(index)}
>
{item.label}
</span>
))}
</div>
{props.tabs.length > 0 && props.builderBlock && (
<Blocks
parent={props.builderBlock.id}
path={`component.options.tabs.${activeTab.value}.content`}
blocks={props.tabs[activeTab.value].content}
/>
)}
</>
);
});
Additionally, here’s the registration code for the Tabs component:
{
component: Tabs,
name: 'Tabs',
canHaveChildren: true,
shouldReceiveBuilderProps: {
builderBlock: true,
},
inputs: [
{
name: 'tabs',
type: 'list',
subFields: [
{
name: 'label',
type: 'text',
defaultValue: 'New tab',
},
{
name: 'content',
type: 'uiBlocks',
defaultValue: [],
},
],
defaultValue: [
{
label: 'Tab 1',
content: [],
},
],
},
],
}
Loom:
SDK used: @builder.io/sdk-qwik": "^0.16.13
Please give this a try and let us know if the issue persists. If you encounter any further difficulties or have any questions, we’ll be happy to assist you further.
Looking forward to your feedback!
Best regards,