Skip to content

Commit

Permalink
Remove the tabindex attribute on blur
Browse files Browse the repository at this point in the history
This is following some feedback from the GDS Accessibility clinic: #1999 (comment)
There is no need for the component to be focusable after the page has loaded.

Only remove the tabindex attribute if it was set by JavaScript.
  • Loading branch information
hannalaakso committed Nov 11, 2020
1 parent 52e001f commit e699b83
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ NotificationBanner.prototype.setFocus = function () {
}

// Set tabindex to -1 to make the element focusable with JavaScript.
// Remove the tabindex on blur as the component doesn't need to be focusable after the page has
// loaded.
if (!$module.getAttribute('tabindex')) {
$module.setAttribute('tabindex', '-1')

$module.addEventListener('blur', function () {
$module.removeAttribute('tabindex')
})
}

$module.focus()
Expand Down

0 comments on commit e699b83

Please sign in to comment.