@@ -4,10 +4,11 @@ import { createModAIShadow } from '../dom/modAIShadow';
4
4
import { createElement } from '../utils' ;
5
5
6
6
import type { Button } from '../dom/button' ;
7
+ import type { El } from '../utils' ;
7
8
8
9
type ConfirmDialogOptions = {
9
10
title : string ;
10
- content : string ;
11
+ content : El ;
11
12
onConfirm : ( ) => void ;
12
13
onCancel ?: ( ) => void ;
13
14
confirmText : string ;
@@ -51,31 +52,26 @@ export const confirmDialog = (config: ConfirmDialogOptions) => {
51
52
{ tabIndex : - 1 } ,
52
53
) ;
53
54
54
- const overlay = createElement (
55
+ const dialog = createElement (
55
56
'div' ,
56
- 'modai--root overlay ' ,
57
+ 'dialog ' ,
57
58
[
58
- createElement (
59
- 'div' ,
60
- 'dialog' ,
61
- [
62
- createElement ( 'h3' , 'title' , config . title ) ,
63
- createElement ( 'p' , 'message' , config . content ) ,
64
- createElement ( 'div' , 'buttons' , [
65
- config . showCancel && cancelBtn ,
66
- config . showConfirm && confirmBtn ,
67
- ] ) ,
68
- ] ,
69
- { tabIndex : - 1 } ,
70
- ) ,
59
+ createElement ( 'h3' , 'title' , config . title ) ,
60
+ createElement ( 'p' , 'message' , config . content ) ,
61
+ createElement ( 'div' , 'buttons' , [
62
+ config . showCancel && cancelBtn ,
63
+ config . showConfirm && confirmBtn ,
64
+ ] ) ,
71
65
] ,
72
- {
73
- ariaModal : 'true' ,
74
- role : 'dialog' ,
75
- ariaLabel : config . title ,
76
- } ,
66
+ { tabIndex : - 1 } ,
77
67
) ;
78
68
69
+ const overlay = createElement ( 'div' , 'modai--root overlay' , [ dialog ] , {
70
+ ariaModal : 'true' ,
71
+ role : 'dialog' ,
72
+ ariaLabel : config . title ,
73
+ } ) ;
74
+
79
75
const destroyDialog = ( ) => {
80
76
document . removeEventListener ( 'keydown' , handleDialogKeyDown ) ;
81
77
overlay . remove ( ) ;
@@ -124,6 +120,16 @@ export const confirmDialog = (config: ConfirmDialogOptions) => {
124
120
125
121
overlay . addEventListener ( 'keydown' , handleDialogKeyDown ) ;
126
122
123
+ overlay . addEventListener ( 'click' , ( ) => {
124
+ closeDialog ( ) ;
125
+ } ) ;
126
+
127
+ dialog . addEventListener ( 'click' , ( e ) => {
128
+ e . preventDefault ( ) ;
129
+ e . stopPropagation ( ) ;
130
+ e . stopImmediatePropagation ( ) ;
131
+ } ) ;
132
+
127
133
shadowRoot . appendChild ( overlay ) ;
128
134
document . body . append ( shadow ) ;
129
135
} ;
0 commit comments