This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user