Skip to content

Commit

Permalink
Fix and optimize closeOnBlur behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jsor committed Sep 7, 2018
1 parent 3527abd commit ab73220
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions dist/ctrly-es2015.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/ctrly-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}, {
Expand Down
2 changes: 1 addition & 1 deletion dist/ctrly.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}, {
Expand Down
2 changes: 1 addition & 1 deletion dist/ctrly.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/ctrly.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ export default 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);
}
Expand Down
2 changes: 1 addition & 1 deletion test/test.allow-multiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/test.context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ab73220

Please sign in to comment.