diff --git a/core/misc/ajax.es6.js b/core/misc/ajax.es6.js index c3633b4636..d3de666e60 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 58759ac7a0..74b42051aa 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 628408e997..8224e1574f 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 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 cab99bd7bc..5c342d06c9 100644 --- a/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php @@ -94,6 +94,7 @@ public function testFilterViewsListing() { $enabled_view = $page->find('css', 'tr.views-ui-list-enabled'); // Open the dropdown with additional actions. $enabled_view->find('css', 'li.dropbutton-toggle button')->click(); + $enabled_view_id = $enabled_view->getAttribute('data-drupal-view-id'); $disable_button = $enabled_view->find('css', 'li.disable.dropbutton-action a'); // Check that the disable button is visible now. $this->assertTrue($disable_button->isVisible()); @@ -109,6 +110,11 @@ 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->assertTrue($this->getSession()->evaluateScript("jQuery(document.activeElement).data('data-drupal-selector') == 'views-listing-$enabled_view_id'")); } /**