fix #832, floating btns closing, Esc to close confirmation dialog, 0x0 rects disabled (#947)

This commit is contained in:
olekhshch
2024-01-20 23:53:20 +01:00
committed by GitHub
parent f75d1a83a0
commit 9f77e9c63a
6 changed files with 43 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
import PlainAlertDialog from 'elix/src/plain/PlainAlertDialog.js'
import { template } from 'elix/src/base/internal.js'
import { template, keydown } from 'elix/src/base/internal.js'
import { fragmentFrom } from 'elix/src/core/htmlLiterals.js'
/**
@@ -63,6 +63,24 @@ export default class SePlainAlertDialog extends PlainAlertDialog {
)
return result
}
/**
* Tracks if users wants to cancel (close dialog without any changes) with Esc
* if null - seConfirm will use responce.choice
*/
keyChoice = null
get [keydown] () {
/**
* Listens to Esc key to close dialog
*/
return (e) => {
if (e.key === 'Escape') {
this.keyChoice = 'Cancel'
this.close()
}
}
}
}
customElements.define('se-elix-alert-dialog', SePlainAlertDialog)

View File

@@ -6,7 +6,7 @@ const seConfirm = async (text, choices) => {
dialog.choices = (choices === undefined) ? ['Ok', 'Cancel'] : choices
dialog.open()
const response = await dialog.whenClosed()
return response.choice
return dialog.keyChoice ?? response.choice
}
window.seConfirm = seConfirm