makeup-exit-emitter
Advanced tools
Comparing version 0.4.1 to 0.4.2
{ | ||
"dependencies":[ | ||
"require: ./dist/index.js" | ||
] | ||
"dependencies": ["require: ./dist/index.js"] | ||
} |
@@ -9,6 +9,6 @@ "use strict"; | ||
var _makeupNextId = _interopRequireDefault(require("makeup-next-id")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var focusExitEmitters = {}; | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
const focusExitEmitters = {}; | ||
function doFocusExit(el, fromElement, toElement) { | ||
el.dispatchEvent(new CustomEvent('focusExit', { | ||
el.dispatchEvent(new CustomEvent("focusExit", { | ||
detail: { | ||
@@ -21,6 +21,5 @@ fromElement, | ||
} | ||
function onDocumentFocusIn(e) { | ||
var newFocusElement = e.target; | ||
var targetIsDescendant = this.el.contains(newFocusElement); | ||
const newFocusElement = e.target; | ||
const targetIsDescendant = this.el.contains(newFocusElement); | ||
@@ -33,4 +32,4 @@ // if focus has moved to a focusable descendant | ||
// else focus has not gone to a focusable descendant | ||
window.removeEventListener('blur', this.onWindowBlurListener); | ||
document.removeEventListener('focusin', this.onDocumentFocusInListener); | ||
window.removeEventListener("blur", this.onWindowBlurListener); | ||
document.removeEventListener("focusin", this.onDocumentFocusInListener); | ||
doFocusExit(this.el, this.currentFocusElement, newFocusElement); | ||
@@ -46,5 +45,5 @@ this.currentFocusElement = null; | ||
// note that mouse click on buttons, checkboxes and radios does not trigger focus events in all browsers! | ||
document.addEventListener('focusin', this.onDocumentFocusInListener); | ||
document.addEventListener("focusin", this.onDocumentFocusInListener); | ||
// listen for focus leaving the window | ||
window.addEventListener('blur', this.onWindowBlurListener); | ||
window.addEventListener("blur", this.onWindowBlurListener); | ||
} | ||
@@ -58,12 +57,12 @@ class FocusExitEmitter { | ||
this.onWindowBlurListener = onWindowBlur.bind(this); | ||
this.el.addEventListener('focusin', this.onWidgetFocusInListener); | ||
this.el.addEventListener("focusin", this.onWidgetFocusInListener); | ||
} | ||
removeEventListeners() { | ||
window.removeEventListener('blur', this.onWindowBlurListener); | ||
document.removeEventListener('focusin', this.onDocumentFocusInListener); | ||
this.el.removeEventListener('focusin', this.onWidgetFocusInListener); | ||
window.removeEventListener("blur", this.onWindowBlurListener); | ||
document.removeEventListener("focusin", this.onDocumentFocusInListener); | ||
this.el.removeEventListener("focusin", this.onWidgetFocusInListener); | ||
} | ||
} | ||
function addFocusExit(el) { | ||
var exitEmitter = null; | ||
let exitEmitter = null; | ||
(0, _makeupNextId.default)(el); | ||
@@ -77,3 +76,3 @@ if (!focusExitEmitters[el.id]) { | ||
function removeFocusExit(el) { | ||
var exitEmitter = focusExitEmitters[el.id]; | ||
const exitEmitter = focusExitEmitters[el.id]; | ||
if (exitEmitter) { | ||
@@ -80,0 +79,0 @@ exitEmitter.removeEventListeners(); |
import nextID from "makeup-next-id"; | ||
const focusExitEmitters = {}; | ||
function doFocusExit(el, fromElement, toElement) { | ||
el.dispatchEvent(new CustomEvent("focusExit", { | ||
detail: { fromElement, toElement }, | ||
bubbles: false | ||
})); | ||
el.dispatchEvent( | ||
new CustomEvent("focusExit", { | ||
detail: { fromElement, toElement }, | ||
bubbles: false | ||
// mirror the native mouseleave event | ||
}) | ||
); | ||
} | ||
@@ -9,0 +12,0 @@ function onDocumentFocusIn(e) { |
{ | ||
"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.1", | ||
"version": "0.4.2", | ||
"main": "./dist/cjs/index.js", | ||
@@ -13,3 +13,3 @@ "module": "./dist/mjs/index.js", | ||
}, | ||
"repository": "https://github.com/makeup/makeup-js/tree/master/packages/makeup-exit-emitter", | ||
"repository": "https://github.com/makeup/makeup-js/tree/master/packages/core/makeup-exit-emitter", | ||
"author": "Ian McBurnie <ianmcburnie@hotmail.com>", | ||
@@ -30,3 +30,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"makeup-next-id": "~0.4.0" | ||
"makeup-next-id": "^0.4.2" | ||
}, | ||
@@ -41,3 +41,4 @@ "files": [ | ||
"extends @ebay/browserslist-config" | ||
] | ||
], | ||
"gitHead": "4d199965cba30b5f63cfc38b5b58544cfc5b27c1" | ||
} |
@@ -12,9 +12,9 @@ # makeup-exit-emitter | ||
```js | ||
import ExitEmitter from 'makeup-exit-emitter'; | ||
import ExitEmitter from "makeup-exit-emitter"; | ||
const el = document.getElementById('#widget1'); | ||
const el = document.getElementById("#widget1"); | ||
ExitEmitter.addFocusExit(el); | ||
el.addEventListener('focusExit', function(e){ | ||
el.addEventListener("focusExit", function (e) { | ||
console.log(this, e); // outputs (el1, 'focusExit') | ||
@@ -26,14 +26,14 @@ }); | ||
* addFocusExit(el) | ||
* removeFocusExit(el) | ||
- addFocusExit(el) | ||
- removeFocusExit(el) | ||
## Events | ||
* 'focusExit' | ||
* event.detail | ||
* fromElement | ||
* toElement | ||
- 'focusExit' | ||
- event.detail | ||
- fromElement | ||
- toElement | ||
## Dependencies | ||
* [makeup-next-id](https://github.com/makeup/makeup-js/packages/makeup-next-id) | ||
- [makeup-next-id](https://github.com/makeup/makeup-js/packages/makeup-next-id) |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
10634
216
Updatedmakeup-next-id@^0.4.2