mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-73116 core: Add triggerElement parameter to saveCancel dialogue
triggerElement parameter is used to return the focus after modal is hidden
This commit is contained in:
parent
6652ec135b
commit
8b535c297b
3 changed files with 14 additions and 5 deletions
2
lib/amd/build/notification.min.js
vendored
2
lib/amd/build/notification.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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});
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue