diff --git a/README.md b/README.md index 3468da2..6a9f820 100644 --- a/README.md +++ b/README.md @@ -339,6 +339,9 @@ This can be combined with the [context](#context) option to only allow multiple open targets inside a context element. See the [accordion example](examples/accordion/) for a use-case. +> To allow multiple open targets, [`closeOnBlur`](#closeonblur) must be set to + `false`. + #### Example ```js diff --git a/dist/ctrly-es2015.js b/dist/ctrly-es2015.js index 478ec3e..43587e8 100644 --- a/dist/ctrly-es2015.js +++ b/dist/ctrly-es2015.js @@ -146,9 +146,8 @@ function ctrly(opts = {}) { removeFuncs.push( on(target, 'focusout', e => { if ( - e.relatedTarget && - !target.contains(e.relatedTarget) && - !closest(e.relatedTarget, controlSelector) + !e.relatedTarget || + !target.contains(e.relatedTarget) ) { close(target, false); } diff --git a/dist/ctrly-module.js b/dist/ctrly-module.js index 42653fd..e19cf00 100644 --- a/dist/ctrly-module.js +++ b/dist/ctrly-module.js @@ -414,7 +414,7 @@ function ctrly() { } if (options.closeOnBlur && !options.trapFocus) { removeFuncs.push(on(target, 'focusout', function (e) { - if (e.relatedTarget && !target.contains(e.relatedTarget) && !closest(e.relatedTarget, controlSelector)) { + if (!e.relatedTarget || !target.contains(e.relatedTarget)) { close(target, false); } }, { diff --git a/dist/ctrly.js b/dist/ctrly.js index 4605e05..b2047b8 100644 --- a/dist/ctrly.js +++ b/dist/ctrly.js @@ -420,7 +420,7 @@ } if (options.closeOnBlur && !options.trapFocus) { removeFuncs.push(on(target, 'focusout', function (e) { - if (e.relatedTarget && !target.contains(e.relatedTarget) && !closest(e.relatedTarget, controlSelector)) { + if (!e.relatedTarget || !target.contains(e.relatedTarget)) { close(target, false); } }, { diff --git a/dist/ctrly.min.js b/dist/ctrly.min.js index 5dea033..899fd20 100644 --- a/dist/ctrly.min.js +++ b/dist/ctrly.min.js @@ -3,4 +3,4 @@ * Copyright (c) 2018 Jan Sorgalla * License: MIT */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.ctrly=t()}(this,function(){"use strict";function f(){try{var e=document.activeElement;return e&&e.nodeName?e:document.body}catch(e){return document.body}}function r(e){for(var t=[];e&&e.parentNode&&1===e.parentNode.nodeType;)e=e.parentNode,t.push(e);return t}function p(e){var t,n;(1 { if ( - e.relatedTarget && - !target.contains(e.relatedTarget) && - !closest(e.relatedTarget, controlSelector) + !e.relatedTarget || + !target.contains(e.relatedTarget) ) { close(target, false); } diff --git a/test/test.allow-multiple.js b/test/test.allow-multiple.js index b7c7f86..5a33548 100644 --- a/test/test.allow-multiple.js +++ b/test/test.allow-multiple.js @@ -27,7 +27,7 @@ describe('ctrly(allowMultiple)', () => { it('allows multiple when configured', done => { const {control, target, control2, target2} = fixture.refs; - ctrlyInstance = ctrly({allowMultiple: true}); + ctrlyInstance = ctrly({allowMultiple: true, closeOnBlur: false}); ready(() => { assertClosed(control, target); diff --git a/test/test.context.js b/test/test.context.js index 8326f17..dc96690 100644 --- a/test/test.context.js +++ b/test/test.context.js @@ -27,7 +27,7 @@ describe('ctrly(context)', () => { it('handles target inside context', done => { const {control, target, control2, target2} = fixture.refs; - ctrlyInstance = ctrly({context: '.context'}); + ctrlyInstance = ctrly({context: '.context', closeOnBlur: false}); ready(() => { assertClosed(control, target);