Skip to content

Commit

Permalink
inline disposables call
Browse files Browse the repository at this point in the history
Each function in the `disposables()` object returns a cleanup function
which means we can return this directly.
  • Loading branch information
RobinMalfait committed Jun 2, 2024
1 parent 5d98f9d commit d1308c8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1210,11 +1210,9 @@ function OptionFn<
if (data.listboxState !== ListboxStates.Open) return
if (!active) return
if (data.activationTrigger === ActivationTrigger.Pointer) return
let d = disposables()
d.requestAnimationFrame(() => {
return disposables().requestAnimationFrame(() => {
internalOptionRef.current?.scrollIntoView?.({ block: 'nearest' })
})
return d.dispose
}, [
internalOptionRef,
active,
Expand Down
4 changes: 1 addition & 3 deletions packages/@headlessui-react/src/components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -844,11 +844,9 @@ function ItemFn<TTag extends ElementType = typeof DEFAULT_ITEM_TAG>(
if (state.menuState !== MenuStates.Open) return
if (!active) return
if (state.activationTrigger === ActivationTrigger.Pointer) return
let d = disposables()
d.requestAnimationFrame(() => {
return disposables().requestAnimationFrame(() => {
internalItemRef.current?.scrollIntoView?.({ block: 'nearest' })
})
return d.dispose
}, [
state.__demoMode,
internalItemRef,
Expand Down

0 comments on commit d1308c8

Please sign in to comment.