Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure
FocusTrap
is only active when the given enabled
value is `…
…true` (#2456) * fix(tabs): wrong tab focus when Tab contains a Dialog * refactor(focus-trap): rename variable and move logic * test(tabs): improve test by asserting the active element * ensure `FocusTrap` is not active when `enabled = false` * fix: move the enabled check to unmounting * refactor to `useOnUnmount` hook This will allow us to make the code relatively similar between React and Vue. * update changelog --------- Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
- Loading branch information
1 parent
159f04d
commit 5cfbb4b
Showing
7 changed files
with
163 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useRef, useEffect } from 'react' | ||
import { microTask } from '../utils/micro-task' | ||
|
||
export function useOnUnmount(cb: () => void) { | ||
let trulyUnmounted = useRef(false) | ||
useEffect(() => { | ||
trulyUnmounted.current = false | ||
|
||
return () => { | ||
trulyUnmounted.current = true | ||
microTask(() => { | ||
if (!trulyUnmounted.current) return | ||
|
||
cb() | ||
}) | ||
} | ||
}, []) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5cfbb4b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
headlessui-vue – ./packages/playground-vue
headlessui-vue.vercel.app
headlessui-vue-git-main-tailwindlabs.vercel.app
headlessui-vue-tailwindlabs.vercel.app
5cfbb4b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
headlessui-react – ./packages/playground-react
headlessui-react-git-main-tailwindlabs.vercel.app
headlessui-react-tailwindlabs.vercel.app
headlessui-react.vercel.app