Skip to content

[BUG] CVA DefaultVariants read as class names #193

@thebuilder

Description

@thebuilder

The named Object lookup seems to be working great - But, it stumbles if you define defaultVariants in CVA, since it doesn't recognize them as valid class names.

Given a cva like this:

const button = cva(["font-semibold", "border", "rounded"], {
  variants: {
    intent: {
      primary: [
        "bg-blue-500",
        "text-white",
        "border-transparent",
        "hover:bg-blue-600",
      ],
      // **or**
      // primary: "bg-blue-500 text-white border-transparent hover:bg-blue-600",
      secondary: [
        "bg-white",
        "text-gray-800",
        "border-gray-400",
        "hover:bg-gray-100",
      ],
    },
    size: {
      small: ["text-sm", "py-1", "px-2"],
      medium: ["text-base", "py-2", "px-4"],
    },
  },
  compoundVariants: [
    {
      intent: "primary",
      size: "medium",
      class: "uppercase",
      // **or** if you're a React.js user, `className` may feel more consistent:
      // className: "uppercase"
    },
  ],
  defaultVariants: {
    intent: "primary",
    size: "medium",
  },
});

You'll get these warnings:

   warning  Classname 'primary' is not a Tailwind CSS class!  tailwindcss/no-custom-classname
   warning  Classname 'medium' is not a Tailwind CSS class!    tailwindcss/no-custom-classname

Not sure what the best way to fix this would be - Should you be able to define keys to ignore when scanning objects? Sorta the opposite of the callees.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreview

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions