fix: make Tab return null instead of using hidden class

This commit is contained in:
p-sw 2024-06-03 22:08:42 +09:00
parent 84a6536383
commit fc4e11f5f9

View File

@ -194,19 +194,11 @@ const TabTrigger = (props: TabTriggerProps) => {
const [tabContentVariant, resolveTabContentVariantProps] = vcn({ const [tabContentVariant, resolveTabContentVariantProps] = vcn({
base: "", base: "",
variants: { variants: {},
active: { defaults: {},
true: "",
false: "hidden",
},
},
defaults: {
active: false,
},
}); });
interface TabContentProps interface TabContentProps extends VariantProps<typeof tabContentVariant> {
extends Omit<VariantProps<typeof tabContentVariant>, "active"> {
name: string; name: string;
children: Exclude< children: Exclude<
React.ReactNode, React.ReactNode,
@ -220,15 +212,18 @@ const TabContent = (props: TabContentProps) => {
const { name, ...restProps } = restPropsBeforeParse; const { name, ...restProps } = restPropsBeforeParse;
const [context] = React.useContext(TabContext); const [context] = React.useContext(TabContext);
if (context.active[1] === name) {
return ( return (
<Slot <Slot
className={tabContentVariant({ className={tabContentVariant({
...variantProps, ...variantProps,
active: context.active[1] === name,
})} })}
{...restProps} {...restProps}
/> />
); );
} else {
return null;
}
}; };
export { TabProvider, useTabState, TabList, TabTrigger, TabContent }; export { TabProvider, useTabState, TabList, TabTrigger, TabContent };