diff --git a/core/misc/ajax.es6.js b/core/misc/ajax.es6.js index c3633b463663fb28efb3d54ede599d4ba314916e..d3de666e60c9d74c9ed4ab2592fb18f8d411eb8b 100644 --- a/core/misc/ajax.es6.js +++ b/core/misc/ajax.es6.js @@ -888,7 +888,7 @@ if (!focusChanged && this.element && !$(this.element).data('disable-refocus')) { let target = false; - for (let n = elementParents.length - 1; !target && n > 0; n--) { + for (let n = elementParents.length - 1; !target && n >= 0; n--) { target = document.querySelector(`[data-drupal-selector="${elementParents[n].getAttribute('data-drupal-selector')}"]`); } diff --git a/core/misc/ajax.js b/core/misc/ajax.js index 58759ac7a09ba378f8f119d1939dc60e438f81a5..74b42051aae09ed7a9df5728cf4bf4a1cd83bf42 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -420,7 +420,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr if (!focusChanged && this.element && !$(this.element).data('disable-refocus')) { var target = false; - for (var n = elementParents.length - 1; !target && n > 0; n--) { + for (var n = elementParents.length - 1; !target && n >= 0; n--) { target = document.querySelector('[data-drupal-selector="' + elementParents[n].getAttribute('data-drupal-selector') + '"]'); } diff --git a/core/modules/views_ui/src/ViewListBuilder.php b/core/modules/views_ui/src/ViewListBuilder.php index 628408e997fde5837e1c4ad0f67108783314afad..c690aee99bf98341a098d1c58497c06b71d44799 100644 --- a/core/modules/views_ui/src/ViewListBuilder.php +++ b/core/modules/views_ui/src/ViewListBuilder.php @@ -178,6 +178,14 @@ public function getDefaultOperations(EntityInterface $entity) { } } + // ajax.js focuses automatically on the data-drupal-selector element. When + // enabling the view again, focusing on the disable link doesn't work, as it + // is hidden. We assign data-drupal-selector to every link, so it focuses + // on the edit link. + foreach ($operations as &$operation) { + $operation['attributes']['data-drupal-selector'] = 'views-listing-' . $entity->id(); + } + return $operations; } diff --git a/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php index cab99bd7bc99a4ab0c08a39f213feb9f09d05421..86d3b6e5e7e4811627f20c8054d6ec6b9d32ff52 100644 --- a/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php @@ -92,6 +92,7 @@ public function testFilterViewsListing() { // Disable a View and see if it moves to the disabled listing. $enabled_view = $page->find('css', 'tr.views-ui-list-enabled'); + $view_description = $enabled_view->find('css', '.views-ui-view-name h3')->getText(); // Open the dropdown with additional actions. $enabled_view->find('css', 'li.dropbutton-toggle button')->click(); $disable_button = $enabled_view->find('css', 'li.disable.dropbutton-action a'); @@ -109,6 +110,18 @@ public function testFilterViewsListing() { // Test that one enabled View has been moved to the disabled list. $this->assertCount($enabled_views_count - 1, $enabled_rows); $this->assertCount($disabled_views_count + 1, $disabled_rows); + + // Test that the keyboard focus is on the dropdown button of the View we + // just disabled. + $this->assertTrue($this->getSession()->evaluateScript("jQuery(document.activeElement).parent().is('li.enable.dropbutton-action')")); + $this->assertEquals($view_description, $this->getSession()->evaluateScript("jQuery(document.activeElement).parents('tr').find('h3').text()")); + + // Enable the view again and ensure we have the focus on the edit button. + $this->getSession()->evaluateScript('jQuery(document.activeElement).click()'); + $session->assertWaitOnAjaxRequest(); + + $this->assertTrue($this->getSession()->evaluateScript("jQuery(document.activeElement).parent().is('li.edit.dropbutton-action')")); + $this->assertEquals($view_description, $this->getSession()->evaluateScript("jQuery(document.activeElement).parents('tr').find('h3').text()")); } /**