@@ -4,10 +4,11 @@ import { createModAIShadow } from '../dom/modAIShadow';
44import { createElement } from '../utils' ;
55
66import type { Button } from '../dom/button' ;
7+ import type { El } from '../utils' ;
78
89type ConfirmDialogOptions = {
910 title : string ;
10- content : string ;
11+ content : El ;
1112 onConfirm : ( ) => void ;
1213 onCancel ?: ( ) => void ;
1314 confirmText : string ;
@@ -51,31 +52,26 @@ export const confirmDialog = (config: ConfirmDialogOptions) => {
5152 { tabIndex : - 1 } ,
5253 ) ;
5354
54- const overlay = createElement (
55+ const dialog = createElement (
5556 'div' ,
56- 'modai--root overlay ' ,
57+ 'dialog ' ,
5758 [
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+ ] ) ,
7165 ] ,
72- {
73- ariaModal : 'true' ,
74- role : 'dialog' ,
75- ariaLabel : config . title ,
76- } ,
66+ { tabIndex : - 1 } ,
7767 ) ;
7868
69+ const overlay = createElement ( 'div' , 'modai--root overlay' , [ dialog ] , {
70+ ariaModal : 'true' ,
71+ role : 'dialog' ,
72+ ariaLabel : config . title ,
73+ } ) ;
74+
7975 const destroyDialog = ( ) => {
8076 document . removeEventListener ( 'keydown' , handleDialogKeyDown ) ;
8177 overlay . remove ( ) ;
@@ -124,6 +120,16 @@ export const confirmDialog = (config: ConfirmDialogOptions) => {
124120
125121 overlay . addEventListener ( 'keydown' , handleDialogKeyDown ) ;
126122
123+ overlay . addEventListener ( 'click' , ( ) => {
124+ closeDialog ( ) ;
125+ } ) ;
126+
127+ dialog . addEventListener ( 'click' , ( e ) => {
128+ e . preventDefault ( ) ;
129+ e . stopPropagation ( ) ;
130+ e . stopImmediatePropagation ( ) ;
131+ } ) ;
132+
127133 shadowRoot . appendChild ( overlay ) ;
128134 document . body . append ( shadow ) ;
129135} ;
0 commit comments