headlessui | Completely unstyled , fully accessible UI components | User Interface library
kandi X-RAY | headlessui Summary
kandi X-RAY | headlessui Summary
Completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of headlessui
headlessui Key Features
headlessui Examples and Code Snippets
Community Discussions
Trending Discussions on headlessui
QUESTION
I need to display icons according to data.id
value, (the example icons display is in the comment code as well. can you suggest to me how to give an else if condition to display this icon according to the data.id
value?
ANSWER
Answered 2022-Mar-10 at 05:08Well, what you can do is put your item.icon div
in conditional render like below.
And use ternary operator
QUESTION
Previously I hardcoded the display icons in the array according to the array index. Now I got the array into a separate JSON file. Now I have loaded all the data from the JSON file. But icons all are the same. I need some "else if" conditions to load the icons according to array index** (the hardcoded version is given in the same file as a comment.) **as an example if the shirt I need to load the shirt icon. JSSON file array has sample data. I need to load an icon according to array index as the comment section code.
my JS file
...ANSWER
Answered 2022-Mar-09 at 13:02If you change your json file to js and have it something like this:
QUESTION
I have the following use case:
A user wants to toggle whether a profile is active or not.
Configuration: Next.js, Fauna DB, react-hook-form
I use useState to change the state on the toggle, and react-hook-forms to send other values to my Fauna database and the state from the toggle. I would like the toggle to have the state from the database, and when the user toggles it followed by a press on the submit button, I would like to change the state in the database.
I cannot seem to send the right state back to the database when I'm toggling it.
Main component:
...ANSWER
Answered 2022-Feb-27 at 13:45I made a small sandbox to demonstrate how you could implement your use case using react-hook-form
.
The reason it isn't working is, that you never update react-hook-form
's internal state when toggling the switch, you only update your useState
. So when you call handleUpdateUser
the data that is passed as the argument is the initial data you set via defaultValues
.
Actually there is no need to use useState
here, as you could just use react-hook-form
's internal form state. For this to work you have to use the component
react-hook-form
provides as the component from Headless UI
@headlessui/react
is an external controlled component which doesn't expose a ref
prop for an actual element (
uses a
instead of an
element). You can find more info here.
This way to you can also make your more generic for a reuse by providing a
value
and onChange
prop instead of status
and setStatus
. But of course you could also use these names still. The will provide a
value
and onChange
prop on the field
object which i spread on the component.
In your example it isn't clear how your component will receive the initial
userData
. I assumed you'd make an api request and so i put it in a useEffect
. To update the form state after the api call finished you have to use the reset
method react-hook-form
provides. If you only render when the
userData
is already loaded you can omit this step and just pass the result to the defaultValues
to useForm
.
I mocked the api calls with a simple Promise, but you should get the idea.
Component.js
QUESTION
I have recently started with Vue 3 and Headless UI.
I have created a ListBox
component which is used in App.vue
to show a list of People
and is working as intended.
I am looking to turn it into a reusable component for showing lists of both People
and Countries
.
How can I change my component to be dynamic for both types?
ListBox.vue
...ANSWER
Answered 2022-Feb-23 at 08:22You almost did what you want, only thing you need is props
.
people
and countries
are instance of your child component DataTable.vue
and you want to use them in a parent component App.vue
.
DataTable.vue :
QUESTION
I have a component which includes another component (from headlessui/react) defined as follows:
...ANSWER
Answered 2022-Feb-08 at 12:16This should works.
QUESTION
I am having a modal component shown below, which is opening by default because the open state is set to true.
...ANSWER
Answered 2022-Feb-07 at 14:16I'm sorry, I cannot exactly point out why your approach is wrong, but it just not how it works. Instead I would do something similar to this:
QUESTION
ANSWER
Answered 2022-Feb-06 at 13:26QUESTION
I have a navbar that uses HeadlessUI's Popover
on mobile for the hamburger menu. By default, this menu closes when you click out/focus on an element that is not in it.
Now I'm trying to add a modal (HeadlessUI Dialog
) that I want to open when clicking on a button that is in the popover menu. The modal is used within a ModalButton
component definition (<>
). This is done for separation of concerns (everything relating to the modal is within
ModalButton
).
The issue is: when I'm in the navbar's popover menu and click on the button to open the dialog. The browser focuses on this new dialog, and so the popover loses focus, making it close. Since it closed, the button (and thus the dialog sibling) are no longer rendered, and so the dialog disappears instantly.
For reference, this is a pseudocode of the react tree:
...ANSWER
Answered 2022-Jan-25 at 21:16You should put the dialog higher up in the tree. Usually these can go at the page level, or even the app level, depending on how global these dialogs are.
You can then use your favourite global state manager or the useContext
hook to tell these dialogs to open programmatically from anywhere in your app.
In which case the popover closing automatically shouldn't be an issue anymore.
QUESTION
I was using Tailwind v2 and when I am upgrading it to v3 it is giving me Postcss 8 Error (Error: PostCSS plugin tailwindcss requires PostCSS 8.). I tried to resolve this Error but did not succeed. Is there any way I can use Tailwind Cli in React Js. Error ScreenShoot
...ANSWER
Answered 2022-Jan-13 at 06:36tailwindcss v3 only supports Postcss8 and only create-react-app v5 supports Postcss8 for now. So you need to upgrade the create-react-app to v5. No need for craco in create-react-app v5 as well
First make sure to checkout to different branch or push your code to github before migrating, just for safety.
1.First run npm uninstall @craco/craco autoprefixer postcss tailwindcss
Delete the craco.config.js file
Delete the tailwind.config.js
Now just follow the offical tailwindcss docs
2. Run npm install -D tailwindcss postcss autoprefixer
3. npx tailwindcss init -p
copy paste the tailwind.config.js file from tailwindcss docs
4. npm install react-scripts@latest
5. Now npm start
Later paste your previous tailwind.config theme in the new tailwind.config.js file.
The order of steps may or may not matter but following this steps worked for me.
QUESTION
I want to use VueUse's virtual scroller composable to render the HeadlessUI's listbox content.
This is what I tried:
...ANSWER
Answered 2022-Jan-03 at 18:27Uncaught (in promise) TypeError: Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element'.
Looks like it is attempting to bind itself to something other than a native DOM element. In the example on the VueUse site they show native DOM elements with the v-bind
directive. However, your code uses v-bind
on non-native DOM elements, you have it on a VNode (the ListBox component).
Even looking at the source code you can see that the binding of containerProps
expects an HTMLElement
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install headlessui
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page