1
+ /* eslint-disable no-unused-expressions */
1
2
/* eslint-disable no-underscore-dangle */
2
3
3
4
import { ViewController , createDuplicateIframeWarning , createURL , createModalNotReadyError } from '@magic-sdk/provider' ;
@@ -46,6 +47,7 @@ function checkForSameSrcInstances(parameters: string) {
46
47
*/
47
48
export class IframeController extends ViewController {
48
49
private iframe ! : Promise < HTMLIFrameElement > ;
50
+ private activeElement : any = null ;
49
51
50
52
protected init ( ) {
51
53
this . iframe = new Promise ( ( resolve ) => {
@@ -54,6 +56,7 @@ export class IframeController extends ViewController {
54
56
const iframe = document . createElement ( 'iframe' ) ;
55
57
iframe . classList . add ( 'magic-iframe' ) ;
56
58
iframe . dataset . magicIframeLabel = createURL ( this . endpoint ) . host ;
59
+ iframe . title = 'Secure Modal' ;
57
60
iframe . src = createURL ( `/send?params=${ encodeURIComponent ( this . parameters ) } ` , this . endpoint ) . href ;
58
61
applyOverlayStyles ( iframe ) ;
59
62
document . body . appendChild ( iframe ) ;
@@ -76,11 +79,15 @@ export class IframeController extends ViewController {
76
79
protected async showOverlay ( ) {
77
80
const iframe = await this . iframe ;
78
81
iframe . style . display = 'block' ;
82
+ this . activeElement = document . activeElement ;
83
+ iframe . focus ( ) ;
79
84
}
80
85
81
86
protected async hideOverlay ( ) {
82
87
const iframe = await this . iframe ;
83
88
iframe . style . display = 'none' ;
89
+ if ( this . activeElement ?. focus ) this . activeElement . focus ( ) ;
90
+ this . activeElement = null ;
84
91
}
85
92
86
93
public async postMessage ( data : any ) {
0 commit comments