Issue #1848940 by milanpavic, dawehner, nod_, helenasue, DuaelFr, Lendude, AjitS, sdstyles, runeasgar, tim.plunkett: When enabling or disabling a View, don't move the cursor to the top of the page

merge-requests/1654/head
Nathaniel Catchpole 2018-05-09 12:29:14 +01:00
parent 323c56ca5c
commit b20aea605d
4 changed files with 23 additions and 2 deletions

View File

@ -888,7 +888,7 @@
if (!focusChanged && this.element && !$(this.element).data('disable-refocus')) { if (!focusChanged && this.element && !$(this.element).data('disable-refocus')) {
let target = false; 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')}"]`); target = document.querySelector(`[data-drupal-selector="${elementParents[n].getAttribute('data-drupal-selector')}"]`);
} }

View File

@ -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')) { if (!focusChanged && this.element && !$(this.element).data('disable-refocus')) {
var target = false; 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') + '"]'); target = document.querySelector('[data-drupal-selector="' + elementParents[n].getAttribute('data-drupal-selector') + '"]');
} }

View File

@ -178,6 +178,14 @@ class ViewListBuilder extends ConfigEntityListBuilder {
} }
} }
// 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; return $operations;
} }

View File

@ -92,6 +92,7 @@ class ViewsListingTest extends JavascriptTestBase {
// Disable a View and see if it moves to the disabled listing. // Disable a View and see if it moves to the disabled listing.
$enabled_view = $page->find('css', 'tr.views-ui-list-enabled'); $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. // Open the dropdown with additional actions.
$enabled_view->find('css', 'li.dropbutton-toggle button')->click(); $enabled_view->find('css', 'li.dropbutton-toggle button')->click();
$disable_button = $enabled_view->find('css', 'li.disable.dropbutton-action a'); $disable_button = $enabled_view->find('css', 'li.disable.dropbutton-action a');
@ -109,6 +110,18 @@ class ViewsListingTest extends JavascriptTestBase {
// Test that one enabled View has been moved to the disabled list. // Test that one enabled View has been moved to the disabled list.
$this->assertCount($enabled_views_count - 1, $enabled_rows); $this->assertCount($enabled_views_count - 1, $enabled_rows);
$this->assertCount($disabled_views_count + 1, $disabled_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()"));
} }
/** /**