FocusFirstCommand example

return $form;
  }

  /** * Callback for testing FocusFirstCommand on a container. * * @return \Drupal\Core\Ajax\AjaxResponse * The AJAX response. */
  public function selectorDoesNotExist() {
    $response = new AjaxResponse();
    return $response->addCommand(new FocusFirstCommand('#selector-does-not-exist'));
  }

  /** * Callback for testing FocusFirstCommand on a container. * * @return \Drupal\Core\Ajax\AjaxResponse * The AJAX response. */
  public function selectorHasNothingTabbable() {
    $response = new AjaxResponse();
    return $response->addCommand(new FocusFirstCommand('#nothing-tabbable'));
  }
$response->addCommand(new ReplaceCommand('#media-library-add-form-wrapper', $form));
      return $response;
    }

    // Check if the remove button is clicked.     if (end($triggering_element['#parents']) === 'remove_button') {
      // When the list of added media is empty, return to the media library and       // shift focus back to the first tabbable element (which should be the       // source field).       if (empty($added_media)) {
        $response->addCommand(new ReplaceCommand('#media-library-add-form-wrapper', $this->buildMediaLibraryUi($form_state)));
        $response->addCommand(new FocusFirstCommand('#media-library-add-form-wrapper'));
      }
      // When there are still more items, update the form and shift the focus to       // the next media item. If the last list item is removed, shift focus to       // the previous item.       else {
        $response->addCommand(new ReplaceCommand("#$wrapper_id", $form));

        // Find the delta of the next media item. If there is no item with a         // bigger delta, we automatically use the delta of the previous item and         // shift the focus there.         $removed_delta = array_slice($triggering_element['#array_parents'], -2, 1)[0];
        
Home | Imprint | This part of the site doesn't use cookies.