common click-outside JS helper

We often want to run some code when clicking outside of an element. examples:

  • sidebar: clicking outside on closes it (on small screens)
  • modal: clicking outside should close it
  • dropdowns: clicking outside should close, possibly save value/submit form

We could do one of:

  • util function, takes an element (or selector) and a callback
  • data attribute on elements
  • Vue wrapper component
  • Vue mixin (example)

Also useful is 'excluded class' for things you can click on that won't be considered outside click. Shown in this Ember lib

Edited Oct 28, 2017 by Simon Knox
Assignee Loading
Time tracking Loading