v-click-outside

Directive

Calls a handler when a click lands outside the bound element. Supports Shadow DOM via handleShadow() and an optional closeConditional guard to suppress the callback.

API

Valeur / Arguments

Forme de la valeur du binding et de chaque propriété de l'objet d'options.

handler
requis
(e: MouseEvent) => void
Function called when a click lands outside the element. Also accepts the full options object in place of a bare function.
closeConditional
(e: Event) => boolean
Optional guard. The handler fires only when this function returns true. Useful to suppress callbacks while a panel is already closed.
include
() => HTMLElement[]
Returns a list of elements that should be treated as part of the component. Clicks on these elements do not trigger the handler.

The directive attaches listeners in capture phase on the document (or the nearest Shadow Root) so it intercepts clicks before any element handler can stop propagation.

Usage

Exemples

Extraits de code prêts à coller dans vos templates.

Basic usage

vue

With options (guard + include)

vue