-
I really like the idea of accessible components! I would like to add some radix primitives to my project. I'm using Next.js and tailwindcss. I would like to add some classes depending on data-state value. I tried using https://github.com/ecklf/tailwindcss-radix but it doesn't seem to work. I also tried wrapping my components with a forwardRef, like here, but I cannot access the "data-state" of the component. I would like to avoid using styled-components or custom CSS classes. How do I get the current state of data-props? |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 16 replies
-
Which component are you trying to retrieve the const [open, setOpen] = React.useState(false);
return (
<Dialog.Root open={open} onOpenChange={setOpen}>
<Dialog.Trigger className={open ? 'bg-blue-300' : 'bg-blue-500'}>Open</Dialog.Trigger>
<Dialog.Content />
</Dialog.Root>
); |
Beta Was this translation helpful? Give feedback.
-
@jjenzz how can we style using tw utility classes active tab in tabs component? |
Beta Was this translation helpful? Give feedback.
-
@jan-osch I maintain |
Beta Was this translation helpful? Give feedback.
-
The modern solution seems to be either: |
Beta Was this translation helpful? Give feedback.
-
The "styles-less" approach is truly bewildering. We have strayed so far from God's grace. Could literally just ship the CSS with variables and then require consumers to set top-level CSS variables rather than requiring brain surgery to use a component. All of web development has been cancelled until further notice. All websites are paused. |
Beta Was this translation helpful? Give feedback.
-
You can use radix-ui attributes like: With tailwind like this:
Incredibly useful - thanks Radix team! |
Beta Was this translation helpful? Give feedback.
-
To anyone who is reading this, recently I've just released a plugin that simplifies styling for Radix UI using Tailwind CSS. It works similarly with tailwindcss-radix but the difference is that it injects Radix UI common data attribute selectors directly to your You can then write Radix's state variants with the benefit of IntelliSense. For example: - class="data-[state=open]:..."
+ class="data-state-open:..." Personally I prefer this way because it feels more "idiomatic" as Tailwind CSS recently added support for data-attribute selectors. The plugin is heavily inspired by tailwindcss-radix, thanks @ecklf! |
Beta Was this translation helpful? Give feedback.
-
i just want to change button background LOL |
Beta Was this translation helpful? Give feedback.
-
I used different approaches to import radix-theme in SolidJS and Tailwind. I prefer the method of customizing based on copy-paste modification, so I provided a solution with CSS modules + CVA. https://github.com/FlatMapIO/radix-theme-solid-start?tab=readme-ov-file |
Beta Was this translation helpful? Give feedback.
The modern solution seems to be either:
A) Use this plugin by the author of that tailwindcss-radix app above which works (https://www.npmjs.com/package/tailwindcss-radix)
B) Target the data-state directly without a plugin with
data-[state=on]:opacity-40
for example