Allow single button dialogs to be dismissed by clicking the background.
This commit is contained in:
parent
ddc7830c4c
commit
72340994da
1 changed files with 15 additions and 0 deletions
|
@ -11,9 +11,16 @@ const MamiMessageBoxContainer = function() {
|
|||
if(typeof dialog !== 'object' || dialog === null)
|
||||
throw 'dialog must be a non-null object';
|
||||
|
||||
const backgroundClick = () => {
|
||||
dialog.clickButtonIndex(0);
|
||||
};
|
||||
|
||||
try {
|
||||
if(dialog.buttonCount === 1)
|
||||
container.addEventListener('click', backgroundClick);
|
||||
return await dialog.show(container);
|
||||
} finally {
|
||||
container.removeEventListener('click', backgroundClick);
|
||||
dialog.dismiss();
|
||||
}
|
||||
},
|
||||
|
@ -117,6 +124,14 @@ const MamiMessageBoxDialog = function(info) {
|
|||
|
||||
return {
|
||||
getElement: () => dialog,
|
||||
|
||||
get buttonCount() {
|
||||
return buttons.childElementCount;
|
||||
},
|
||||
clickButtonIndex: num => {
|
||||
buttons.children[num].click();
|
||||
},
|
||||
|
||||
show: container => {
|
||||
return new Promise((resolve, reject) => {
|
||||
showResolve = resolve;
|
||||
|
|
Loading…
Reference in a new issue