nextui icon indicating copy to clipboard operation
nextui copied to clipboard

[BUG] - Switch [selected=true] doesnt work

Open nickaris1 opened this issue 1 year ago • 6 comments

NextUI Version

2.2.5

Describe the bug

when using custom class names, [selected=true] doesn't work for thumb slots, while if I remove the =true and leave it as [selected] it works

eg group-data-[selected=true]:ml-8 doesn't works group-data-[selected]:ml-[33px] works

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

custom Switch

{
        base: twMerge(
          'ml-1 max-w-md bg-content1 hover:bg-content2 items-center',
          'rounded-lg gap-2 border-2 border-transparent',
          'data-[selected=true]:border-primary',
          base,
        ),
        wrapper: twMerge(
          'p-1 bg-white group-data-[selected=true]:bg-cxc-orange w-16 flex shadow-lg',
          wrapper,
          wrapperColor,
        ),
        thumb: twMerge(
          '!size-6 border-2 shadow-lg',
          'group-data-[hover=true]:border-primary',
          //selected
          'bg-cxc-gray group-data-[selected=true]:bg-white group-data-[selected=true]:ml-8',
          // pressed
          'group-data-[pressed=true]:w-7',
          'group-data-[selected=true]:group-data-[pressed=true]:ml-8',
          thumb,
        ),
      }

the code provided is based on switch#custom-styles

this happened after changing from "@nextui-org/react": "^2.2.9" to "@nextui-org/switch": "^2.2.5"

Expected behavior

The thumb goes only to about ml-6 while I have a bigger wrapper

Screenshots or Videos

No response

Operating System Version

any

Browser

Other (add additional context)

nickaris1 avatar Dec 12 '24 15:12 nickaris1

Had the same error, use group-data-[selected=true]:ms-8 instead. This probably happens because the tailwind class that comes with the component on the thumb slot 'group-data-[selected=true]:ms-5' has more specificity than yours. group-data-[selected]:ml-[33px] works because it has more specifity than the default rule used, so it overrides it. I would suggest structuring your tailwind rule the same way the default one is structured, since that way, because of tailwind variants, the default rule will not exist because you have provided one with the same structure.

stefnto avatar Dec 13 '24 09:12 stefnto

Is it just being overwritten by thumb? Does it work if you move the args around? If not please provide a minimal, reproducible sandbox @nickaris1

Peterl561 avatar Dec 16 '24 03:12 Peterl561

Had the same error, use group-data-[selected=true]:ms-8 instead. This probably happens because the tailwind class that comes with the component on the thumb slot 'group-data-[selected=true]:ms-5' has more specificity than yours. group-data-[selected]:ml-[33px] works because it has more specifity than the default rule used, so it overrides it. I would suggest structuring your tailwind rule the same way the default one is structured, since that way, because of tailwind variants, the default rule will not exist because you have provided one with the same structure.

I should make that more specific. On the reproducible step is all you need to make it so it doesn't work. when I was in dev which is refreshing the state on save, the margin did work on the thumb.

  • thanks group-data-[selected=true]:ms-8 works
  • the thing that worked for me is to change in the thumb slot the [selected=true]:ml-8 to [selected]:ml-8

nickaris1 avatar Dec 17 '24 07:12 nickaris1

Is it just being overwritten by thumb? Does it work if you move the args around? If not please provide a minimal, reproducible sandbox @nickaris1

codesandbox

nickaris1 avatar Dec 17 '24 08:12 nickaris1

The custom styles example for Switch in the docs is using the wrong class. As @stefnto suggested, ms is the correct one to use. ms/margin-inline-start is used by default and should not be mixed with ml/margin-left.

Peterl561 avatar Dec 17 '24 22:12 Peterl561