makeup-exit-emitter
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -8,15 +8,5 @@ "use strict"; | ||
exports.removeFocusExit = removeFocusExit; | ||
var _makeupNextId = _interopRequireDefault(require("makeup-next-id")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
var focusExitEmitters = {}; | ||
function doFocusExit(el, fromElement, toElement) { | ||
@@ -29,3 +19,2 @@ el.dispatchEvent(new CustomEvent('focusExit', { | ||
bubbles: false // mirror the native mouseleave event | ||
})); | ||
@@ -36,4 +25,5 @@ } | ||
var newFocusElement = e.target; | ||
var targetIsDescendant = this.el.contains(newFocusElement); // if focus has moved to a focusable descendant | ||
var targetIsDescendant = this.el.contains(newFocusElement); | ||
// if focus has moved to a focusable descendant | ||
if (targetIsDescendant === true) { | ||
@@ -50,19 +40,14 @@ // set the target as the currently focussed element | ||
} | ||
function onWindowBlur() { | ||
doFocusExit(this.el, this.currentFocusElement, undefined); | ||
} | ||
function onWidgetFocusIn() { | ||
// listen for focus moving to anywhere in document | ||
// note that mouse click on buttons, checkboxes and radios does not trigger focus events in all browsers! | ||
document.addEventListener('focusin', this.onDocumentFocusInListener); // listen for focus leaving the window | ||
document.addEventListener('focusin', this.onDocumentFocusInListener); | ||
// listen for focus leaving the window | ||
window.addEventListener('blur', this.onWindowBlurListener); | ||
} | ||
var FocusExitEmitter = /*#__PURE__*/function () { | ||
function FocusExitEmitter(el) { | ||
_classCallCheck(this, FocusExitEmitter); | ||
class FocusExitEmitter { | ||
constructor(el) { | ||
this.el = el; | ||
@@ -75,19 +60,11 @@ this.currentFocusElement = null; | ||
} | ||
_createClass(FocusExitEmitter, [{ | ||
key: "removeEventListeners", | ||
value: function removeEventListeners() { | ||
window.removeEventListener('blur', this.onWindowBlurListener); | ||
document.removeEventListener('focusin', this.onDocumentFocusInListener); | ||
this.el.removeEventListener('focusin', this.onWidgetFocusInListener); | ||
} | ||
}]); | ||
return FocusExitEmitter; | ||
}(); | ||
removeEventListeners() { | ||
window.removeEventListener('blur', this.onWindowBlurListener); | ||
document.removeEventListener('focusin', this.onDocumentFocusInListener); | ||
this.el.removeEventListener('focusin', this.onWidgetFocusInListener); | ||
} | ||
} | ||
function addFocusExit(el) { | ||
var exitEmitter = null; | ||
(0, _makeupNextId.default)(el); | ||
if (!focusExitEmitters[el.id]) { | ||
@@ -97,9 +74,6 @@ exitEmitter = new FocusExitEmitter(el); | ||
} | ||
return exitEmitter; | ||
} | ||
function removeFocusExit(el) { | ||
var exitEmitter = focusExitEmitters[el.id]; | ||
if (exitEmitter) { | ||
@@ -106,0 +80,0 @@ exitEmitter.removeEventListeners(); |
{ | ||
"name": "makeup-exit-emitter", | ||
"description": "Emits custom 'focusExit' event when keyboard focus has exited an element and all of it's descendants", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"main": "./dist/cjs/index.js", | ||
@@ -6,0 +6,0 @@ "module": "./dist/mjs/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
7
169
0
8681