Git Product home page Git Product logo

Comments (2)

RobinMalfait avatar RobinMalfait commented on June 16, 2024 1

Hey!

The problem you are seeing is that the ui-open also applies because the Dialog also exposes that information. To solve this, you can explicitly mark the bg-white with ui-not-open:

- <Listbox.Button className="rounded-t-md rounded-b-md ui-open:rounded-b-none bg-white ui-open:bg-sky-300">
+ <Listbox.Button className="rounded-t-md rounded-b-md ui-open:rounded-b-none uit-not-open:bg-white ui-open:bg-sky-300">

It's a bit of an unfortunate situation, but this should solve your issue.
If this still won't work, then you can fallback to using JS based values using render props: https://headlessui.com/react/listbox#using-render-props

We are aware of this inconvenience, and to handle this in a more explicit and reliable way we made the following changes to the next versions of Headless UI and Tailwind CSS (both are currently in an alpha stage, but wanted to share this with you already):

  • In Headless UI v2, we expose these values as data attributes directly, this means that you will be able to use data-[open]:… directly.
  • In Tailwind CSS v4, data attributes will be available as data-open:… which is easier to type than data-[open]:….
  • If you combine these with named group classes (https://tailwindcss.com/docs/hover-focus-and-other-states#differentiating-nested-groups) then you can add a named group to the listbox and handle it explicitly:

This means that eventually, you will be able to do something like this to explicitly target the correct data:

<Listbox as="div" className="group/my-listbox">
  <ListboxButton className="group-data-open/my-listbox:…" />
</Listbox>

But for now, explicitly adding ui-not-open:bg-white or using the render prop should do the trick.

Hope this helps!

from headlessui.

anzuj avatar anzuj commented on June 16, 2024

@RobinMalfait truly, thank you for taking the time for such a comprehensive response! ui-not-open class indeed did the trick and the inputs within the dialog correctly get styled only when they are open. Appreciate the sneak peek to future features as well!

Would you perhaps have at hand any online codesandbox where @headlessui/tailwindcss plugin is working alongside @headlessui/react? It would be a hugely helpful asset to make online demos of HeadlessUI components for my team.

from headlessui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.