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 PopoverPanel can be used inside <transition> #1653

Merged
merged 4 commits into from
Jul 7, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@headlessui-react/src/test-utils/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export async function click(
) {
try {
if (element === null) return expect(element).not.toBe(null)
if (element.disabled) return
if (element instanceof HTMLButtonElement && element.disabled) return

let options = { button }

Expand Down
1 change: 1 addition & 0 deletions packages/@headlessui-vue/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix getting Vue dom elements ([#1610](https://github.com/tailwindlabs/headlessui/pull/1610))
- Ensure `CMD`+`Backspace` works in nullable mode for `Combobox` component ([#1617](https://github.com/tailwindlabs/headlessui/pull/1617))
- Properly merge incoming props with own props ([#1651](https://github.com/tailwindlabs/headlessui/pull/1651))
- Ensure `PopoverPanel` can be used inside `<transition>` ([#1653](https://github.com/tailwindlabs/headlessui/pull/1653))

## [1.6.5] - 2022-06-20

Expand Down
73 changes: 39 additions & 34 deletions packages/@headlessui-vue/src/components/popover/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ export let PopoverPanel = defineComponent({
function run() {
match(direction.value, {
[TabDirection.Forwards]: () => {
focusIn(el, Focus.First)
focusIn(el, Focus.Next)
},
[TabDirection.Backwards]: () => {
// Coming from the Popover.Panel (which is portalled to somewhere else). Let's redirect
Expand Down Expand Up @@ -592,7 +592,7 @@ export let PopoverPanel = defineComponent({

focusIn(combined, Focus.First, false)
},
[TabDirection.Backwards]: () => focusIn(el, Focus.Last),
[TabDirection.Backwards]: () => focusIn(el, Focus.Previous),
})
}

Expand All @@ -618,38 +618,43 @@ export let PopoverPanel = defineComponent({
tabIndex: -1,
}

return h(Fragment, [
visible.value &&
api.isPortalled.value &&
h(Hidden, {
id: beforePanelSentinelId,
ref: api.beforePanelSentinel,
features: HiddenFeatures.Focusable,
as: 'button',
type: 'button',
onFocus: handleBeforeFocus,
}),
render({
ourProps,
theirProps: { ...attrs, ...props },
slot,
attrs,
slots,
features: Features.RenderStrategy | Features.Static,
visible: visible.value,
name: 'PopoverPanel',
}),
visible.value &&
api.isPortalled.value &&
h(Hidden, {
id: afterPanelSentinelId,
ref: api.afterPanelSentinel,
features: HiddenFeatures.Focusable,
as: 'button',
type: 'button',
onFocus: handleAfterFocus,
}),
])
return render({
ourProps,
theirProps: { ...attrs, ...props },
attrs,
slot,
slots: {
...slots,
default: (...args) => [
h(Fragment, [
visible.value &&
api.isPortalled.value &&
h(Hidden, {
id: beforePanelSentinelId,
ref: api.beforePanelSentinel,
features: HiddenFeatures.Focusable,
as: 'button',
type: 'button',
onFocus: handleBeforeFocus,
}),
slots.default?.(...args),
visible.value &&
api.isPortalled.value &&
h(Hidden, {
id: afterPanelSentinelId,
ref: api.afterPanelSentinel,
features: HiddenFeatures.Focusable,
as: 'button',
type: 'button',
onFocus: handleAfterFocus,
}),
]),
],
},
features: Features.RenderStrategy | Features.Static,
visible: visible.value,
name: 'PopoverPanel',
})
}
},
})
Expand Down
2 changes: 1 addition & 1 deletion packages/@headlessui-vue/src/internal/focus-sentinel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export let FocusSentinel = defineComponent({

// Try to move focus to the correct element. This depends on the implementation
// of `onFocus` of course since it would be different for each place we use it in.
if (props.onFocus()) {
if (props.onFocus?.()) {
enabled.value = false
cancelAnimationFrame(frame)
return
Expand Down
2 changes: 1 addition & 1 deletion packages/@headlessui-vue/src/test-utils/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export async function click(
) {
try {
if (element === null) return expect(element).not.toBe(null)
if (element.disabled) return
if (element instanceof HTMLButtonElement && element.disabled) return

let options = { button }

Expand Down