diff --git a/core/lib/Drupal/Core/Render/Element/RenderElement.php b/core/lib/Drupal/Core/Render/Element/RenderElement.php index 47c84024c696e0e4685485ec94b6492c055cce08..b6f95bcd6cc7c2df28966c1d3448a48f2929c69f 100644 --- a/core/lib/Drupal/Core/Render/Element/RenderElement.php +++ b/core/lib/Drupal/Core/Render/Element/RenderElement.php @@ -269,6 +269,11 @@ public static function preRenderAjaxForm($element) { return $element; } + // Add a data attribute to disable automatic refocus after ajax call. + if (!empty($element['#ajax']['disable-refocus'])) { + $element['#attributes']['data-disable-refocus'] = "true"; + } + // Add a reasonable default event handler if none was specified. if (isset($element['#ajax']) && !isset($element['#ajax']['event'])) { switch ($element['#type']) { diff --git a/core/misc/ajax.js b/core/misc/ajax.js index 2a6616dc760a28f9a91e07e78f8caf8dcedf552f..b63bc0344360af59e66a5a3081061a4a3231d989 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -735,9 +735,36 @@ } $(this.element).prop('disabled', false); + // Save element's ancestors tree so if the element is removed from the dom + // we can try to refocus one of its parents. Using addBack reverse the + // result array, meaning that index 0 is the highest parent in the hierarchy + // in this situation it is usually a