Skip to content

Commit

Permalink
Fix dropdown focus. (NatLibFi#2931)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pasi Tiisanoja authored Apr 22, 2024
1 parent 1d9a527 commit 591b19a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions themes/finna2/js/finna-a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ finna.a11y = (function a11y() {
var dropdown = $(event.target);

// Set aria-expanded to true
dropdown.find('.dropdown-menu').attr('aria-expanded', true);
dropdown.find('.dropdown-toggle').attr('aria-expanded', true);

// Set focus on the first link in the dropdown
setTimeout(function shiftFocus() {
dropdown.find('.dropdown-menu li:first-child a').trigger("focus"); }, 10);
dropdown.find('.dropdown-menu li:first-child a').trigger("focus");
}, 50);
});

// On dropdown close
$(document).on('hidden.bs.dropdown', function dropdownClose(event) {
var dropdown = $(event.target);

// Set aria-expanded to false
dropdown.find('.dropdown-menu').attr('aria-expanded', false);
dropdown.find('.dropdown-toggle').attr('aria-expanded', false);

// Set focus back to dropdown toggle
dropdown.find('.dropdown-toggle').trigger("focus");
Expand Down
2 changes: 1 addition & 1 deletion themes/finna2/templates/search/searchbox.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
}
?>
<input id="searchForm_type" type="hidden" name="type" value="<?=$this->escapeHtmlAttr($value)?>" class="searchForm_type">
<a href="#" class="dropdown-toggle" aria-haspopup="true" aria-expanded="false" aria-label="<?= $this->transEsc('Narrow Search') ?>" data-toggle="dropdown"><span><?=$this->transEsc($label)?></span> <?=$this->icon('type-dropdown-open') ?></a>
<a role="button" href="#" class="dropdown-toggle" aria-expanded="false" aria-label="<?= $this->transEsc('Narrow Search') ?>" data-toggle="dropdown"><span><?=$this->transEsc($label)?></span> <?=$this->icon('type-dropdown-open') ?></a>
<ul class="dropdown-menu" role="menu">
<?php foreach ($handlers as $handler): ?>
<li>
Expand Down

0 comments on commit 591b19a

Please sign in to comment.