@@ -46,7 +46,7 @@ export function enhanceDialog(item, options) {
4646 offs . push ( on ( dialog , 'animationend' , onanimationend ) ) ;
4747
4848 // set up backdrop click handler
49- offs . push ( on ( dialog , 'click ' , onclick ) ) ;
49+ offs . push ( on ( dialog , 'pointerdown ' , onpointer ) ) ;
5050 offs . push ( on ( dialog , 'clickbackdrop' , onclickbackdrop ) ) ;
5151
5252 // if dialog is setup with "method=dialog" form / inputs
@@ -90,7 +90,7 @@ export function enhanceDialog(item, options) {
9090/**
9191 * @param {MouseEvent } event
9292 */
93- function onclick ( event ) {
93+ function onpointer ( event ) {
9494 if ( event . defaultPrevented ) return ;
9595 const dialog = /** @type {HTMLDialogElement } */ ( event . currentTarget ) ;
9696 const rect = dialog . getBoundingClientRect ( ) ;
@@ -101,7 +101,16 @@ function onclick(event) {
101101 rect . top > event . clientY ||
102102 rect . bottom < event . clientY
103103 ) {
104- dialog . dispatchEvent ( new CustomEvent ( 'clickbackdrop' ) ) ;
104+ // only register clickbackdrop if both pointerdown and pointerup
105+ // are outside the dialog
106+ if ( event . type === 'pointerdown' ) {
107+ const off = on ( dialog , 'pointerup' , ( e ) => {
108+ off ( ) ;
109+ onpointer ( e ) ;
110+ } ) ;
111+ } else if ( event . type === 'pointerup' ) {
112+ dialog . dispatchEvent ( new CustomEvent ( 'clickbackdrop' ) ) ;
113+ }
105114 }
106115}
107116
0 commit comments