Skip to content
Snippets Groups Projects
Unverified Commit df7a5194 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3094783 by ravi.shankar, tim.plunkett, ridhimaabrol24, Kristen Pol,...

Issue #3094783 by ravi.shankar, tim.plunkett, ridhimaabrol24, Kristen Pol, phenaproxima: Do not use the internal data attribute for disable-refocus
parent b1fc8e03
No related branches found
No related tags found
8 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!144Issue #2666286: Clean up menu_ui to conform to Drupal coding standards,!16Draft: Resolve #2081585 "History storage",!13Resolve #2903456
......@@ -484,9 +484,6 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
'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 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
'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' => [],
......
......@@ -90,20 +90,14 @@ public function viewsForm(array &$form, FormStateInterface $form_state) {
'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';
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment