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

Improve performance of internal useInertOthers hook #3181

Merged
merged 2 commits into from
May 7, 2024
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
4 changes: 3 additions & 1 deletion packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet!
### Fixed

- Improve performance of internal `useInertOthers` hook ([#3181](https://github.com/tailwindlabs/headlessui/pull/3181))

## [2.0.1] - 2024-05-06

Expand Down
8 changes: 4 additions & 4 deletions packages/@headlessui-react/src/hooks/use-inert-others.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ function markNotInert(element: HTMLElement) {
*/
export function useInertOthers(
{
allowed = () => [],
disallowed = () => [],
allowed,
disallowed,
}: { allowed?: () => (HTMLElement | null)[]; disallowed?: () => (HTMLElement | null)[] } = {},
enabled = true
) {
Expand All @@ -85,14 +85,14 @@ export function useInertOthers(
let d = disposables()

// Mark all disallowed elements as inert
for (let element of disallowed()) {
for (let element of disallowed?.() ?? []) {
if (!element) continue

d.add(markInert(element))
}

// Mark all siblings of allowed elements (and parents) as inert
let allowedElements = allowed()
let allowedElements = allowed?.() ?? []

for (let element of allowedElements) {
if (!element) continue
Expand Down
Loading