Tailwind "Checked" modifier not applying on Checkbox check #2078
-
So i've got a checkbox that i'm trying to style via tailwind. The only issue is that tailwinds checked modifier isn't applying on check. It works using the standard 'use client';
import * as React from 'react';
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
import { FaCheck } from 'react-icons/fa';
import { cn } from '../../lib/utils';
const Checkbox1 = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
onCheckedChange={(checked) => {
console.log('checked', checked);
}}
className={cn(
'peer h-6 w-6 shrink-0 rounded-lg border border-gray-300 hover:border-yonder-300 checked:bg-yonder-500 checked:border-yonder-500 focus:outline-none focus:ring-2 focus:ring-yonder-400 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
className,
)}
{...props}
>
<CheckboxPrimitive.Indicator
className={cn('flex items-center justify-center')}
>
<FaCheck className='h-4 w-4' />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox1.displayName = CheckboxPrimitive.Root.displayName;
export { Checkbox1 }; |
Beta Was this translation helpful? Give feedback.
Answered by
benoitgrelard
Apr 13, 2023
Replies: 1 comment 2 replies
-
Hey @Rocinante89 you should be able to target the |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
cill-i-am
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @Rocinante89 you should be able to target the
data-state
attribute natively in tailwind using arbitrary data attributes syntax: https://tailwindcss.com/docs/hover-focus-and-other-states#data-attributes