From cd85146e19691283fd37f97e380263e32ca2c154 Mon Sep 17 00:00:00 2001 From: Helena McCabe Date: Fri, 13 Apr 2018 13:07:42 -0500 Subject: [PATCH] Rerolls work previously done on this for 8.1 --- core/modules/views_ui/js/views_ui.listing.es6.js | 34 ++++++++++++++++++++++ core/modules/views_ui/js/views_ui.listing.js | 15 ++++++++++ core/modules/views_ui/src/ViewListBuilder.php | 1 + .../src/FunctionalJavascript/ViewsListingTest.php | 6 ++++ 4 files changed, 56 insertions(+) diff --git a/core/modules/views_ui/js/views_ui.listing.es6.js b/core/modules/views_ui/js/views_ui.listing.es6.js index 61a66661e7..865e8afac1 100644 --- a/core/modules/views_ui/js/views_ui.listing.es6.js +++ b/core/modules/views_ui/js/views_ui.listing.es6.js @@ -47,4 +47,38 @@ } }, }; + + // When a view is enabled/disabled, this variable will hold its machine name. + // It is used in the behavior to focus on the first dropbutton link of this + // view's row. + + var changedView = ''; + + /** + * Handles focus after Ajax update. + * + * @type {Drupal~behavior} + * + * @prop {Drupal~behaviorAttach} attach + * Listen to disable events on views listing page to keep focus in context. + */ + Drupal.behaviors.viewsChangeFocus = { + attach: function (context) { + // Enable a view, keep the machine name around so that the next round of + // Drupal.behaviorAttach() focuses it. + $(context).find('[data-drupal-view-id] .use-ajax').once('viewsUiListFocus') + .on('click', function (event) { + // Store the machine name of the view to focus after ajax update. + changedView = $(event.target).closest('tr').attr('data-drupal-view-id'); + }); + + // A view has been enabled/disabled, focus the first dropbutton link. + if (changedView && changedView !== '') { + $('[data-drupal-view-id="' + changedView + '"]') + .find('.dropbutton a').eq(0).trigger('focus'); + changedView = ''; + } + } + }; + }(jQuery, Drupal)); diff --git a/core/modules/views_ui/js/views_ui.listing.js b/core/modules/views_ui/js/views_ui.listing.js index 4da040580e..cb73bd14ed 100644 --- a/core/modules/views_ui/js/views_ui.listing.js +++ b/core/modules/views_ui/js/views_ui.listing.js @@ -35,4 +35,19 @@ } } }; + + var changedView = ''; + + Drupal.behaviors.viewsChangeFocus = { + attach: function attach(context) { + $(context).find('[data-drupal-view-id] .use-ajax').once('viewsUiListFocus').on('click', function (event) { + changedView = $(event.target).closest('tr').attr('data-drupal-view-id'); + }); + + if (changedView && changedView !== '') { + $('[data-drupal-view-id="' + changedView + '"]').find('.dropbutton a').eq(0).trigger('focus'); + changedView = ''; + } + } + }; })(jQuery, Drupal); \ No newline at end of file diff --git a/core/modules/views_ui/src/ViewListBuilder.php b/core/modules/views_ui/src/ViewListBuilder.php index 628408e997..6c21499192 100644 --- a/core/modules/views_ui/src/ViewListBuilder.php +++ b/core/modules/views_ui/src/ViewListBuilder.php @@ -113,6 +113,7 @@ public function buildRow(EntityInterface $view) { ], '#attributes' => [ 'class' => [$view->status() ? 'views-ui-list-enabled' : 'views-ui-list-disabled'], + 'data-drupal-view-id' => $view->id(), ], ]; } diff --git a/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php index cab99bd7bc..98c226f84a 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).parents('tr.views-ui-list-disabled').data('drupal-view-id') == '$enabled_view_id'")); } /**