Skip to content

Fix: [AEA-5081] - fixed skip link focus and updated trivyignore#1798

Merged
jonathanwelch1-nhs merged 16 commits intomainfrom
aea-5081-work-on-header
Feb 26, 2026
Merged

Fix: [AEA-5081] - fixed skip link focus and updated trivyignore#1798
jonathanwelch1-nhs merged 16 commits intomainfrom
aea-5081-work-on-header

Conversation

@jonathanwelch1-nhs
Copy link
Copy Markdown
Contributor

Summary

fixed skip link focus and updated trivyignore plus updated title
https://nhsd-jira.digital.nhs.uk/browse/AEA-5081

  • Routine Change

@github-actions
Copy link
Copy Markdown
Contributor

This PR is linked to a ticket in an NHS Digital JIRA Project. Here's a handy link to the ticket:

AEA-5081

const target = event.target as HTMLElement

if (target && target.id) {
const interactiveSelectors = [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

youve got this list in at least 2 places, best to condense into a single common place to avoid any issues if anything ever needs adding or removing.


// Initial check: see if there's an active interactive element on page load
const activeElement = document.activeElement as HTMLElement
const hasActiveInteractiveElement = activeElement &&
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this condition be tightened up any? theres a lot of moving parts to it

target.tagName === "TEXTAREA" ||
target.tagName === "SELECT" ||
target.tagName === "BUTTON" ||
target.hasAttribute("contenteditable")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this condition be tightened/neatened up any?

// Default behavior: if user hasn't interacted, focus skip link
if (!hasUserInteracted) {
e.preventDefault()
const skipLink = document.querySelector(".nhsuk-skip-link") as HTMLElement
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be a little brittle if the css class name ever changes in the framework etc can we use an id that were in full control of instead?

lastElement.focus()
} else {
e.preventDefault()
const skipLink = document.querySelector(".nhsuk-skip-link") as HTMLElement
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skip link is being defined twice within this nested set of conditions, can it just be defined one before this block?

}

// Remove listeners after handling first tab
document.removeEventListener("keydown", handleKeyDown)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these same set of 4 removals happen in 2 places, is it worth pulling them out into a little common function?

activeElement !== document.body &&
activeElement.tagName !== "HTML" &&
(activeElement.tagName === "INPUT" ||
activeElement.tagName === "TEXTAREA" || activeElement.tagName === "SELECT")) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this condition be tightened up any?

document.removeEventListener("keydown", handleKeyDown)
const mainContent = document.querySelector("#main-content") || document.body
mainContent.removeEventListener("click", handleUserInteraction)
mainContent.removeEventListener("focusin", handleUserInteraction)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these the same set of removals from the helper? if so can a common function work for all occasions your doing this?

document.removeEventListener("keydown", handleKeyDown)
document.removeEventListener("click", handleUserInteraction)
document.removeEventListener("focusin", handleUserInteraction)
const mainContent = document.querySelector("#main-content") || document.body
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mainContent is defined twice, can it be moved up in scope and only defined once?

setTimeout(addDirectListeners, 100)

const mainContent = document.querySelector("#main-content") || document.body
mainContent.addEventListener("click", handleUserInteraction)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see other comments about having common functions for these add/remove listeners that are in several places

@sonarqubecloud
Copy link
Copy Markdown

@jonathanwelch1-nhs jonathanwelch1-nhs merged commit 259e4b1 into main Feb 26, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants