Skip to content

Commit

Permalink
fix(useElementByPoint): make document configurable (#2614)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaakian committed Jan 4, 2023
1 parent 48e01d6 commit c363935
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/core/useElementByPoint/index.ts
Expand Up @@ -2,8 +2,10 @@ import { ref } from 'vue-demi'
import type { MaybeComputedRef } from '@vueuse/shared'
import { resolveUnref } from '@vueuse/shared'
import { useRafFn } from '../useRafFn'
import type { ConfigurableDocument } from '../_configurable'
import { defaultDocument } from '../_configurable'

export interface UseElementByPointOptions {
export interface UseElementByPointOptions extends ConfigurableDocument {
x: MaybeComputedRef<number>
y: MaybeComputedRef<number>
}
Expand All @@ -17,10 +19,10 @@ export interface UseElementByPointOptions {
export function useElementByPoint(options: UseElementByPointOptions) {
const element = ref<HTMLElement | null>(null)

const { x, y } = options
const { x, y, document = defaultDocument } = options

const controls = useRafFn(() => {
element.value = document.elementFromPoint(resolveUnref(x), resolveUnref(y)) as HTMLElement | null
element.value = (document?.elementFromPoint(resolveUnref(x), resolveUnref(y)) || null) as HTMLElement | null
})

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/guide/config.md
Expand Up @@ -69,7 +69,7 @@ const parentMousePos = useMouse({ window: window.parent })
const iframe = document.querySelect('#my-iframe')

// accessing child context
const childMousePos = useMouse({ window: iframe.contextWindow })
const childMousePos = useMouse({ window: iframe.contentWindow })
```

```ts
Expand Down

0 comments on commit c363935

Please sign in to comment.