Skip to content

[bug]: Prefix not working properly for Pseudo-classes #6687

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

Open
2 tasks done
Ain477 opened this issue Feb 19, 2025 · 3 comments · May be fixed by #6688 or #6885
Open
2 tasks done

[bug]: Prefix not working properly for Pseudo-classes #6687

Ain477 opened this issue Feb 19, 2025 · 3 comments · May be fixed by #6688 or #6885
Labels
bug Something isn't working

Comments

@Ain477
Copy link

Ain477 commented Feb 19, 2025

Describe the bug

Tailwind prefix not working for Pseudo-classes classes.

Right now it's

const buttonVariants = cva( "ac:inline-flex ac:items-center ac:justify-center ac:gap-2 ac:whitespace-nowrap ac:rounded-md ac:text-sm ac:font-medium ac:transition-[color,box-shadow] disabled:ac:pointer-events-none disabled:ac:opacity-50 [&_svg]:ac:pointer-events-none [&_svg:not([class*=size-])]:ac:size-4 [&_svg]:ac:shrink-0 ac:ring-ring/10 dark:ac:ring-ring/20 dark:ac:outline-ring/40 ac:outline-ring/50 focus-visible:ac:ring-4 focus-visible:ac:outline-1 aria-invalid:focus-visible:ac:ring-0", { variants: { variant: { default: "ac:bg-primary ac:text-primary-foreground ac:shadow-sm hover:ac:bg-primary/90" }, size: { default: "ac:h-9 ac:px-4 ac:py-2 has-[>svg]:ac:px-3" }, }, defaultVariants: { variant: "default", size: "default", }, } )

But it should be
const buttonVariants = cva( "ac:inline-flex ac:items-center ac:justify-center ac:gap-2 ac:whitespace-nowrap ac:rounded-md ac:text-sm ac:font-medium ac:transition-[color,box-shadow] ac:disabled:pointer-events-none ac:disabled:opacity-50 ac:[&_svg]:pointer-events-none ac:[&_svg:not([class*=size-])]:size-4 ac:[&_svg]:shrink-0 ac:ring-ring/10 ac:dark:ring-ring/20 ac:dark:outline-ring/40 ac:outline-ring/50 ac:focus-visible:ring-4 ac:focus-visible:outline-1 ac:aria-invalid:focus-visible:ring-0", { variants: { variant: { default: "ac:bg-primary ac:text-primary-foreground ac:shadow-sm ac:hover:bg-primary/90", }, size: { default: "ac:h-9 ac:px-4 ac:py-2 ac:has-[>svg]:px-3" }, }, defaultVariants: { variant: "default", size: "default", }, } )

Affected component/components

all

How to reproduce

  1. Install a nextjs project
  2. install tailwindcss
  3. install shadnc@canary
  4. config prefix

Codesandbox/StackBlitz link

https://codesandbox.io/p/devbox/qkftty

Logs

System Info

https://codesandbox.io/p/devbox/qkftty

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
@sonomandeep
Copy link

There is any update on this? Or any workaround?

@Gabrielbdd
Copy link

Gabrielbdd commented Mar 27, 2025

I’m having the same problem, and I’m not sure why the PRs to fix it are taking so long to merge.

In the meantime, I’m manually patching the generated components with this script:

fd . './src/components/ui/' --exec sd '(\w+(-\w+)?):bcp' 'bcp:$1'

Change bcp to your prefix and ./src/components/ui/ to the relative location where the generated components are.

Also, it needs fd and sd to be installed.

@tapeboy7
Copy link

tapeboy7 commented Apr 9, 2025

I’m having the same problem, and I’m not sure why the PRs to fix it are taking so long to merge.

In the meantime, I’m manually patching the generated components with this script:

fd . './src/components/ui/' --exec sd '(\w+(-\w+)?):bcp' 'bcp:$1'
Change bcp to your prefix and ./src/components/ui/ to the relative location where the generated components are.

Also, it needs fd and sd to be installed.

This temporary solution works great, thank you!

However, I did notice that the regex misses some cases. For example, in the button components, the class
has-[>svg]:tw:px-3 should be transformed into:
tw:has-[>svg]:px-3 but the current regex doesn’t account for brackets.

To fix this, I’ve updated the regex. Here’s the modified command, which is now escaped for running as a shell script:

#!/bin/zsh
fd . './src/components/ui/' --exec sd "([^\s'\"]+)(bcp:)([^\s'\"]+)" "\$2\$1\$3"

Same instructions:

Change bcp to your prefix and ./src/components/ui/ to the relative location where the generated components are.

Also, it needs fd and sd to be installed.

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
4 participants