Listen for clicks outside of an element. Useful for modal or dropdown.



  <div ref="target">
    Hello world
    Outside element

import { ref } from 'vue'
import { onClickOutside } from '@vueuse/core'

export default {
  setup() {
    const target = ref(null)

    onClickOutside(target, (event) => console.log(event))

    return { target }

This function uses Event.composedPath() which is NOT supported by IE 11, Edge 18 and below. If you are targeting these browsers, we recommend you to include this code snippet on your project.


<OnClickOutside @trigger="count++">
    Click Outside of Me
Learn more about component usage

Type Declarations

export declare type OnClickOutsideEvents = Pick<
  | "click"
  | "mousedown"
  | "mouseup"
  | "touchstart"
  | "touchend"
  | "pointerdown"
  | "pointerup"
export interface OnClickOutsideOptions<E extends keyof OnClickOutsideEvents>
  extends ConfigurableWindow {
  event?: E
 * Listen for clicks outside of an element.
 * @see https://vueuse.org/onClickOutside
 * @param target
 * @param handler
 * @param options
export declare function onClickOutside<
  E extends keyof OnClickOutsideEvents = "pointerdown"
  target: MaybeElementRef,
  handler: (evt: OnClickOutsideEvents[E]) => void,
  options?: OnClickOutsideOptions<E>
): Fn | undefined