Skip to main content
Vuetify0 is now in alpha!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

useClickOutside

A composable for detecting clicks outside of specified element(s) with automatic cleanup.


IntermediateApr 5, 2026

Usage

The useClickOutside composable detects when users click outside target elements. It uses two-phase detection (pointerdown → pointerup) to prevent false positives when dragging, and includes touch scroll handling for mobile.

vue
<script setup lang="ts">
  import { useClickOutside } from '@vuetify/v0'
  import { useTemplateRef } from 'vue'

  const menu = useTemplateRef('menu')

  useClickOutside(menu, () => {
    console.log('Clicked outside the menu')
  })
</script>

<template>
  <div ref="menu">
    Menu content
  </div>
</template>

Architecture

useClickOutside builds on useEventListener for pointer and focus event detection:

Click Outside Hierarchy

Use controls to zoom and pan. Click outside or press Escape to close.

Click Outside Hierarchy

Multiple Targets

Pass an array of refs to ignore clicks inside any of them:

ts
import { useClickOutside } from '@vuetify/v0'
import { useTemplateRef } from 'vue'

const trigger = useTemplateRef('trigger')
const panel = useTemplateRef('panel')

// Clicks inside EITHER trigger or panel are ignored
useClickOutside([trigger, panel], () => {
  console.log('Clicked outside both elements')
})

The target parameter accepts MaybeArray<ClickOutsideTarget> — a single ref/getter or an array of refs/getters.

Options

OptionTypeDefaultDescription
boundsbooleanfalseUse bounding-rect detection instead of DOM containment. Required for native <dialog> elements — backdrop clicks have the <dialog> as the event target, so containment checks always pass
ts
import { useClickOutside } from '@vuetify/v0'

const dialog = useTemplateRef('dialog')

// For native <dialog> — backdrop clicks are detected via coordinates
useClickOutside(dialog, () => dialog.value?.close(), { bounds: true })

Reactivity

Property/MethodReactiveNotes
isActiveComputed from !isPaused
isPausedShallowRef, readonly
pause()-Stop detection, preserve state
resume()-Resume detection
stop()-Stop and clean up listeners

Examples

A dropdown menu that opens on button click and automatically closes when clicking anywhere outside the menu.

API Reference

The following API details are for the useClickOutside composable.

Functions

useClickOutside

(target: MaybeArray<ClickOutsideTarget>, handler: (event: PointerEvent | FocusEvent) => void, options?: UseClickOutsideOptions) => UseClickOutsideReturn

Detects clicks outside of the specified element(s). Uses two-phase detection (pointerdown → pointerup) to prevent false positives when users drag from inside to outside an element.

Options

capture

boolean | undefined

Use capture phase for event listeners. Ensures detection works even when inner elements call stopPropagation.

Default: true

touchScrollThreshold

number | undefined

Touch movement threshold in pixels. If finger moves more than this distance, it's treated as a scroll, not a tap. Only applies to touch interactions.

Default: 30

detectIframe

boolean | undefined

Detect focus moving to iframes as an outside click. Useful when iframes are outside the target elements.

Default: false

ignore

MaybeRefOrGetter<ClickOutsideIgnoreTarget[]> | undefined

Elements to ignore when detecting outside clicks. Accepts element refs, getters, or CSS selector strings. Clicks on these elements (or their descendants) won't trigger the handler. Note: CSS selectors cannot match across Shadow DOM boundaries due to browser limitations. Use element refs instead when ignoring shadow hosts.

bounds

boolean | undefined

Use bounding rect instead of DOM containment to detect outside clicks. When true, checks if click coordinates are outside the element's bounding box. Useful for native <dialog> elements where backdrop clicks have the dialog as target.

Default: false

Properties

isActive

Readonly<Ref<boolean, boolean>>

Whether the listener is currently active

isPaused

Readonly<Ref<boolean, boolean>>

Whether the listener is currently paused

Methods

pause

() => void

Pause listening (stops detection but keeps state)

resume

() => void

Resume listening

stop

() => void

Stop listening and clean up

Was this page helpful?

© 2016-1970 Vuetify, LLC
Ctrl+/