Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using compondVariants with slots and defaultVariants breaks #238

Open
mehdibha opened this issue Jan 23, 2025 · 1 comment
Open

Using compondVariants with slots and defaultVariants breaks #238

mehdibha opened this issue Jan 23, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@mehdibha
Copy link

Describe the bug

Using tailwind-variants with slots, compoundVariants, defaultVariants and explicitly passing the variants as undefined breaks.

To Reproduce

import { tv } from "tailwind-variants";

const variants = tv({
  slots: {
    root: "",
  },
  variants: {
    variant: {
      solid: {},
    },
    orientation: {
      horizontal: {
        root: "",
      },
    },
  },
  compoundVariants: [
    {
      orientation: "horizontal",
      variant: "solid",
      className: {
        root: "border-b",
      },
    },
  ],
  defaultVariants: {
    orientation: "horizontal",
    variant: "solid",
  },
});

const { root } = variants();

console.log(root({})) // Output: "border-b" 
console.log(root({ orientation: undefined, variant: undefined })) // Output: "" 

Expected behavior
It should use the defaultVariants

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser Chrome 131
  • Version 0.31

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@mehdibha mehdibha added the bug Something isn't working label Jan 23, 2025
@davidhellmann
Copy link

I have the same? experience:

const tvSpeaker = tv({
  slots: {
    slotRoot: "flex",
    slotBody: "flex flex-col",
    slotFontSize: "",
  },
  variants: {
    layout: {
      vertical: {
        slotRoot: "flex-col",
        slotBody: "text-center",
        slotFontSize: "",
      },
      horizontal: {
        slotRoot: "flex-row flex-nowrap",
        slotBody: "flex-row",
        slotFontSize: "",
      },
    },
  },
  defaultVariants: {
    layout: "horizontal",
  },
});
export const Speaker: React.FC<SpeakerProps> = ({
  layout,
  ...props
}) => {}

When I log layout it's undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants