New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

defocuser-vue

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defocuser-vue

Vue plugin for Defocuser

0.1.4
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Defocuser Vue plugin

It has been way too many times when I implemented (with greater or lesser success) automated way for closing dropdowns when clicking outside of them or by pressing the Escape key. This utility is a way for me to stop repeating myself and have it working always the way it should.

Usage

There are 2 directives in this package:

v-defocus="method" - when this directive is added to an element and the user clicks outside of that element then the method will be called

The v-defocus directive takes 3 optional modifiers:

  • capture - use capture phase rather than bubbling phase
  • stop - call e.stopPropagation() on the click or keydown event. It is useful if you want to ensure that if the user clicks on for example a link that link won't be actioned.
  • prevent - call e.preventDefault() on the click or keydown event. It is useful if you want to stop propagation of the event, for example you want to make sure that clicking on another label of another dropdown that dropdown will not be opened automatically

v-defocus-secondary="ref" when this directive is added alongside the v-defocus element then the algorithm for checking if the click was inside or outside will take both roots into account. This is useful when you have a label that is not a direct parent of your dropdown but you still want it to be treated just like it would be one.

You can either manually import those directives like so

import { defocus } from 'defocuser-vue'

export default {
  directives: {
    defocus
  },
...
}

or use it as a plugin and register both directives automatically:

import Vue from 'vue'
import Defocuser from 'defocuser-vue'

Vue.use(Defocuser)

Remarks

Please see the following codepen for an example

https://codepen.io/padcom/pen/NzLQGM

Please see the following repository to see it in action

https://github.com/padcom/defocuser-example

Keywords

defocuser

FAQs

Package last updated on 01 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts