This commit is contained in:
Andrew Nicols 2022-02-08 10:57:40 +08:00
commit df154ecb72
21 changed files with 47 additions and 31 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -222,9 +222,13 @@ export const confirm = (title, question, saveLabel, noLabel, saveCallback, cance
* @param {String|Promise} saveLabel
* @param {String|Promise} saveCallback
* @param {String|Promise} cancelCallback
* @param {Object} options
* @param {HTMLElement} [options.triggerElement=null] The element that triggered the modal (will receive the focus after hidden)
* @returns {Promise}
*/
export const saveCancel = async(title, question, saveLabel, saveCallback, cancelCallback) => {
export const saveCancel = async(title, question, saveLabel, saveCallback, cancelCallback, {
triggerElement = null,
} = {}) => {
const pendingPromise = new Pending('core/notification:confirm');
const [
@ -250,6 +254,7 @@ export const saveCancel = async(title, question, saveLabel, saveCallback, cancel
modal.getRoot().on(ModalEvents.save, saveCallback);
modal.getRoot().on(ModalEvents.cancel, cancelCallback);
modal.getRoot().on(ModalEvents.hidden, () => triggerElement?.focus());
pendingPromise.resolve();
return modal;
@ -262,10 +267,14 @@ export const saveCancel = async(title, question, saveLabel, saveCallback, cancel
* @param {Promise|String} title The header of the modal
* @param {Promise|String} question What do we want the user to confirm
* @param {Promise|String} saveLabel The modal action link text
* @param {Object} options
* @param {HTMLElement} [options.triggerElement=null] The element that triggered the modal (will receive the focus after hidden)
* @return {Promise}
*/
export const saveCancelPromise = (title, question, saveLabel) => new Promise((resolve, reject) => {
saveCancel(title, question, saveLabel, resolve, reject);
export const saveCancelPromise = (title, question, saveLabel, {
triggerElement = null,
} = {}) => new Promise((resolve, reject) => {
saveCancel(title, question, saveLabel, resolve, reject, {triggerElement});
});
/**