Skip to content

Commit f3c70aa

Browse files
authored
Fix Dialog usage in Tabs (#1149)
* only record the restoreElement once enabled Currently we are collecting the `restoreElement` even if the focus trap is not enabled. When we unmount we try to restore it. The problem is the moment you unmount you want to restore but only if the focus trap was enabled. Another issue is that the dialog state will be `closed` before we get to the `onUmount` hook. So there is probably a cleaner way to fix this, but this does the trick as well where we only record the restoreElement the moment the focus trap gets enabled. * update changelog
1 parent 26670d2 commit f3c70aa

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
- Make sure that the input syncs when the combobox closes ([#1137](https://github.com/tailwindlabs/headlessui/pull/1137))
1919
- Ensure that you can close the combobox initially ([#1148](https://github.com/tailwindlabs/headlessui/pull/1148))
20+
- Fix Dialog usage in Tabs ([#1149](https://github.com/tailwindlabs/headlessui/pull/1149))
2021

2122
## [@headlessui/react@v1.5.0] - 2022-02-17
2223

packages/@headlessui-vue/src/hooks/use-focus-trap.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ export function useFocusTrap(
1818
enabled: Ref<boolean> = ref(true),
1919
options: Ref<{ initialFocus?: HTMLElement | null }> = ref({})
2020
) {
21-
let restoreElement = ref<HTMLElement | null>(
22-
typeof window !== 'undefined' ? (document.activeElement as HTMLElement) : null
23-
)
21+
let restoreElement = ref<HTMLElement | null>(null)
2422
let previousActiveElement = ref<HTMLElement | null>(null)
2523

2624
function handleFocus() {

0 commit comments

Comments
 (0)