diff --git a/core/lib/Drupal/Core/Render/Element/RenderElement.php b/core/lib/Drupal/Core/Render/Element/RenderElement.php index b6f95bc..7a8d1ea 100644 --- a/core/lib/Drupal/Core/Render/Element/RenderElement.php +++ b/core/lib/Drupal/Core/Render/Element/RenderElement.php @@ -269,11 +269,6 @@ 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']) { @@ -325,6 +320,13 @@ public static function preRenderAjaxForm($element) { } } + // Disable automatic refocus after ajax call by adding a data attribute if + // the disable-refocus flag has been set or the ajax event is 'blur' to + // avoid an infinite focus loop. + if (!empty($element['#ajax']['disable-refocus']) || (!empty($element['#ajax']['event']) && $element['#ajax']['event'] == 'blur')) { + $element['#attributes']['data-disable-refocus'] = "true"; + } + // Attach JavaScript settings to the element. if (isset($element['#ajax']['event'])) { $element['#attached']['library'][] = 'core/jquery.form';