Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rerolls work previously done on this for 8.1 #1

Open
wants to merge 2 commits into
base: 8.6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions core/modules/views_ui/js/views_ui.listing.es6.js
Expand Up @@ -47,4 +47,37 @@
}
},
};

// 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.

/**
* 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.
*/

let changedView = null;
Drupal.behaviors.viewsChangeFocus = {
attach: (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', (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) {
$(`[data-drupal-view-id=${changedView}]`)
.find('.dropbutton a').eq(0).trigger('focus');
changedView = null;
}
},
};
}(jQuery, Drupal));
14 changes: 14 additions & 0 deletions core/modules/views_ui/js/views_ui.listing.js
Expand Up @@ -35,4 +35,18 @@
}
}
};

var changedView = null;
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) {
$('[data-drupal-view-id=' + changedView + ']').find('.dropbutton a').eq(0).trigger('focus');
changedView = null;
}
}
};
})(jQuery, Drupal);
1 change: 1 addition & 0 deletions core/modules/views_ui/src/ViewListBuilder.php
Expand Up @@ -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(),
],
];
}
Expand Down
Expand Up @@ -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());
Expand All @@ -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'"));
}

/**
Expand Down