From df7a51943cb8469b7730d6633a3d30fb10535368 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Thu, 3 Sep 2020 20:23:03 +0100 Subject: [PATCH] Issue #3094783 by ravi.shankar, tim.plunkett, ridhimaabrol24, Kristen Pol, phenaproxima: Do not use the internal data attribute for disable-refocus --- .../Plugin/Field/FieldWidget/MediaLibraryWidget.php | 6 +++--- .../Plugin/views/field/MediaLibrarySelectForm.php | 12 +++--------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php b/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php index 85412168c42..31d14f4d7df 100644 --- a/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php +++ b/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php @@ -484,9 +484,6 @@ class MediaLibraryWidget extends WidgetBase implements TrustedCallbackInterface 'class' => [ 'js-media-library-open-button', ], - // The jQuery UI dialog automatically moves focus to the first :tabbable - // element of the modal, so we need to disable refocus on the button. - 'data-disable-refocus' => 'true', ], '#media_library_state' => $state, '#ajax' => [ @@ -495,6 +492,9 @@ class MediaLibraryWidget extends WidgetBase implements TrustedCallbackInterface 'type' => 'throbber', 'message' => $this->t('Opening media library.'), ], + // The AJAX system automatically moves focus to the first :tabbable + // element of the modal, so we need to disable refocus on the button. + 'disable-refocus' => TRUE, ], // Allow the media library to be opened even if there are form errors. '#limit_validation_errors' => [], diff --git a/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php b/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php index 2d0702bd4dc..bc506f202a1 100644 --- a/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php +++ b/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php @@ -90,20 +90,14 @@ class MediaLibrarySelectForm extends FieldPluginBase { 'query' => $query, ], 'callback' => [static::class, 'updateWidget'], + // The AJAX system automatically moves focus to the first :tabbable + // element of the modal, so we need to disable refocus on the button. + 'disable-refocus' => TRUE, ]; $form['actions']['submit']['#value'] = $this->t('Insert selected'); $form['actions']['submit']['#button_type'] = 'primary'; $form['actions']['submit']['#field_id'] = $selection_field_id; - // By default, the AJAX system tries to move the focus back to the element - // that triggered the AJAX request. Since the media library is closed after - // clicking the select button, the focus can't be moved back. We need to set - // the 'data-disable-refocus' attribute to prevent the AJAX system from - // moving focus to a random element. The select button triggers an update in - // the opener, and the opener should be responsible for moving the focus. An - // example of this can be seen in MediaLibraryWidget::updateWidget(). - // @see \Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidget::updateWidget() - $form['actions']['submit']['#attributes']['data-disable-refocus'] = 'true'; } /**