Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure the the <Popover.Panel focus> closes correctly #1477

Merged
merged 2 commits into from May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,12 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

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

## [Unreleased - @headlessui/react]

### Fixed

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

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

Expand Down
60 changes: 60 additions & 0 deletions packages/@headlessui-react/src/components/popover/popover.test.tsx
Expand Up @@ -1500,6 +1500,7 @@ describe('Keyboard interactions', () => {

// Open the second popover
await click(getByText('Trigger 2'))
getByText('Trigger 2')?.focus()

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

// Open popover
await click(getPopoverButton())
getPopoverButton()?.focus()

// Verify it is open
assertPopoverButton({ state: PopoverState.Visible })
Expand Down Expand Up @@ -2269,4 +2271,62 @@ describe('Mouse interactions', () => {
assertPopoverButton({ state: PopoverState.InvisibleHidden })
})
)

it(
'should be possible to close the Popover by clicking on the Popover.Button outside the Popover.Panel',
suppressConsoleLogs(async () => {
render(
<Popover>
<Popover.Button>Toggle</Popover.Button>
<Popover.Panel>
<button>Contents</button>
</Popover.Panel>
</Popover>
)

// Open the popover
await click(getPopoverButton())

// Verify it is open
assertPopoverPanel({ state: PopoverState.Visible })

// Close the popover
await click(getPopoverButton())

// Verify it is closed
assertPopoverPanel({ state: PopoverState.InvisibleUnmounted })

// Verify the button is focused
assertActiveElement(getPopoverButton())
})
)

it(
'should be possible to close the Popover by clicking on the Popover.Button outside the Popover.Panel (when using the `focus` prop)',
suppressConsoleLogs(async () => {
render(
<Popover>
<Popover.Button>Toggle</Popover.Button>
<Popover.Panel focus>
<button>Contents</button>
</Popover.Panel>
</Popover>
)

// Open the popover
await click(getPopoverButton())

// Verify it is open
assertPopoverPanel({ state: PopoverState.Visible })

// Close the popover
await click(getPopoverButton())

// Verify it is closed
assertPopoverPanel({ state: PopoverState.InvisibleUnmounted })

// Verify the button is focused
assertActiveElement(getPopoverButton())
})
)
})