Skip to content

Commit

Permalink
fix: check focus on iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardocavazza committed Nov 21, 2022
1 parent 272e31f commit 7433466
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/odd-worms-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chialab/loock": patch
---

Handle focus on iframes.
17 changes: 16 additions & 1 deletion src/Manager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { window } from '@chialab/dna';
import { window, document } from '@chialab/dna';
import { Context } from './Context.js';
import { ESC_KEY, TAB_KEY } from './keys.js';

Expand Down Expand Up @@ -121,8 +121,22 @@ export class Manager {
}
};

/**
* @private
*/
this.onIframeFocus = () => {
setTimeout(() => {
if (document.activeElement?.tagName === 'IFRAME') {
if (this.activeContext) {
this.activeContext.exit();
}
}
}, 0);
};

root.addEventListener('keydown', this.onKeyDown);
root.addEventListener('focusin', this.onFocusIn);
root.addEventListener('focusout', this.onIframeFocus);
}

/**
Expand Down Expand Up @@ -266,6 +280,7 @@ export class Manager {
});
this.root.removeEventListener('keydown', this.onKeyDown);
this.root.removeEventListener('focusin', this.onFocusIn);
this.root.removeEventListener('focusout', this.onIframeFocus);
}
}

Expand Down

0 comments on commit 7433466

Please sign in to comment.