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

compound variants not work with responsive values #52

Open
mohammadgarmroodi opened this issue May 21, 2023 · 16 comments
Open

compound variants not work with responsive values #52

mohammadgarmroodi opened this issue May 21, 2023 · 16 comments
Labels
bug Something isn't working cant reproduce This bug cannot be reproduced responsive Issues related to responsive variants

Comments

@mohammadgarmroodi
Copy link

Describe the bug
compound variants does not support responsive values

To Reproduce
https://stackblitz.com/edit/vite-react-tailwind-dtjgiu?file=src%2FApp.jsx

@mohammadgarmroodi mohammadgarmroodi added the bug Something isn't working label May 21, 2023
@mskelton mskelton added the responsive Issues related to responsive variants label Oct 28, 2023
@sebpowell
Copy link

I'm running into this issue too – the classes are properly applied, but the Tailwind compiler doesn't seem to pick them up so the styles aren't generated.

@raminrez
Copy link

raminrez commented Dec 5, 2023

@mohammadgarmroodi
I have forked your example and updated the package (V0.1.18) to the latest version, but I can't see the problem. Can you double-check?

Here is my fork:
https://stackblitz.com/edit/vite-react-tailwind-rucbt4?file=src%2FApp.jsx

@mskelton mskelton added the cant reproduce This bug cannot be reproduced label Jan 18, 2024
@mskelton
Copy link
Collaborator

Closing due to lack of reproducability and response.

@mskelton mskelton closed this as not planned Won't fix, can't repro, duplicate, stale Jan 18, 2024
@Sliov
Copy link

Sliov commented Mar 14, 2024

Can we reopen this? We merged from cva to tailwind-variants and use compoundVariants quite a lot.

Here's an repro using the latest tailwind-variants version:

https://codesandbox.io/p/sandbox/tailwind-variants-example-forked-4tw75x?file=%2Fsrc%2FApp.tsx%3A39%2C9

@Gomah
Copy link
Contributor

Gomah commented Mar 19, 2024

Yeah, it looks like the logic from the regular variants is missing/not implemented for compoundVariants.

cc @mskelton

@mskelton mskelton reopened this Mar 20, 2024
@Sliov
Copy link

Sliov commented Mar 20, 2024

@mskelton, @jrgarciadev

Is it intended to work or it is a limitation like it is with Panda CSS?

When using compoundVariants in the recipe, you're not able to use responsive values in the variants.

To be fair, I think implementing this logic will impact performance as it needs to loop against the variants and the responsive screens?

@Jbmanllr
Copy link

Jbmanllr commented May 3, 2024

Wondering as well if it's intended. Guys what's your workarounds?

@Jbmanllr
Copy link

Jbmanllr commented May 4, 2024

To be more specific, compounded values are working, but are not responsive, it apply only to initial value.

@flozero
Copy link

flozero commented Jun 6, 2024

Same issue here

@w0ofy
Copy link
Contributor

w0ofy commented Jun 17, 2024

Bumping this thread because I'm running into this issue too. Is there a fix underway? Or a workaround?

@flozero

This comment was marked as off-topic.

@troymcginnis
Copy link

troymcginnis commented Aug 13, 2024

Same issue encountered here as well.

const mediaVariants = tv(
  {
    base: 'w-full flex-1 grow basis-1/2',
    compoundVariants: [
      {
        class: 'order-2 pt-0',
        layout: 'vertical',
        mediaPosition: 'bottom',
      },
    ],
    defaultVariants: {
      fill: false,
      mediaPosition: 'center',
    },
    variants: {
      fill: {
        true: 'relative aspect-[4/3]',
      },
      layout: {
        horizontal: '',
        vertical: '',
      },
      mediaPosition: {
        bottom: 'pt-7',
        center: 'py-7',
      },
    },
  },
  {
    responsiveVariants: true,
  }
)

When initialized with...

mediaVariants({ 
  layout: { initial: 'vertical', sm: 'horizontal' },
  mediaPosition: 'bottom',
})

Will always force the initial breakpoint use case resulting in being stuck with the following:

{
  class: 'order-2 pt-0',
  layout: 'vertical',
  mediaPosition: 'bottom',
}

My current workaround feels bad but works okay for my use case:

{
  class: 'max-sm:order-2 max-sm:pt-0',
  layout: 'vertical',
  mediaPosition: 'bottom',
},

Not ideal though. Very dependant on having the breakpoints of this component never change.

@flozero
Copy link

flozero commented Aug 13, 2024

my company and I have create a package that achieve this pretty well if you want to have a look and way faster

https://github.com/busbud/tailwind-buddy

@Kinbaum
Copy link

Kinbaum commented Aug 14, 2024

@mskelton Raising this issue as well. Here is a test case for responsive compound variants that can be added which currently fails. Note the comment in the expected results array:

describe("Tailwind Variants (TV) - Screen Variants", () => {
  test("should work with responsive compound variants", () => {
    const button = tv(
      {
        base: "text-xs font-bold",
        variants: {
          variant: {
            solid: "border-none bg-blue-500",
            outline: "bg-transparent border border-blue-500"
          },
          size: {
            sm: "text-sm",
            md: "text-md",
            lg: "text-lg"
          }
        },
        compoundVariants: [
          {
            variant: "solid",
            size: "sm",
            className: "bg-red-500"
          }
        ]
      },
      {
        responsiveVariants: true
      }
    );

    const result = button({
      variant: {
        initial: "outline",
        md: "solid"
      },
      size: 'sm'
    });

    const expectedResult = [
      "bg-transparent",
      "border",
      "border-blue-500",
      "font-bold",
      "md:bg-red-500", // expected md:bg-red-500 -- received md:bg-blue-500
      "md:border-none",
      "text-sm"
    ];

    expect(result).toHaveClass(expectedResult);
  });
});

@samogray
Copy link

The same issue, compoundVariants is not working for responsive :( , always returned initial value

@Volosojui
Copy link

The same issue here. This is a pretty important feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cant reproduce This bug cannot be reproduced responsive Issues related to responsive variants
Projects
None yet
Development

No branches or pull requests