### Basic Dropdown Menu Example
Source: https://headlessui.com/react/menu
A fundamental example demonstrating the Menu, MenuButton, MenuItems, and MenuItem components for creating a dropdown.
```jsx
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/react'
function Example() {
return (
My account
Settings
Support
License
)
}
```
--------------------------------
### Install Headless UI
Source: https://headlessui.com/react/button
Install the Headless UI library for React using npm.
```bash
npm install @headlessui/react
```
--------------------------------
### Basic Listbox Example
Source: https://headlessui.com/react/listbox
A fundamental example demonstrating the usage of Listbox, ListboxButton, ListboxOptions, and ListboxOption components. The ListboxButton toggles the ListboxOptions, which are keyboard-navigable when open.
```jsx
import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from '@headlessui/react'
import { useState } from 'react'
const people = [
{ id: 1, name: 'Durward Reynolds' },
{ id: 2, name: 'Kenton Towne' },
{ id: 3, name: 'Therese Wunsch' },
{ id: 4, name: 'Benedict Kessler' },
{ id: 5, name: 'Katelyn Rohan' },
]
function Example() {
const [selectedPerson, setSelectedPerson] = useState(people[0])
return (
{selectedPerson.name}
{people.map((person) => (
{person.name}
))}
)
}
```
--------------------------------
### Basic Select Example
Source: https://headlessui.com/react/select
A basic implementation of the Select component with options.
```jsx
import { Select } from '@headlessui/react'
function Example() {
return (
Active
Paused
Delayed
Canceled
)
}
```
--------------------------------
### Basic Radio Group Example
Source: https://headlessui.com/react/radio-group
A fundamental example demonstrating the usage of RadioGroup, Field, Label, and Radio components to create a selectable list.
```jsx
import { Field, Label, Radio, RadioGroup } from '@headlessui/react'
import { useState } from 'react'
const plans = ['Startup', 'Business', 'Enterprise']
function Example() {
let [selected, setSelected] = useState(plans[0])
return (
{plans.map((plan) => (
{plan}
))}
)
}
```
--------------------------------
### Basic Tab Group Example
Source: https://headlessui.com/react/tabs
A fundamental example demonstrating the structure of a tab interface using TabGroup, TabList, Tab, TabPanels, and TabPanel components. The first tab is selected by default.
```jsx
import { Tab, TabGroup, TabList, TabPanel, TabPanels } from '@headlessui/react'
function Example() {
return (
Tab 1
Tab 2
Tab 3
Content 1
Content 2
Content 3
)
}
```
--------------------------------
### Basic Switch Example
Source: https://headlessui.com/react/switch
A fundamental example of the Switch component. Toggling the switch calls the onChange function with a negated version of the checked value.
```jsx
import { Switch } from '@headlessui/react'
import { useState } from 'react'
function Example() {
const [enabled, setEnabled] = useState(false)
return (
)
}
```
--------------------------------
### Basic Combobox Example
Source: https://headlessui.com/react/combobox
A fundamental example of a Combobox component with filtering logic. It requires importing Combobox, ComboboxInput, ComboboxOption, and ComboboxOptions from '@headlessui/react'.
```jsx
import { Combobox, ComboboxInput, ComboboxOption, ComboboxOptions } from '@headlessui/react'
import { useState } from 'react'
const people = [
{ id: 1, name: 'Durward Reynolds' },
{ id: 2, name: 'Kenton Towne' },
{ id: 3, name: 'Therese Wunsch' },
{ id: 4, name: 'Benedict Kessler' },
{ id: 5, name: 'Katelyn Rohan' },
]
function Example() {
const [selectedPerson, setSelectedPerson] = useState(people[0])
const [query, setQuery] = useState('')
const filteredPeople =
query === ''
? people
: people.filter((person) => {
return person.name.toLowerCase().includes(query.toLowerCase())
})
return (
setQuery('')}>
person?.name}
onChange={(event) => setQuery(event.target.value)}
/>
{filteredPeople.map((person) => (
{person.name}
))}
)
}
```
--------------------------------
### Basic Disclosure Example
Source: https://headlessui.com/react/disclosure
A fundamental example demonstrating the Disclosure, DisclosureButton, and DisclosurePanel components. The button automatically toggles the panel, and accessibility attributes are managed by default.
```jsx
import { Disclosure, DisclosureButton, DisclosurePanel } from '@headlessui/react'
function Example() {
return (
Is team pricing available?
Yes! You can purchase a license that you can share with your entire team.
)
}
```
--------------------------------
### Rendered Checkbox Example (HTML)
Source: https://headlessui.com/react/checkbox
An example of how a Checkbox component might be rendered in HTML, showing the `data-checked` and `data-disabled` attributes.
```html
```
--------------------------------
### Basic Fieldset Example
Source: https://headlessui.com/react/fieldset
Demonstrates how to use the Fieldset, Legend, Field, Label, Input, Select, and Textarea components to create a grouped form with a title.
```APIDOC
## Basic Fieldset Example
Use the `Fieldset` and `Legend` components to group a set of form controls together with a title:
```javascript
import { Field, Fieldset, Input, Label, Legend, Select, Textarea } from '@headlessui/react'
function Example() {
return (
Shipping details
Street address
Country
Canada
Mexico
United States
Delivery notes
)
}
```
Since the native HTML `` element is difficult to style, the `Legend` component is rendered as a ``. The `
` component uses the native `` component.
```
--------------------------------
### Transition with appear prop
Source: https://headlessui.com/react/transition
Use the `appear` prop set to `true` on the `Transition` component to enable transitions on the initial mount. This example shows a div fading in.
```jsx
import { Transition } from '@headlessui/react'
import { useState } from 'react'
function Example() {
const [open, setOpen] = useState(true)
return (
<>
setOpen((open) => !open)}>Toggle
I will fade in on initial render
>
)
}
```
--------------------------------
### Basic Dialog Example
Source: https://headlessui.com/react/dialog
Demonstrates the basic usage of the Dialog component with DialogPanel, DialogTitle, and Description. Control dialog visibility using the `open` prop and handle closing with the `onClose` callback.
```jsx
import { Description, Dialog, DialogPanel, DialogTitle } from '@headlessui/react'
import { useState } from 'react'
function Example() {
let [isOpen, setIsOpen] = useState(false)
return (
<>
setIsOpen(true)}>Open dialog
setIsOpen(false)} className="relative z-50">
Deactivate account
This will permanently deactivate your account
Are you sure you want to deactivate your account? All of your data will be permanently removed.
setIsOpen(false)}>Cancel
setIsOpen(false)}>Deactivate
>
)
}
```
--------------------------------
### Basic Fieldset Example
Source: https://headlessui.com/react/fieldset
Use Fieldset and Legend components to group form controls with a title. Ensure all necessary components are imported from '@headlessui/react'.
```jsx
import { Field, Fieldset, Input, Label, Legend, Select, Textarea } from '@headlessui/react'
function Example() {
return (
Shipping details
Street address
Country
Canada
Mexico
United States
Delivery notes
)
}
```
--------------------------------
### Enter/Leave Transitions with Data Attributes
Source: https://headlessui.com/react/transition
Apply distinct transition styles for entering and leaving using `data-enter` and `data-leave` attributes. This example combines them with `data-closed` for specific start/end points and durations.
```jsx
import { Transition } from '@headlessui/react'
import clsx from 'clsx'
import { useState } from 'react'
function Example() {
const [open, setOpen] = useState(false)
return (
setOpen((open) => !open)}>Toggle
I will enter from the left and leave to the right
)
}
```
--------------------------------
### Using MenuItems with Buttons
Source: https://headlessui.com/react/menu
Demonstrates how to use `MenuItem` components with buttons to trigger actions, such as opening dialogs or submitting forms, within a `Menu` component. Includes examples of link and button `MenuItem` types.
```jsx
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/react'
function Example() {
function showSettingsDialog() {
alert('Open settings dialog!')
}
return (
My account
Settings
Support
License
)
}
```
--------------------------------
### Basic Popover Example
Source: https://headlessui.com/react/popover
A basic implementation of the Popover component using PopoverButton and PopoverPanel. Clicking the button toggles the panel, and it closes on outside click, Escape key, or tab away.
```jsx
import { Popover, PopoverButton, PopoverPanel } from '@headlessui/react'
function Example() {
return (
Solutions
Analytics
Engagement
Security
Integrations
)
}
```
--------------------------------
### Basic Checkbox Example
Source: https://headlessui.com/react/checkbox
A basic implementation of the Checkbox component. Toggles its state when clicked or when the spacebar is pressed while focused. The `onChange` function is called with the new checked state.
```jsx
import { Checkbox } from '@headlessui/react'
import { useState } from 'react'
function Example() {
const [enabled, setEnabled] = useState(false)
return (
{/* Checkmark icon */}
)
}
```
--------------------------------
### Set Dropdown Width with CSS
Source: https://headlessui.com/react/menu
Set a fixed width for the dropdown using the `className` prop on `MenuItems`. This example sets a width of 52 units.
```jsx
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/react'
function Example() {
return (
My account
Settings
Support
License
)
}
```
--------------------------------
### Render Menu as Custom Component and Elements
Source: https://headlessui.com/react/menu
Use the `as` prop to render Menu components as different HTML elements or custom React components. Ensure custom components forward refs. This example shows rendering MenuButton as a custom button and MenuItems as a section.
```jsx
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/react'
import { forwardRef } from 'react'
let MyCustomButton = forwardRef(function (props, ref) {
return
})
function Example() {
return (
My account
Settings
Support
License
)
}
```
--------------------------------
### Disclosure with Transitions
Source: https://headlessui.com/react/disclosure
Add animated opening and closing to the disclosure panel by using the `transition` prop on `DisclosurePanel` and applying CSS for transition stages. This example uses Tailwind CSS for styling.
```jsx
import { Disclosure, DisclosureButton, DisclosurePanel } from '@headlessui/react'
function Example() {
return (
Is team pricing available?
Yes! You can purchase a license that you can share with your entire team.
)
}
```
--------------------------------
### Custom Listbox with Buttonless API
Source: https://headlessui.com/react/listbox
This example demonstrates how to create a custom Listbox component that includes the button by default, making the `ListboxButton` component optional for the consumer. It utilizes `ListboxSelectedOption` to render the selected item and a placeholder.
```jsx
Active
Paused
Delayed
Canceled
```
```jsx
import { Listbox, ListboxButton, ListboxOption, ListboxOptions, ListboxSelectedOption } from '@headlessui/react'
import { Fragment, useState } from 'react'
const people = [
{ id: 1, name: 'Durward Reynolds' },
{ id: 2, name: 'Kenton Towne' },
{ id: 3, name: 'Therese Wunsch' },
{ id: 4, name: 'Benedict Kessler' },
{ id: 5, name: 'Katelyn Rohan' },
]
function Example() {
const [selectedPerson, setSelectedPerson] = useState(people[0])
return (
{people.map((person) => (
{person.name}
))}
)
}
function MyListbox({ placeholder, children, ...props }) {
return (
{placeholder}} />
{children}
)
}
function MyListboxOption({ children, ...props }) {
return (
{({ selectedOption }) => {
return selectedOption ? children : {children}
}}
)
}
```
--------------------------------
### Popover Styling with Data Attributes
Source: https://headlessui.com/react/popover
Demonstrates styling a Popover using data attributes, specifically `data-open`, which indicates the popover's open state. This example uses Tailwind CSS with the data attribute modifier.
```html
```
```jsx
import { Popover, PopoverButton, PopoverPanel } from '@headlessui/react'
import { ChevronDownIcon } from '@heroicons/react/20/solid'
function Example() {
return (
Solutions
Insights
Automations
Reports
)
}
```
--------------------------------
### Position Dropdown with Anchor Prop
Source: https://headlessui.com/react/menu
Use the `anchor` prop on `MenuItems` to automatically position the dropdown relative to the `MenuButton`. This example positions it to the bottom start.
```jsx
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/react'
function Example() {
return (
My account
Settings
Support
License
)
}
```
--------------------------------
### Rendering as Different Elements
Source: https://headlessui.com/react/popover
Explains how to use the `as` prop to render Popover components as different HTML elements or custom components.
```APIDOC
## Rendering as Different Elements
By default, the `Popover` and its subcomponents each render a default element that is sensible for that component. The `Popover`, `PopoverBackdrop`, `PopoverPanel`, and `PopoverGroup` components all render a ``, and the `PopoverButton` component renders a `
`.
Use the `as` prop to render the component as a different element or as your own custom component, making sure your custom components forward refs so that Headless UI can wire things up correctly.
```jsx
import { Popover, PopoverButton, PopoverPanel } from '@headlessui/react'
import { forwardRef } from 'react'
let MyCustomButton = forwardRef(function (props, ref) {
return
})
function Example() {
return (
Solutions
)
}
```
```
--------------------------------
### Grouping MenuItems into Sections
Source: https://headlessui.com/react/menu
Demonstrates how to group menu items into distinct sections using `MenuSection`, `MenuHeading`, and `MenuSeparator` components for enhanced menu organization and clarity.
```jsx
import { Menu, MenuButton, MenuHeading, MenuItem, MenuItems, MenuSection, MenuSeparator } from '@headlessui/react'
function Example() {
return (
My account
Settings
My profile
Notifications
Support
Documentation
License
)
}
```
--------------------------------
### Bind strings as values in Combobox
Source: https://headlessui.com/react/combobox
When binding simple string values, you can omit the `displayValue` prop from the `ComboboxInput`. This example demonstrates binding an array of strings.
```jsx
import { Combobox, ComboboxInput, ComboboxOption, ComboboxOptions } from '@headlessui/react'
import { useState } from 'react'
const people = ['Durward Reynolds', 'Kenton Towne', 'Therese Wunsch', 'Benedict Kessler', 'Katelyn Rohan']
function Example() {
const [selectedPerson, setSelectedPerson] = useState(people[0])
const [query, setQuery] = useState('')
const filteredPeople =
query === ''
? people
: people.filter((person) => {
return person.toLowerCase().includes(query.toLowerCase())
})
return (
setQuery('')}>
setQuery(event.target.value)} />
{filteredPeople.map((person) => (
{person}
))}
)
}
```
--------------------------------
### Setting Listbox Dropdown Width
Source: https://headlessui.com/react/listbox
Set a fixed width for the Listbox dropdown using the `className` prop on `ListboxOptions`. This example sets a width of 'w-52'.
```jsx
import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from '@headlessui/react'
import { useState } from 'react'
const people = [
{ id: 1, name: 'Durward Reynolds' },
{ id: 2, name: 'Kenton Towne' },
{ id: 3, name: 'Therese Wunsch' },
{ id: 4, name: 'Benedict Kessler' },
{ id: 5, name: 'Katelyn Rohan' },
]
function Example() {
const [selectedPerson, setSelectedPerson] = useState(people[0])
return (
{selectedPerson.name}
{people.map((person) => (
{person.name}
))}
)
}
```
--------------------------------
### Basic Fade Transition
Source: https://headlessui.com/react/transition
Use the `show` prop to control visibility and CSS with `data-closed` for fade-in/out effects. Styles defined with `data-closed` serve as both entry and exit points.
```jsx
import { Transition } from '@headlessui/react'
import { useState } from 'react'
function Example() {
const [open, setOpen] = useState(false)
return (
<>
setOpen((open) => !open)}>Toggle
I will fade in and out
>
)
}
```
--------------------------------
### Transition Component API
Source: https://headlessui.com/react/transition
Props available for the Transition component.
```APIDOC
## Transition Component API
### Props
| Prop | Default | Description |
|---|---|---|
| `as` | `Fragment` | `String | Component` The element or component the transition should render as. |
| `show` | — | `Boolean` Whether the children should be shown or hidden. |
| `appear` | `false` | `Boolean` Whether the transition should run on initial mount. |
| `unmount` | `true` | `Boolean` Whether the element should be unmounted or hidden based on the show state. |
| `beforeEnter` | — | `() => void` Callback which is called before we start the enter transition. |
| `afterEnter` | — | `() => void` Callback which is called after we finished the enter transition. |
| `beforeLeave` | — | `() => void` Callback which is called before we start the leave transition. |
| `afterLeave` | — | `() => void` Callback which is called after we finished the leave transition. |
```
--------------------------------
### Compare Objects by Field in Combobox
Source: https://headlessui.com/react/combobox
When binding objects, use the `by` prop to compare them by a specific field, defaulting to `id` if present. This example compares departments by their `name` field.
```jsx
import { Combobox, ComboboxInput, ComboboxOption, ComboboxOptions } from '@headlessui/react'
import { useState } from 'react'
const departments = [
{ name: 'Marketing', contact: 'Durward Reynolds' },
{ name: 'HR', contact: 'Kenton Towne' },
{ name: 'Sales', contact: 'Therese Wunsch' },
{ name: 'Finance', contact: 'Benedict Kessler' },
{ name: 'Customer service', contact: 'Katelyn Rohan' },
]
function DepartmentPicker({ selectedDepartment, onChange }) {
const [query, setQuery] = useState('')
const filteredDepartments =
query === ''
? departments
: departments.filter((department) => {
return department.name.toLowerCase().includes(query.toLowerCase())
})
return (
setQuery('')}>
department?.name}
onChange={(event) => setQuery(event.target.value)}
/>
{filteredDepartments.map((department) => (
{department.name}
))}
)
}
```
--------------------------------
### Disable Combobox Option
Source: https://headlessui.com/react/combobox
Prevent a specific `ComboboxOption` from being selected by using the `disabled` prop on the `ComboboxOption` component. This example shows disabling options based on an `available` property.
```javascript
import { Combobox, ComboboxInput, ComboboxOption, ComboboxOptions } from '@headlessui/react'
import { useState } from 'react'
const people = [
{ id: 1, name: 'Durward Reynolds', available: true },
{ id: 2, name: 'Kenton Towne', available: true },
{ id: 3, name: 'Therese Wunsch', available: true },
{ id: 4, name: 'Benedict Kessler', available: false },
{ id: 5, name: 'Katelyn Rohan', available: true },
]
function Example() {
const [selectedPerson, setSelectedPerson] = useState(people[0])
const [query, setQuery] = useState('')
const filteredPeople =
query === ''
? people
: people.filter((person) => {
return person.name.toLowerCase().includes(query.toLowerCase())
})
return (
setQuery('')}>
person?.name}
onChange={(event) => setQuery(event.target.value)}
/>
{filteredPeople.map((person) => (
{person.name}
))}
)
}
```
--------------------------------
### Styling a Dialog
Source: https://headlessui.com/react/dialog
Illustrates how to style the Dialog and DialogPanel components using the `className` prop. The dialog is initially open for demonstration purposes.
```jsx
import { Dialog, DialogPanel, DialogTitle } from '@headlessui/react'
import { useState } from 'react'
function Example() {
let [isOpen, setIsOpen] = useState(true)
return (
setIsOpen(false)} className="relative z-50">
Deactivate account order
{/* ... */}
)
}
```
--------------------------------
### Render Checkbox as a Div
Source: https://headlessui.com/react/checkbox
Use the `as` prop to render the Checkbox component as a `div` element. This example demonstrates controlling the checkbox state with React's `useState` hook.
```jsx
import { Checkbox } from '@headlessui/react'
import { useState } from 'react'
function Example() {
const [enabled, setEnabled] = useState(false)
return (
)
}
```
--------------------------------
### Closing Popovers Manually
Source: https://headlessui.com/react/popover
Demonstrates how to close popovers manually using `CloseButton`, the `close` render prop, and the `useClose` hook.
```APIDOC
## Closing Popovers Manually
### Using `CloseButton`
To close a popover manually when clicking a child of its panel, render that child as a `CloseButton`. You can use the `as` prop to customize which element is being rendered.
```jsx
import { CloseButton, Popover, PopoverButton, PopoverPanel } from '@headlessui/react'
import MyLink from './MyLink'
function Example() {
return (
Solutions
Insights
)
}
```
### Using the `close` Render Prop
The `Popover` and `PopoverPanel` expose a `close` render prop which you can use to imperatively close the panel, say after running an async action.
```jsx
import { Popover, PopoverButton, PopoverPanel } from '@headlessui/react'
function Example() {
return (
Terms
{({ close }) => (
{
await fetch('/accept-terms', { method: 'POST' })
close()
}}
>
Read and accept
)}
)
}
```
By default the `PopoverButton` receives focus after calling `close`, but you can change this by passing a ref into `close(ref)`.
### Using the `useClose` Hook
Headless UI also provides a `useClose` hook that can be used to imperatively close the nearest popover ancestor when you don't have easy access to the `close` render prop, such as in a nested component.
```jsx
import { Popover, PopoverButton, PopoverPanel, useClose } from '@headlessui/react'
function MySearchForm() {
let close = useClose()
return (
)
}
function Example() {
return (
Filters
)
}
```
The `useClose` hook must be used in a component that's nested within the `Popover`, otherwise it will not work.
```
--------------------------------
### Disabled Textarea within Field
Source: https://headlessui.com/react/textarea
Disable a Textarea, Label, and Description by adding the `disabled` prop to the Field component. This example also shows styling for disabled states.
```jsx
import { Description, Field, Label, Textarea } from '@headlessui/react'
function Example() {
return (
Name
Add any extra information about your event here.
)
}
```
--------------------------------
### Styling Fieldset with Data Attributes
Source: https://headlessui.com/react/fieldset
Style disabled fieldsets using the `data-disabled` attribute with CSS attribute selectors. This example uses Tailwind CSS with the `data-disabled` modifier.
```html
Shipping details
```
```jsx
import { Fieldset, Legend } from '@headlessui/react'
function Example() {
return (
Shipping details
{/* ... */}
)
}
```
--------------------------------
### Keyboard Interaction
Source: https://headlessui.com/react/menu
Defines the keyboard commands and their corresponding actions for interacting with the Menu component.
```APIDOC
## Keyboard interaction
Command| Description
---|---
`Enter` or `Space`when `MenuButton` is focused| Opens menu and focuses first non-disabled item
`ArrowDown` or `ArrowUp`when `MenuButton` is focused| Opens menu and focuses first/last non-disabled item
`Esc`when menu is open| Closes any open Menus
`ArrowDown` or `ArrowUp`when menu is open| Focuses previous/next non-disabled item
`Home` or `PageUp`when menu is open| Focuses first non-disabled item
`End` or `PageDown`when menu is open| Focuses last non-disabled item
`Enter` or `Space`when menu is open| Activates/clicks the current menu item
`A–Z` or `a–z`when menu is open| Focuses first item that matches keyboard input
```
--------------------------------
### Custom Object Comparison in Combobox
Source: https://headlessui.com/react/combobox
Provide a custom comparison function to the `by` prop for complete control over object comparison in a Combobox. This example uses a case-insensitive comparison of department names.
```jsx
import { Combobox, ComboboxInput, ComboboxOption, ComboboxOptions } from '@headlessui/react'
import { useState } from 'react'
const departments = [
{ id: 1, name: 'Marketing', contact: 'Durward Reynolds' },
{ id: 2, name: 'HR', contact: 'Kenton Towne' },
{ id: 3, name: 'Sales', contact: 'Therese Wunsch' },
{ id: 4, name: 'Finance', contact: 'Benedict Kessler' },
{ id: 5, name: 'Customer service', contact: 'Katelyn Rohan' },
]
function compareDepartments(a, b) {
return a.name.toLowerCase() === b.name.toLowerCase()
}
function DepartmentPicker({ selectedDepartment, onChange }) {
const [query, setQuery] = useState('')
const filteredDepartments =
query === ''
? departments
: departments.filter((department) => {
return department.name.toLowerCase().includes(query.toLowerCase())
})
return (
setQuery('')}>
department?.name}
onChange={(event) => setQuery(event.target.value)}
/>
{filteredDepartments.map((department) => (
```
--------------------------------
### Imperatively Close Disclosure with Render Prop
Source: https://headlessui.com/react/disclosure
Use the `close` render prop exposed by `DisclosurePanel` to imperatively close the panel, for example, after an asynchronous action like a fetch request.
```jsx
import { Disclosure, DisclosureButton, DisclosurePanel } from '@headlessui/react'
function Example() {
return (
Terms
{({ close }) => (
{
await fetch('/accept-terms', { method: 'POST' })
close()
}}
>
Read and accept
)}
)
}
```
--------------------------------
### Component API: Popover
Source: https://headlessui.com/react/popover
API documentation for the main `Popover` component, including its props and data attributes.
```APIDOC
## Component API
### Popover
The main popover component.
| Prop | Default | Description |
|---|---|---|
| `as` | `div` | `String | Component` The element or component the popover should render as. |
| Data Attribute | Render Prop | Description |
|---|---|---|
| `data-open` | `open` | `Boolean` Whether or not the popover is open. |
| — | `close` | `(ref) => void` Closes the popover and refocuses `PopoverButton`. Optionally pass in a **ref** or **HTMLElement** to focus that element instead. |
```
--------------------------------
### Styling Textarea with Data Attributes
Source: https://headlessui.com/react/textarea
Style the Textarea component using CSS attribute selectors based on `data-focus` and `data-hover` attributes. This example uses Tailwind CSS for styling.
```html
```
```jsx
import { Textarea } from '@headlessui/react'
function Example() {
return
}
```