diff --git a/packages/@headlessui-react/pages/transitions/component-examples/dropdown.tsx b/packages/@headlessui-react/pages/transitions/component-examples/dropdown.tsx
index f36d461..e391543 100644
--- a/packages/@headlessui-react/pages/transitions/component-examples/dropdown.tsx
+++ b/packages/@headlessui-react/pages/transitions/component-examples/dropdown.tsx
@@ -17,7 +17,7 @@ export default function Home() {
}
function Dropdown() {
- const [isOpen, setIsOpen] = useState(false)
+ let [isOpen, setIsOpen] = useState(false)
return (
diff --git a/packages/@headlessui-react/pages/transitions/component-examples/modal.tsx b/packages/@headlessui-react/pages/transitions/component-examples/modal.tsx
index 31e4a00..cd03991 100644
--- a/packages/@headlessui-react/pages/transitions/component-examples/modal.tsx
+++ b/packages/@headlessui-react/pages/transitions/component-examples/modal.tsx
@@ -2,14 +2,14 @@ import React, { useRef, useState } from 'react'
import { Transition } from '@headlessui/react'
export default function Home() {
- const [isOpen, setIsOpen] = useState(false)
+ let [isOpen, setIsOpen] = useState(false)
function toggle() {
setIsOpen(v => !v)
}
- const [email, setEmail] = useState('')
- const [events, setEvents] = useState([])
- const inputRef = useRef(null)
+ let [email, setEmail] = useState('')
+ let [events, setEvents] = useState([])
+ let inputRef = useRef(null)
function addEvent(name) {
setEvents(existing => [...existing, `${new Date().toJSON()} - ${name}`])
diff --git a/packages/@headlessui-react/pages/transitions/component-examples/nested/hidden.tsx b/packages/@headlessui-react/pages/transitions/component-examples/nested/hidden.tsx
index 7cec0cc..989f266 100644
--- a/packages/@headlessui-react/pages/transitions/component-examples/nested/hidden.tsx
+++ b/packages/@headlessui-react/pages/transitions/component-examples/nested/hidden.tsx
@@ -1,8 +1,8 @@
-import React, { useState } from 'react'
+import React, { useState, ReactNode } from 'react'
import { Transition } from '@headlessui/react'
export default function Home() {
- const [isOpen, setIsOpen] = useState(true)
+ let [isOpen, setIsOpen] = useState(true)
return (
<>
@@ -40,7 +40,7 @@ export default function Home() {
)
}
-function Box({ children }: { children?: React.ReactNode }) {
+function Box({ children }: { children?: ReactNode }) {
return (
@@ -40,7 +40,7 @@ export default function Home() {
)
}
-function Box({ children }: { children?: React.ReactNode }) {
+function Box({ children }: { children?: ReactNode }) {
return (
diff --git a/packages/@headlessui-react/pages/transitions/full-page-examples/full-page-transition.tsx b/packages/@headlessui-react/pages/transitions/full-page-examples/full-page-transition.tsx
index feab22c..33a96ea 100644
--- a/packages/@headlessui-react/pages/transitions/full-page-examples/full-page-transition.tsx
+++ b/packages/@headlessui-react/pages/transitions/full-page-examples/full-page-transition.tsx
@@ -21,7 +21,7 @@ export default function Shell() {
}
function usePrevious(value: T) {
- const ref = useRef(value)
+ let ref = useRef(value)
useEffect(() => {
ref.current = value
}, [value])
@@ -33,8 +33,8 @@ enum Direction {
Backwards = ' <- ',
}
-const pages = ['Dashboard', 'Team', 'Projects', 'Calendar', 'Reports']
-const colors = [
+let pages = ['Dashboard', 'Team', 'Projects', 'Calendar', 'Reports']
+let colors = [
'bg-gradient-to-r from-teal-400 to-blue-400',
'bg-gradient-to-r from-blue-400 to-orange-400',
'bg-gradient-to-r from-orange-400 to-purple-400',
@@ -43,12 +43,12 @@ const colors = [
]
function FullPageTransition() {
- const [activePage, setActivePage] = useState(0)
- const previousPage = usePrevious(activePage)
+ let [activePage, setActivePage] = useState(0)
+ let previousPage = usePrevious(activePage)
- const direction = activePage > previousPage ? Direction.Forwards : Direction.Backwards
+ let direction = activePage > previousPage ? Direction.Forwards : Direction.Backwards
- const transitions = match(direction, {
+ let transitions = match(direction, {
[Direction.Forwards]: {
enter: 'transition transform ease-in-out duration-500',
enterFrom: 'translate-x-full',
diff --git a/packages/@headlessui-react/pages/transitions/full-page-examples/layout-with-sidebar.tsx b/packages/@headlessui-react/pages/transitions/full-page-examples/layout-with-sidebar.tsx
index f6b3129..0cc33e0 100644
--- a/packages/@headlessui-react/pages/transitions/full-page-examples/layout-with-sidebar.tsx
+++ b/packages/@headlessui-react/pages/transitions/full-page-examples/layout-with-sidebar.tsx
@@ -3,7 +3,7 @@ import Head from 'next/head'
import { Transition } from '@headlessui/react'
export default function App() {
- const [mobileOpen, setMobileOpen] = useState(false)
+ let [mobileOpen, setMobileOpen] = useState(false)
useEffect(() => {
function handleEscape(event) {
diff --git a/packages/@headlessui-react/playground-utils/hooks/use-popper.ts b/packages/@headlessui-react/playground-utils/hooks/use-popper.ts
index ddd9445..4d10885 100644
--- a/packages/@headlessui-react/playground-utils/hooks/use-popper.ts
+++ b/packages/@headlessui-react/playground-utils/hooks/use-popper.ts
@@ -1,4 +1,4 @@
-import React from 'react'
+import { RefCallback, useRef, useCallback, useMemo } from 'react'
import { createPopper, Options } from '@popperjs/core'
/**
@@ -6,13 +6,13 @@ import { createPopper, Options } from '@popperjs/core'
*/
export function usePopper(
options?: Partial
-): [React.RefCallback, React.RefCallback] {
- const reference = React.useRef(null)
- const popper = React.useRef(null)
+): [RefCallback, RefCallback] {
+ let reference = useRef(null)
+ let popper = useRef(null)
- const cleanupCallback = React.useRef(() => {})
+ let cleanupCallback = useRef(() => {})
- const instantiatePopper = React.useCallback(() => {
+ let instantiatePopper = useCallback(() => {
if (!reference.current) return
if (!popper.current) return
@@ -21,7 +21,7 @@ export function usePopper(
cleanupCallback.current = createPopper(reference.current, popper.current, options).destroy
}, [reference, popper, cleanupCallback, options])
- return React.useMemo(
+ return useMemo(
() => [
referenceDomNode => {
reference.current = referenceDomNode
diff --git a/packages/@headlessui-react/playground-utils/resolve-all-examples.ts b/packages/@headlessui-react/playground-utils/resolve-all-examples.ts
index 7f500a6..397c367 100644
--- a/packages/@headlessui-react/playground-utils/resolve-all-examples.ts
+++ b/packages/@headlessui-react/playground-utils/resolve-all-examples.ts
@@ -7,14 +7,14 @@ export type ExamplesType = {
}
export async function resolveAllExamples(...paths: string[]) {
- const base = path.resolve(process.cwd(), ...paths)
+ let base = path.resolve(process.cwd(), ...paths)
if (!fs.existsSync(base)) {
return false
}
- const files = await fs.promises.readdir(base, { withFileTypes: true })
- const items: ExamplesType[] = []
+ let files = await fs.promises.readdir(base, { withFileTypes: true })
+ let items: ExamplesType[] = []
for (let file of files) {
// Skip reserved filenames from Next. E.g.: _app.tsx, _error.tsx
@@ -22,7 +22,7 @@ export async function resolveAllExamples(...paths: string[]) {
continue
}
- const bucket: ExamplesType = {
+ let bucket: ExamplesType = {
name: file.name.replace(/-/g, ' ').replace(/\.tsx?/g, ''),
path: [...paths, file.name]
.join('/')
@@ -32,7 +32,7 @@ export async function resolveAllExamples(...paths: string[]) {
}
if (file.isDirectory()) {
- const children = await resolveAllExamples(...paths, file.name)
+ let children = await resolveAllExamples(...paths, file.name)
if (children) {
bucket.children = children
diff --git a/packages/@headlessui-react/src/components/listbox/listbox.test.tsx b/packages/@headlessui-react/src/components/listbox/listbox.test.tsx
index a84bed5..953c81a 100644
--- a/packages/@headlessui-react/src/components/listbox/listbox.test.tsx
+++ b/packages/@headlessui-react/src/components/listbox/listbox.test.tsx
@@ -1,4 +1,4 @@
-import React from 'react'
+import React, { createElement, useState } from 'react'
import { render } from '@testing-library/react'
import { Listbox } from './listbox'
@@ -54,7 +54,7 @@ describe('safeguards', () => {
])(
'should error when we are using a <%s /> without a parent ',
suppressConsoleLogs((name, Component) => {
- expect(() => render(React.createElement(Component))).toThrowError(
+ expect(() => render(createElement(Component))).toThrowError(
`<${name} /> is missing a parent component.`
)
})
@@ -426,7 +426,7 @@ describe('Rendering composition', () => {
// Open Listbox
await click(getListboxButton())
- const options = getListboxOptions()
+ let options = getListboxOptions()
// Verify correct classNames
expect('' + options[0].classList).toEqual(
@@ -545,7 +545,7 @@ describe('Keyboard interactions', () => {
assertListboxButtonLinkedWithListbox()
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach(option => assertListboxOption(option, { selected: false }))
@@ -626,7 +626,7 @@ describe('Keyboard interactions', () => {
assertListboxButtonLinkedWithListbox()
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach((option, i) => assertListboxOption(option, { selected: i === 1 }))
@@ -670,7 +670,7 @@ describe('Keyboard interactions', () => {
assertActiveElement(getListbox())
assertListboxButtonLinkedWithListbox()
- const options = getListboxOptions()
+ let options = getListboxOptions()
// Hover over Option A
await mouseMove(options[0])
@@ -699,12 +699,12 @@ describe('Keyboard interactions', () => {
it(
'should be possible to open the listbox with Enter, and focus the selected option (with a list of objects)',
suppressConsoleLogs(async () => {
- const myOptions = [
+ let myOptions = [
{ id: 'a', name: 'Option A' },
{ id: 'b', name: 'Option B' },
{ id: 'c', name: 'Option C' },
]
- const selectedOption = myOptions[1]
+ let selectedOption = myOptions[1]
render(
Trigger
@@ -740,7 +740,7 @@ describe('Keyboard interactions', () => {
assertListboxButtonLinkedWithListbox()
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach((option, i) => assertListboxOption(option, { selected: i === 1 }))
@@ -801,7 +801,7 @@ describe('Keyboard interactions', () => {
// Open listbox
await press(Keys.Enter)
- const options = getListboxOptions()
+ let options = getListboxOptions()
// Verify that the first non-disabled listbox option is active
assertActiveListboxOption(options[1])
@@ -838,7 +838,7 @@ describe('Keyboard interactions', () => {
// Open listbox
await press(Keys.Enter)
- const options = getListboxOptions()
+ let options = getListboxOptions()
// Verify that the first non-disabled listbox option is active
assertActiveListboxOption(options[2])
@@ -922,10 +922,10 @@ describe('Keyboard interactions', () => {
it(
'should be possible to close the listbox with Enter and choose the active listbox option',
suppressConsoleLogs(async () => {
- const handleChange = jest.fn()
+ let handleChange = jest.fn()
function Example() {
- const [value, setValue] = React.useState(undefined)
+ let [value, setValue] = useState(undefined)
return (
{
assertListboxButton({ state: ListboxState.Visible })
// Activate the first listbox option
- const options = getListboxOptions()
+ let options = getListboxOptions()
await mouseMove(options[0])
// Choose option, and close listbox
@@ -1023,7 +1023,7 @@ describe('Keyboard interactions', () => {
assertListboxButtonLinkedWithListbox()
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach(option => assertListboxOption(option))
assertActiveListboxOption(options[0])
@@ -1101,7 +1101,7 @@ describe('Keyboard interactions', () => {
assertListboxButtonLinkedWithListbox()
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach((option, i) => assertListboxOption(option, { selected: i === 1 }))
@@ -1162,7 +1162,7 @@ describe('Keyboard interactions', () => {
// Open listbox
await press(Keys.Space)
- const options = getListboxOptions()
+ let options = getListboxOptions()
// Verify that the first non-disabled listbox option is active
assertActiveListboxOption(options[1])
@@ -1199,7 +1199,7 @@ describe('Keyboard interactions', () => {
// Open listbox
await press(Keys.Space)
- const options = getListboxOptions()
+ let options = getListboxOptions()
// Verify that the first non-disabled listbox option is active
assertActiveListboxOption(options[2])
@@ -1245,10 +1245,10 @@ describe('Keyboard interactions', () => {
it(
'should be possible to close the listbox with Space and choose the active listbox option',
suppressConsoleLogs(async () => {
- const handleChange = jest.fn()
+ let handleChange = jest.fn()
function Example() {
- const [value, setValue] = React.useState(undefined)
+ let [value, setValue] = useState(undefined)
return (
{
assertListboxButton({ state: ListboxState.Visible })
// Activate the first listbox option
- const options = getListboxOptions()
+ let options = getListboxOptions()
await mouseMove(options[0])
// Choose option, and close listbox
@@ -1389,7 +1389,7 @@ describe('Keyboard interactions', () => {
assertListboxButtonLinkedWithListbox()
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach(option => assertListboxOption(option))
assertActiveListboxOption(options[0])
@@ -1440,7 +1440,7 @@ describe('Keyboard interactions', () => {
assertListboxButtonLinkedWithListbox()
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach(option => assertListboxOption(option))
assertActiveListboxOption(options[0])
@@ -1493,7 +1493,7 @@ describe('Keyboard interactions', () => {
assertListboxButtonLinkedWithListbox()
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach(option => assertListboxOption(option))
@@ -1573,7 +1573,7 @@ describe('Keyboard interactions', () => {
assertListboxButtonLinkedWithListbox()
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach((option, i) => assertListboxOption(option, { selected: i === 1 }))
@@ -1633,7 +1633,7 @@ describe('Keyboard interactions', () => {
await press(Keys.Enter)
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach(option => assertListboxOption(option))
assertActiveListboxOption(options[0])
@@ -1681,7 +1681,7 @@ describe('Keyboard interactions', () => {
await press(Keys.Enter)
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach(option => assertListboxOption(option))
assertActiveListboxOption(options[1])
@@ -1723,7 +1723,7 @@ describe('Keyboard interactions', () => {
await press(Keys.Enter)
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach(option => assertListboxOption(option))
assertActiveListboxOption(options[2])
@@ -1768,7 +1768,7 @@ describe('Keyboard interactions', () => {
assertListboxButtonLinkedWithListbox()
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach(option => assertListboxOption(option))
@@ -1848,7 +1848,7 @@ describe('Keyboard interactions', () => {
assertListboxButtonLinkedWithListbox()
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach((option, i) => assertListboxOption(option, { selected: i === 1 }))
@@ -1912,7 +1912,7 @@ describe('Keyboard interactions', () => {
await press(Keys.ArrowUp)
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach(option => assertListboxOption(option))
assertActiveListboxOption(options[0])
@@ -1950,7 +1950,7 @@ describe('Keyboard interactions', () => {
await press(Keys.Enter)
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach(option => assertListboxOption(option))
assertActiveListboxOption(options[2])
@@ -2001,7 +2001,7 @@ describe('Keyboard interactions', () => {
assertListboxButtonLinkedWithListbox()
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach(option => assertListboxOption(option))
assertActiveListboxOption(options[2])
@@ -2042,7 +2042,7 @@ describe('Keyboard interactions', () => {
// Open listbox
await press(Keys.Enter)
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be on the first option
assertActiveListboxOption(options[0])
@@ -2078,7 +2078,7 @@ describe('Keyboard interactions', () => {
// Open listbox
await press(Keys.Enter)
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be on the first option
assertActiveListboxOption(options[0])
@@ -2119,7 +2119,7 @@ describe('Keyboard interactions', () => {
// We should not be able to go to the end
await press(Keys.End)
- const options = getListboxOptions()
+ let options = getListboxOptions()
assertActiveListboxOption(options[0])
})
)
@@ -2182,7 +2182,7 @@ describe('Keyboard interactions', () => {
// Open listbox
await press(Keys.Enter)
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be on the first option
assertActiveListboxOption(options[0])
@@ -2218,7 +2218,7 @@ describe('Keyboard interactions', () => {
// Open listbox
await press(Keys.Enter)
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be on the first option
assertActiveListboxOption(options[0])
@@ -2259,7 +2259,7 @@ describe('Keyboard interactions', () => {
// We should not be able to go to the end
await press(Keys.PageDown)
- const options = getListboxOptions()
+ let options = getListboxOptions()
assertActiveListboxOption(options[0])
})
)
@@ -2322,7 +2322,7 @@ describe('Keyboard interactions', () => {
// Open listbox
await press(Keys.ArrowUp)
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be on the last option
assertActiveListboxOption(options[2])
@@ -2361,7 +2361,7 @@ describe('Keyboard interactions', () => {
// We should not be able to go to the end
await press(Keys.Home)
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be on the first non-disabled option
assertActiveListboxOption(options[2])
@@ -2398,7 +2398,7 @@ describe('Keyboard interactions', () => {
// We should not be able to go to the end
await press(Keys.Home)
- const options = getListboxOptions()
+ let options = getListboxOptions()
assertActiveListboxOption(options[3])
})
)
@@ -2461,7 +2461,7 @@ describe('Keyboard interactions', () => {
// Open listbox
await press(Keys.ArrowUp)
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be on the last option
assertActiveListboxOption(options[2])
@@ -2500,7 +2500,7 @@ describe('Keyboard interactions', () => {
// We should not be able to go to the end
await press(Keys.PageUp)
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be on the first non-disabled option
assertActiveListboxOption(options[2])
@@ -2537,7 +2537,7 @@ describe('Keyboard interactions', () => {
// We should not be able to go to the end
await press(Keys.PageUp)
- const options = getListboxOptions()
+ let options = getListboxOptions()
assertActiveListboxOption(options[3])
})
)
@@ -2597,7 +2597,7 @@ describe('Keyboard interactions', () => {
// Open listbox
await click(getListboxButton())
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be able to go to the second option
await type(word('bob'))
@@ -2633,7 +2633,7 @@ describe('Keyboard interactions', () => {
// Open listbox
await press(Keys.ArrowUp)
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be on the last option
assertActiveListboxOption(options[2])
@@ -2672,7 +2672,7 @@ describe('Keyboard interactions', () => {
// Open listbox
await press(Keys.ArrowUp)
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be on the last option
assertActiveListboxOption(options[2])
@@ -2713,7 +2713,7 @@ describe('Keyboard interactions', () => {
// Open listbox
await press(Keys.ArrowUp)
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be on the last option
assertActiveListboxOption(options[2])
@@ -2814,7 +2814,7 @@ describe('Mouse interactions', () => {
assertListboxButtonLinkedWithListbox()
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach(option => assertListboxOption(option))
})
@@ -2913,7 +2913,7 @@ describe('Mouse interactions', () => {
assertListboxButtonLinkedWithListbox()
// Verify we have listbox options
- const options = getListboxOptions()
+ let options = getListboxOptions()
expect(options).toHaveLength(3)
options.forEach((option, i) => assertListboxOption(option, { selected: i === 1 }))
@@ -3031,7 +3031,7 @@ describe('Mouse interactions', () => {
)
- const [button1, button2] = getListboxButtons()
+ let [button1, button2] = getListboxButtons()
// Click the first menu button
await click(button1)
@@ -3097,7 +3097,7 @@ describe('Mouse interactions', () => {
// Open listbox
await click(getListboxButton())
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be able to go to the second option
await mouseMove(options[1])
assertActiveListboxOption(options[1])
@@ -3129,7 +3129,7 @@ describe('Mouse interactions', () => {
// Open listbox
await click(getListboxButton())
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be able to go to the second option
await mouseMove(options[1])
assertActiveListboxOption(options[1])
@@ -3153,7 +3153,7 @@ describe('Mouse interactions', () => {
// Open listbox
await click(getListboxButton())
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be able to go to the second option
await mouseMove(options[1])
@@ -3185,7 +3185,7 @@ describe('Mouse interactions', () => {
// Open listbox
await click(getListboxButton())
- const options = getListboxOptions()
+ let options = getListboxOptions()
await mouseMove(options[1])
assertNoActiveListboxOption()
@@ -3211,7 +3211,7 @@ describe('Mouse interactions', () => {
// Open listbox
await click(getListboxButton())
- const options = getListboxOptions()
+ let options = getListboxOptions()
// Try to hover over option 1, which is disabled
await mouseMove(options[1])
@@ -3238,7 +3238,7 @@ describe('Mouse interactions', () => {
// Open listbox
await click(getListboxButton())
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be able to go to the second option
await mouseMove(options[1])
@@ -3282,7 +3282,7 @@ describe('Mouse interactions', () => {
// Open listbox
await click(getListboxButton())
- const options = getListboxOptions()
+ let options = getListboxOptions()
// Try to hover over option 1, which is disabled
await mouseMove(options[1])
@@ -3296,9 +3296,9 @@ describe('Mouse interactions', () => {
it(
'should be possible to click a listbox option, which closes the listbox',
suppressConsoleLogs(async () => {
- const handleChange = jest.fn()
+ let handleChange = jest.fn()
function Example() {
- const [value, setValue] = React.useState(undefined)
+ let [value, setValue] = useState(undefined)
return (
{
assertListbox({ state: ListboxState.Visible })
assertActiveElement(getListbox())
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be able to click the first option
await click(options[1])
@@ -3347,9 +3347,9 @@ describe('Mouse interactions', () => {
it(
'should be possible to click a disabled listbox option, which is a no-op',
suppressConsoleLogs(async () => {
- const handleChange = jest.fn()
+ let handleChange = jest.fn()
function Example() {
- const [value, setValue] = React.useState(undefined)
+ let [value, setValue] = useState(undefined)
return (
{
assertListbox({ state: ListboxState.Visible })
assertActiveElement(getListbox())
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should be able to click the first option
await click(options[1])
@@ -3416,7 +3416,7 @@ describe('Mouse interactions', () => {
assertListbox({ state: ListboxState.Visible })
assertActiveElement(getListbox())
- const options = getListboxOptions()
+ let options = getListboxOptions()
// Verify that nothing is active yet
assertNoActiveListboxOption()
@@ -3448,7 +3448,7 @@ describe('Mouse interactions', () => {
assertListbox({ state: ListboxState.Visible })
assertActiveElement(getListbox())
- const options = getListboxOptions()
+ let options = getListboxOptions()
// We should not be able to focus the first option
await focus(options[1])
diff --git a/packages/@headlessui-react/src/components/listbox/listbox.tsx b/packages/@headlessui-react/src/components/listbox/listbox.tsx
index 13a3d0e..eb1c3a2 100644
--- a/packages/@headlessui-react/src/components/listbox/listbox.tsx
+++ b/packages/@headlessui-react/src/components/listbox/listbox.tsx
@@ -1,4 +1,22 @@
-import * as React from 'react'
+import React, {
+ createContext,
+ createRef,
+ useCallback,
+ useContext,
+ useEffect,
+ useMemo,
+ useReducer,
+ useRef,
+ Fragment,
+
+ // Types
+ Dispatch,
+ ElementType,
+ KeyboardEvent as ReactKeyboardEvent,
+ MouseEvent as ReactMouseEvent,
+ MutableRefObject,
+ Ref,
+} from 'react'
import { useDisposables } from '../../hooks/use-disposables'
import { useId } from '../../hooks/use-id'
@@ -19,18 +37,18 @@ enum ListboxStates {
Closed,
}
-type ListboxOptionDataRef = React.MutableRefObject<{
+type ListboxOptionDataRef = MutableRefObject<{
textValue?: string
disabled: boolean
value: unknown
}>
-type StateDefinition = {
+interface StateDefinition {
listboxState: ListboxStates
- propsRef: React.MutableRefObject<{ value: unknown; onChange(value: unknown): void }>
- labelRef: React.MutableRefObject
- buttonRef: React.MutableRefObject
- optionsRef: React.MutableRefObject
+ propsRef: MutableRefObject<{ value: unknown; onChange(value: unknown): void }>
+ labelRef: MutableRefObject
+ buttonRef: MutableRefObject
+ optionsRef: MutableRefObject
options: { id: string; dataRef: ListboxOptionDataRef }[]
searchQuery: string
activeOptionIndex: number | null
@@ -58,7 +76,7 @@ type Actions =
| { type: ActionTypes.RegisterOption; id: string; dataRef: ListboxOptionDataRef }
| { type: ActionTypes.UnregisterOption; id: string }
-const reducers: {
+let reducers: {
[P in ActionTypes]: (
state: StateDefinition,
action: Extract
@@ -71,7 +89,7 @@ const reducers: {
}),
[ActionTypes.OpenListbox]: state => ({ ...state, listboxState: ListboxStates.Open }),
[ActionTypes.GoToOption]: (state, action) => {
- const activeOptionIndex = calculateActiveIndex(action, {
+ let activeOptionIndex = calculateActiveIndex(action, {
resolveItems: () => state.options,
resolveActiveIndex: () => state.activeOptionIndex,
resolveId: item => item.id,
@@ -82,8 +100,8 @@ const reducers: {
return { ...state, searchQuery: '', activeOptionIndex }
},
[ActionTypes.Search]: (state, action) => {
- const searchQuery = state.searchQuery + action.value
- const match = state.options.findIndex(
+ let searchQuery = state.searchQuery + action.value
+ let match = state.options.findIndex(
option =>
!option.dataRef.current.disabled &&
option.dataRef.current.textValue?.startsWith(searchQuery)
@@ -98,11 +116,11 @@ const reducers: {
options: [...state.options, { id: action.id, dataRef: action.dataRef }],
}),
[ActionTypes.UnregisterOption]: (state, action) => {
- const nextOptions = state.options.slice()
- const currentActiveOption =
+ let nextOptions = state.options.slice()
+ let currentActiveOption =
state.activeOptionIndex !== null ? nextOptions[state.activeOptionIndex] : null
- const idx = nextOptions.findIndex(a => a.id === action.id)
+ let idx = nextOptions.findIndex(a => a.id === action.id)
if (idx !== -1) nextOptions.splice(idx, 1)
@@ -121,13 +139,13 @@ const reducers: {
},
}
-const ListboxContext = React.createContext<[StateDefinition, React.Dispatch] | null>(null)
+let ListboxContext = createContext<[StateDefinition, Dispatch] | null>(null)
ListboxContext.displayName = 'ListboxContext'
function useListboxContext(component: string) {
- const context = React.useContext(ListboxContext)
+ let context = useContext(ListboxContext)
if (context === null) {
- const err = new Error(`<${component} /> is missing a parent <${Listbox.name} /> component.`)
+ let err = new Error(`<${component} /> is missing a parent <${Listbox.name} /> component.`)
if (Error.captureStackTrace) Error.captureStackTrace(err, useListboxContext)
throw err
}
@@ -140,31 +158,30 @@ function stateReducer(state: StateDefinition, action: Actions) {
// ---
-const DEFAULT_LISTBOX_TAG = React.Fragment
-type ListboxRenderPropArg = { open: boolean }
+let DEFAULT_LISTBOX_TAG = Fragment
+interface ListboxRenderPropArg {
+ open: boolean
+}
-export function Listbox<
- TTag extends React.ElementType = typeof DEFAULT_LISTBOX_TAG,
- TType = string
->(
+export function Listbox(
props: Props & {
value: TType
onChange(value: TType): void
}
) {
- const { value, onChange, ...passThroughProps } = props
- const d = useDisposables()
- const reducerBag = React.useReducer(stateReducer, {
+ let { value, onChange, ...passThroughProps } = props
+ let d = useDisposables()
+ let reducerBag = useReducer(stateReducer, {
listboxState: ListboxStates.Closed,
propsRef: { current: { value, onChange } },
- labelRef: React.createRef(),
- buttonRef: React.createRef(),
- optionsRef: React.createRef(),
+ labelRef: createRef(),
+ buttonRef: createRef(),
+ optionsRef: createRef(),
options: [],
searchQuery: '',
activeOptionIndex: null,
} as StateDefinition)
- const [{ listboxState, propsRef, optionsRef, buttonRef }, dispatch] = reducerBag
+ let [{ listboxState, propsRef, optionsRef, buttonRef }, dispatch] = reducerBag
useIsoMorphicEffect(() => {
propsRef.current.value = value
@@ -173,10 +190,10 @@ export function Listbox<
propsRef.current.onChange = onChange
}, [onChange, propsRef])
- React.useEffect(() => {
+ useEffect(() => {
function handler(event: MouseEvent) {
- const target = event.target as HTMLElement
- const active = document.activeElement
+ let target = event.target as HTMLElement
+ let active = document.activeElement
if (listboxState !== ListboxStates.Open) return
if (buttonRef.current?.contains(target)) return
@@ -190,7 +207,7 @@ export function Listbox<
return () => window.removeEventListener('mousedown', handler)
}, [listboxState, optionsRef, buttonRef, d, dispatch])
- const propsBag = React.useMemo(
+ let propsBag = useMemo(
() => ({ open: listboxState === ListboxStates.Open }),
[listboxState]
)
@@ -204,8 +221,10 @@ export function Listbox<
// ---
-const DEFAULT_BUTTON_TAG = 'button'
-type ButtonRenderPropArg = { open: boolean }
+let DEFAULT_BUTTON_TAG = 'button' as const
+interface ButtonRenderPropArg {
+ open: boolean
+}
type ButtonPropsWeControl =
| 'id'
| 'type'
@@ -216,20 +235,18 @@ type ButtonPropsWeControl =
| 'onKeyDown'
| 'onClick'
-const Button = forwardRefWithAs(function Button<
- TTag extends React.ElementType = typeof DEFAULT_BUTTON_TAG
->(
+let Button = forwardRefWithAs(function Button(
props: Props,
- ref: React.Ref
+ ref: Ref
) {
- const [state, dispatch] = useListboxContext([Listbox.name, Button.name].join('.'))
- const buttonRef = useSyncRefs(state.buttonRef, ref)
+ let [state, dispatch] = useListboxContext([Listbox.name, Button.name].join('.'))
+ let buttonRef = useSyncRefs(state.buttonRef, ref)
- const id = `headlessui-listbox-button-${useId()}`
- const d = useDisposables()
+ let id = `headlessui-listbox-button-${useId()}`
+ let d = useDisposables()
- const handleKeyDown = React.useCallback(
- (event: React.KeyboardEvent) => {
+ let handleKeyDown = useCallback(
+ (event: ReactKeyboardEvent) => {
switch (event.key) {
// Ref: https://www.w3.org/TR/wai-aria-practices-1.2/#keyboard-interaction-13
@@ -259,8 +276,8 @@ const Button = forwardRefWithAs(function Button<
[dispatch, state, d]
)
- const handleClick = React.useCallback(
- (event: React.MouseEvent) => {
+ let handleClick = useCallback(
+ (event: ReactMouseEvent) => {
if (isDisabledReactIssue7711(event.currentTarget)) return event.preventDefault()
if (props.disabled) return
if (state.listboxState === ListboxStates.Open) {
@@ -275,17 +292,17 @@ const Button = forwardRefWithAs(function Button<
[dispatch, d, state, props.disabled]
)
- const labelledby = useComputed(() => {
+ let labelledby = useComputed(() => {
if (!state.labelRef.current) return undefined
return [state.labelRef.current.id, id].join(' ')
}, [state.labelRef.current, id])
- const propsBag = React.useMemo(
+ let propsBag = useMemo(
() => ({ open: state.listboxState === ListboxStates.Open }),
[state]
)
- const passthroughProps = props
- const propsWeControl = {
+ let passthroughProps = props
+ let propsWeControl = {
ref: buttonRef,
id,
type: 'button',
@@ -302,33 +319,36 @@ const Button = forwardRefWithAs(function Button<
// ---
-const DEFAULT_LABEL_TAG = 'label'
+let DEFAULT_LABEL_TAG = 'label' as const
+interface LabelRenderPropArg {
+ open: boolean
+}
type LabelPropsWeControl = 'id' | 'ref' | 'onClick'
-type LabelRenderPropArg = { open: boolean }
-function Label(
+function Label(
props: Props
) {
- const [state] = useListboxContext([Listbox.name, Label.name].join('.'))
- const id = `headlessui-listbox-label-${useId()}`
+ let [state] = useListboxContext([Listbox.name, Label.name].join('.'))
+ let id = `headlessui-listbox-label-${useId()}`
- const handleClick = React.useCallback(
- () => state.buttonRef.current?.focus({ preventScroll: true }),
- [state.buttonRef]
- )
+ let handleClick = useCallback(() => state.buttonRef.current?.focus({ preventScroll: true }), [
+ state.buttonRef,
+ ])
- const propsBag = React.useMemo(
+ let propsBag = useMemo(
() => ({ open: state.listboxState === ListboxStates.Open }),
[state]
)
- const propsWeControl = { ref: state.labelRef, id, onClick: handleClick }
+ let propsWeControl = { ref: state.labelRef, id, onClick: handleClick }
return render({ ...props, ...propsWeControl }, propsBag, DEFAULT_LABEL_TAG)
}
// ---
-const DEFAULT_OPTIONS_TAG = 'ul'
-type OptionsRenderPropArg = { open: boolean }
+let DEFAULT_OPTIONS_TAG = 'ul' as const
+interface OptionsRenderPropArg {
+ open: boolean
+}
type OptionsPropsWeControl =
| 'aria-activedescendant'
| 'aria-labelledby'
@@ -337,24 +357,24 @@ type OptionsPropsWeControl =
| 'role'
| 'tabIndex'
-const OptionsRenderFeatures = Features.RenderStrategy | Features.Static
+let OptionsRenderFeatures = Features.RenderStrategy | Features.Static
-const Options = forwardRefWithAs(function Options<
- TTag extends React.ElementType = typeof DEFAULT_OPTIONS_TAG
+let Options = forwardRefWithAs(function Options<
+ TTag extends ElementType = typeof DEFAULT_OPTIONS_TAG
>(
props: Props &
PropsForFeatures,
- ref: React.Ref
+ ref: Ref
) {
- const [state, dispatch] = useListboxContext([Listbox.name, Options.name].join('.'))
- const optionsRef = useSyncRefs(state.optionsRef, ref)
+ let [state, dispatch] = useListboxContext([Listbox.name, Options.name].join('.'))
+ let optionsRef = useSyncRefs(state.optionsRef, ref)
- const id = `headlessui-listbox-options-${useId()}`
- const d = useDisposables()
- const searchDisposables = useDisposables()
+ let id = `headlessui-listbox-options-${useId()}`
+ let d = useDisposables()
+ let searchDisposables = useDisposables()
- const handleKeyDown = React.useCallback(
- (event: React.KeyboardEvent) => {
+ let handleKeyDown = useCallback(
+ (event: ReactKeyboardEvent) => {
searchDisposables.dispose()
switch (event.key) {
@@ -371,7 +391,7 @@ const Options = forwardRefWithAs(function Options<
event.preventDefault()
dispatch({ type: ActionTypes.CloseListbox })
if (state.activeOptionIndex !== null) {
- const { dataRef } = state.options[state.activeOptionIndex]
+ let { dataRef } = state.options[state.activeOptionIndex]
state.propsRef.current.onChange(dataRef.current.value)
}
disposables().nextFrame(() => state.buttonRef.current?.focus({ preventScroll: true }))
@@ -414,16 +434,16 @@ const Options = forwardRefWithAs(function Options<
[d, dispatch, searchDisposables, state]
)
- const labelledby = useComputed(() => state.labelRef.current?.id ?? state.buttonRef.current?.id, [
+ let labelledby = useComputed(() => state.labelRef.current?.id ?? state.buttonRef.current?.id, [
state.labelRef.current,
state.buttonRef.current,
])
- const propsBag = React.useMemo(
+ let propsBag = useMemo(
() => ({ open: state.listboxState === ListboxStates.Open }),
[state]
)
- const propsWeControl = {
+ let propsWeControl = {
'aria-activedescendant':
state.activeOptionIndex === null ? undefined : state.options[state.activeOptionIndex]?.id,
'aria-labelledby': labelledby,
@@ -433,7 +453,7 @@ const Options = forwardRefWithAs(function Options<
tabIndex: 0,
ref: optionsRef,
}
- const passthroughProps = props
+ let passthroughProps = props
return render(
{ ...passthroughProps, ...propsWeControl },
@@ -446,8 +466,12 @@ const Options = forwardRefWithAs(function Options<
// ---
-const DEFAULT_OPTION_TAG = 'li'
-type OptionRenderPropArg = { active: boolean; selected: boolean; disabled: boolean }
+let DEFAULT_OPTION_TAG = 'li' as const
+interface OptionRenderPropArg {
+ active: boolean
+ selected: boolean
+ disabled: boolean
+}
type ListboxOptionPropsWeControl =
| 'id'
| 'role'
@@ -461,7 +485,7 @@ type ListboxOptionPropsWeControl =
| 'onFocus'
function Option<
- TTag extends React.ElementType = typeof DEFAULT_OPTION_TAG,
+ TTag extends ElementType = typeof DEFAULT_OPTION_TAG,
// TODO: One day we will be able to infer this type from the generic in Listbox itself.
// But today is not that day..
TType = Parameters[0]['value']
@@ -474,14 +498,14 @@ function Option<
className?: ((bag: OptionRenderPropArg) => string) | string
}
) {
- const { disabled = false, value, className, ...passthroughProps } = props
- const [state, dispatch] = useListboxContext([Listbox.name, Option.name].join('.'))
- const id = `headlessui-listbox-option-${useId()}`
- const active =
+ let { disabled = false, value, className, ...passthroughProps } = props
+ let [state, dispatch] = useListboxContext([Listbox.name, Option.name].join('.'))
+ let id = `headlessui-listbox-option-${useId()}`
+ let active =
state.activeOptionIndex !== null ? state.options[state.activeOptionIndex].id === id : false
- const selected = state.propsRef.current.value === value
+ let selected = state.propsRef.current.value === value
- const bag = React.useRef({ disabled, value })
+ let bag = useRef({ disabled, value })
useIsoMorphicEffect(() => {
bag.current.disabled = disabled
@@ -493,10 +517,7 @@ function Option<
bag.current.textValue = document.getElementById(id)?.textContent?.toLowerCase()
}, [bag, id])
- const select = React.useCallback(() => state.propsRef.current.onChange(value), [
- state.propsRef,
- value,
- ])
+ let select = useCallback(() => state.propsRef.current.onChange(value), [state.propsRef, value])
useIsoMorphicEffect(() => {
dispatch({ type: ActionTypes.RegisterOption, id, dataRef: bag })
@@ -513,12 +534,12 @@ function Option<
useIsoMorphicEffect(() => {
if (state.listboxState !== ListboxStates.Open) return
if (!active) return
- const d = disposables()
+ let d = disposables()
d.nextFrame(() => document.getElementById(id)?.scrollIntoView?.({ block: 'nearest' }))
return d.dispose
}, [active, state.listboxState])
- const handleClick = React.useCallback(
+ let handleClick = useCallback(
(event: { preventDefault: Function }) => {
if (disabled) return event.preventDefault()
select()
@@ -528,29 +549,25 @@ function Option<
[dispatch, state.buttonRef, disabled, select]
)
- const handleFocus = React.useCallback(() => {
+ let handleFocus = useCallback(() => {
if (disabled) return dispatch({ type: ActionTypes.GoToOption, focus: Focus.Nothing })
dispatch({ type: ActionTypes.GoToOption, focus: Focus.Specific, id })
}, [disabled, id, dispatch])
- const handleMove = React.useCallback(() => {
+ let handleMove = useCallback(() => {
if (disabled) return
if (active) return
dispatch({ type: ActionTypes.GoToOption, focus: Focus.Specific, id })
}, [disabled, active, id, dispatch])
- const handleLeave = React.useCallback(() => {
+ let handleLeave = useCallback(() => {
if (disabled) return
if (!active) return
dispatch({ type: ActionTypes.GoToOption, focus: Focus.Nothing })
}, [disabled, active, dispatch])
- const propsBag = React.useMemo(() => ({ active, selected, disabled }), [
- active,
- selected,
- disabled,
- ])
- const propsWeControl = {
+ let propsBag = useMemo(() => ({ active, selected, disabled }), [active, selected, disabled])
+ let propsWeControl = {
id,
role: 'option',
tabIndex: -1,
diff --git a/packages/@headlessui-react/src/components/menu/menu.test.tsx b/packages/@headlessui-react/src/components/menu/menu.test.tsx
index 802ed5b..357d65b 100644
--- a/packages/@headlessui-react/src/components/menu/menu.test.tsx
+++ b/packages/@headlessui-react/src/components/menu/menu.test.tsx
@@ -1,4 +1,4 @@
-import React from 'react'
+import React, { createElement } from 'react'
import { render } from '@testing-library/react'
import { Menu } from './menu'
@@ -48,7 +48,7 @@ describe('Safe guards', () => {
])(
'should error when we are using a <%s /> without a parent ',
suppressConsoleLogs((name, Component) => {
- expect(() => render(React.createElement(Component))).toThrowError(
+ expect(() => render(createElement(Component))).toThrowError(
`<${name} /> is missing a parent component.`
)
})
@@ -321,7 +321,7 @@ describe('Rendering composition', () => {
// Open menu
await click(getMenuButton())
- const items = getMenuItems()
+ let items = getMenuItems()
// Verify correct classNames
expect('' + items[0].classList).toEqual(JSON.stringify({ active: false, disabled: false }))
@@ -379,7 +379,7 @@ describe('Rendering composition', () => {
await click(getMenuButton())
// Verify items are buttons now
- const items = getMenuItems()
+ let items = getMenuItems()
items.forEach(item => assertMenuItem(item, { tag: 'button' }))
})
)
@@ -422,7 +422,7 @@ describe('Keyboard interactions', () => {
assertMenuButtonLinkedWithMenu()
// Verify we have menu items
- const items = getMenuItems()
+ let items = getMenuItems()
expect(items).toHaveLength(3)
items.forEach(item => assertMenuItem(item))
@@ -517,7 +517,7 @@ describe('Keyboard interactions', () => {
// Open menu
await press(Keys.Enter)
- const items = getMenuItems()
+ let items = getMenuItems()
// Verify that the first non-disabled menu item is active
assertMenuLinkedWithMenuItem(items[1])
@@ -554,7 +554,7 @@ describe('Keyboard interactions', () => {
// Open menu
await press(Keys.Enter)
- const items = getMenuItems()
+ let items = getMenuItems()
// Verify that the first non-disabled menu item is active
assertMenuLinkedWithMenuItem(items[2])
@@ -638,7 +638,7 @@ describe('Keyboard interactions', () => {
it(
'should be possible to close the menu with Enter and invoke the active menu item',
suppressConsoleLogs(async () => {
- const clickHandler = jest.fn()
+ let clickHandler = jest.fn()
render(
)
- const [button1, button2] = getMenuButtons()
+ let [button1, button2] = getMenuButtons()
// Click the first menu button
await click(button1)
@@ -2637,7 +2637,7 @@ describe('Mouse interactions', () => {
// Open menu
await click(getMenuButton())
- const items = getMenuItems()
+ let items = getMenuItems()
// We should be able to go to the second item
await mouseMove(items[1])
assertMenuLinkedWithMenuItem(items[1])
@@ -2669,7 +2669,7 @@ describe('Mouse interactions', () => {
// Open menu
await click(getMenuButton())
- const items = getMenuItems()
+ let items = getMenuItems()
// We should be able to go to the second item
await mouseMove(items[1])
assertMenuLinkedWithMenuItem(items[1])
@@ -2693,7 +2693,7 @@ describe('Mouse interactions', () => {
// Open menu
await click(getMenuButton())
- const items = getMenuItems()
+ let items = getMenuItems()
// We should be able to go to the second item
await mouseMove(items[1])
@@ -2725,7 +2725,7 @@ describe('Mouse interactions', () => {
// Open menu
await click(getMenuButton())
- const items = getMenuItems()
+ let items = getMenuItems()
await mouseMove(items[1])
assertNoActiveMenuItem()
@@ -2751,7 +2751,7 @@ describe('Mouse interactions', () => {
// Open menu
await click(getMenuButton())
- const items = getMenuItems()
+ let items = getMenuItems()
// Try to hover over item 1, which is disabled
await mouseMove(items[1])
@@ -2778,7 +2778,7 @@ describe('Mouse interactions', () => {
// Open menu
await click(getMenuButton())
- const items = getMenuItems()
+ let items = getMenuItems()
// We should be able to go to the second item
await mouseMove(items[1])
@@ -2822,7 +2822,7 @@ describe('Mouse interactions', () => {
// Open menu
await click(getMenuButton())
- const items = getMenuItems()
+ let items = getMenuItems()
// Try to hover over item 1, which is disabled
await mouseMove(items[1])
@@ -2836,7 +2836,7 @@ describe('Mouse interactions', () => {
it(
'should be possible to click a menu item, which closes the menu',
suppressConsoleLogs(async () => {
- const clickHandler = jest.fn()
+ let clickHandler = jest.fn()
render(