Skip to content

Commit

Permalink
Update variable names and test description
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtrussler committed Mar 25, 2024
1 parent 6647f35 commit a799630
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
var $navMenuLinks = this.$navMenu.querySelectorAll('li a')
var $firstNavLink = $navMenuLinks[0]
var $lastNavLink = $navMenuLinks[$navMenuLinks.length - 1]
var $searchMenuTabable = this.$searchMenu.querySelectorAll('li a, input, button')
var $lastSearchTabable = $searchMenuTabable[$searchMenuTabable.length - 1]
var $searchMenuTabbable = this.$searchMenu.querySelectorAll('li a, input, button')
var $lastSearchMenuTabbable = $searchMenuTabbable[$searchMenuTabbable.length - 1]

if (event.keyCode === KEY_TAB) {
if (!this.$navMenu.hasAttribute('hidden')) {
Expand Down Expand Up @@ -169,7 +169,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
break
}
} else if (!this.$searchMenu.hasAttribute('hidden')) {
if (document.activeElement === $lastSearchTabable) {
if (document.activeElement === $lastSearchMenuTabbable) {
if (!event.shiftKey) {
hide(this.$searchToggle, this.$searchMenu)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ describe('The super header navigation', function () {
var $firstNavLink
var $lastNavLink
var $searchMenu
var $searchTabable
var $lastSearchTabable
var $searchMenuTabbable
var $lastSearchMenuTabbable

beforeEach(function () {
thisModule.init()
Expand All @@ -341,8 +341,8 @@ describe('The super header navigation', function () {
$firstNavLink = $navLinks[0]
$lastNavLink = $navLinks[$navLinks.length - 1]
$searchMenu = document.querySelector('#super-search-menu')
$searchTabable = $searchMenu.querySelectorAll('li a, input, button')
$lastSearchTabable = $searchTabable[$searchTabable.length - 1]
$searchMenuTabbable = $searchMenu.querySelectorAll('li a, input, button')
$lastSearchMenuTabbable = $searchMenuTabbable[$searchMenuTabbable.length - 1]
})

it('when the Menu button is focussed, the nav menu is open and the tab key is pressed focus moves to the first nav menu link', function () {
Expand Down Expand Up @@ -381,10 +381,10 @@ describe('The super header navigation', function () {
expect(document.activeElement).toEqual($lastNavLink)
})

it('when the last search menu link is focussed and the tab key is pressed the search menu is closed', function () {
it('when the last tabbable element in the search menu is focussed and the tab key is pressed the search menu is closed', function () {
$searchMenu.removeAttribute('hidden')
$lastSearchTabable.focus()
window.GOVUK.triggerEvent($lastSearchTabable, 'keydown', { keyCode: 9, cancelable: true })
$lastSearchMenuTabbable.focus()
window.GOVUK.triggerEvent($lastSearchMenuTabbable, 'keydown', { keyCode: 9, cancelable: true })

expect($searchMenu.hasAttribute('hidden')).toEqual(true)
expect($searchMenuButton.getAttribute('aria-expanded')).toEqual('false')
Expand Down

0 comments on commit a799630

Please sign in to comment.