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
Value / Arguments
Shape of the binding value and each property in the options object.
- handlerrequired(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
Examples
Ready-to-paste code snippets for your templates.
Basic usage
With options (guard + include)