Skip to content

Commit cc6aaa2

Browse files
authored
Ensure the the <Popover.Panel focus> closes correctly (#1477)
* ensure the the `<Popover.Panel focus>` closes correctly * update changelog
1 parent 9280d92 commit cc6aaa2

File tree

7 files changed

+308
-227
lines changed

7 files changed

+308
-227
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Allow to override the `type` on the `ComboboxInput` ([#1476](https://github.com/tailwindlabs/headlessui/pull/1476))
13+
- Ensure the the `<PopoverPanel focus>` closes correctly ([#1477](https://github.com/tailwindlabs/headlessui/pull/1477))
1314

1415
## [Unreleased - @headlessui/react]
1516

1617
### Fixed
1718

1819
- Allow to override the `type` on the `Combobox.Input` ([#1476](https://github.com/tailwindlabs/headlessui/pull/1476))
20+
- Ensure the the `<Popover.Panel focus>` closes correctly ([#1477](https://github.com/tailwindlabs/headlessui/pull/1477))
1921

2022
## [@headlessui/vue@v1.6.2] - 2022-05-19
2123

packages/@headlessui-react/src/components/popover/popover.test.tsx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,7 @@ describe('Keyboard interactions', () => {
15001500

15011501
// Open the second popover
15021502
await click(getByText('Trigger 2'))
1503+
getByText('Trigger 2')?.focus()
15031504

15041505
// Ensure the second popover is open
15051506
assertPopoverButton({ state: PopoverState.Visible }, getByText('Trigger 2'))
@@ -2146,6 +2147,7 @@ describe('Mouse interactions', () => {
21462147

21472148
// Open popover
21482149
await click(getPopoverButton())
2150+
getPopoverButton()?.focus()
21492151

21502152
// Verify it is open
21512153
assertPopoverButton({ state: PopoverState.Visible })
@@ -2269,4 +2271,62 @@ describe('Mouse interactions', () => {
22692271
assertPopoverButton({ state: PopoverState.InvisibleHidden })
22702272
})
22712273
)
2274+
2275+
it(
2276+
'should be possible to close the Popover by clicking on the Popover.Button outside the Popover.Panel',
2277+
suppressConsoleLogs(async () => {
2278+
render(
2279+
<Popover>
2280+
<Popover.Button>Toggle</Popover.Button>
2281+
<Popover.Panel>
2282+
<button>Contents</button>
2283+
</Popover.Panel>
2284+
</Popover>
2285+
)
2286+
2287+
// Open the popover
2288+
await click(getPopoverButton())
2289+
2290+
// Verify it is open
2291+
assertPopoverPanel({ state: PopoverState.Visible })
2292+
2293+
// Close the popover
2294+
await click(getPopoverButton())
2295+
2296+
// Verify it is closed
2297+
assertPopoverPanel({ state: PopoverState.InvisibleUnmounted })
2298+
2299+
// Verify the button is focused
2300+
assertActiveElement(getPopoverButton())
2301+
})
2302+
)
2303+
2304+
it(
2305+
'should be possible to close the Popover by clicking on the Popover.Button outside the Popover.Panel (when using the `focus` prop)',
2306+
suppressConsoleLogs(async () => {
2307+
render(
2308+
<Popover>
2309+
<Popover.Button>Toggle</Popover.Button>
2310+
<Popover.Panel focus>
2311+
<button>Contents</button>
2312+
</Popover.Panel>
2313+
</Popover>
2314+
)
2315+
2316+
// Open the popover
2317+
await click(getPopoverButton())
2318+
2319+
// Verify it is open
2320+
assertPopoverPanel({ state: PopoverState.Visible })
2321+
2322+
// Close the popover
2323+
await click(getPopoverButton())
2324+
2325+
// Verify it is closed
2326+
assertPopoverPanel({ state: PopoverState.InvisibleUnmounted })
2327+
2328+
// Verify the button is focused
2329+
assertActiveElement(getPopoverButton())
2330+
})
2331+
)
22722332
})

0 commit comments

Comments
 (0)