Skip to content

Commit

Permalink
fix(a11y): keep focus on toggled menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Oct 20, 2023
1 parent a927b9b commit b87d3a8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions mod/likes/views/default/elgg/likes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ define(['jquery', 'elgg', 'elgg/Ajax', 'elgg/hooks'], function ($, elgg, Ajax, h

function update_like_menu_item(guid, menu_item) {
$('.elgg-menu-item-likes > a[data-likes-guid=' + guid + ']').replaceWith(menu_item);
$('.elgg-menu-item-likes > a[data-likes-guid=' + guid + ']').focus(); // can't chain because the selector is replaced
}

function set_counts(guid, num_likes, new_value) {
Expand Down
4 changes: 2 additions & 2 deletions views/default/navigation/menu/elements/item_toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ define(['jquery', 'elgg/hooks', 'elgg/Ajax'], function ($, hooks, Ajax) {
var $both_items = $item_clicked.add($other_item);
// Be optimistic about success
$both_items.toggleClass('hidden');
$other_item.focus();
$other_item.children('a').focus();

// Send the ajax request

Expand All @@ -34,7 +34,7 @@ define(['jquery', 'elgg/hooks', 'elgg/Ajax'], function ($, hooks, Ajax) {
error: function() {
// Something went wrong, so undo the optimistic changes
$both_items.toggleClass('hidden');
$item_clicked.focus();
$item_clicked.children('a').focus();
}
});

Expand Down

0 comments on commit b87d3a8

Please sign in to comment.