Commit 4cd3927c authored by jun's avatar jun
Browse files

MDL-59858 amd: Focus on the element that actually triggers the modal

parent 159b4e5d
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -63,12 +63,15 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',
*/
var setUpTrigger = function(modalPromise, triggerElement) {
if (typeof triggerElement != 'undefined') {
// The element that actually shows the modal.
var actualTriggerElement = null;
if (Array.isArray(triggerElement)) {
var selector = triggerElement[1];
triggerElement = triggerElement[0];
CustomEvents.define(triggerElement, [CustomEvents.events.activate]);
triggerElement.on(CustomEvents.events.activate, selector, function(e, data) {
actualTriggerElement = e.currentTarget;
modalPromise.then(function(modal) {
modal.show();
......@@ -79,6 +82,7 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',
} else {
CustomEvents.define(triggerElement, [CustomEvents.events.activate]);
triggerElement.on(CustomEvents.events.activate, function(e, data) {
actualTriggerElement = e.currentTarget;
modalPromise.then(function(modal) {
modal.show();
......@@ -90,7 +94,10 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',
modalPromise.then(function(modal) {
modal.getRoot().on(ModalEvents.hidden, function() {
triggerElement.focus();
// Focus on the trigger element that actually launched the modal.
if (actualTriggerElement !== null) {
actualTriggerElement.focus();
}
});
return modal;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment