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

fix(useElementBounding): call update on mounted (#626) #1541

Merged
merged 1 commit into from
May 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/core/useElementBounding/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ref, watch } from 'vue-demi'
import { tryOnMounted } from '@vueuse/shared'
import { useEventListener } from '../useEventListener'
import type { MaybeElementRef } from '../unrefElement'
import { unrefElement } from '../unrefElement'
Expand All @@ -24,6 +25,13 @@ export interface UseElementBoundingOptions {
* @default true
*/
windowScroll?: boolean

/**
* Immediately call update on component mounted
*
* @default true
*/
immediate?: boolean
}

/**
Expand All @@ -40,6 +48,7 @@ export function useElementBounding(
reset = true,
windowResize = true,
windowScroll = true,
immediate = true,
} = options

const height = ref(0)
Expand Down Expand Up @@ -88,6 +97,11 @@ export function useElementBounding(
if (windowResize)
useEventListener('resize', update, { passive: true })

tryOnMounted(() => {
if (immediate)
update()
})

return {
height,
bottom,
Expand Down