You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On page load, the button component's javascript binds to all elements with data-module="button" in order to run the debouncing, and the spacebar activation for links as buttons.
There's a comment in the code which says:
/**
* Initialise an event listener for keydown at document level
* this will help listening for later inserted elements with a role="button"
*/
but this isn't true. The button code is invoked with individual button elements as follows:
which means that $module inside the code corresponds to an individual button, not to the document element. And so the events are bound directly to the individual buttons.
This means that any buttons which are added after this JS has run will not have this behaviour.
I suspect the comment in the JS came across from govuk-frontend when it was ported over, but during refactoring to make it follow nhsuk-frontend JS patterns the bug has been introduced.
I think the fix should be as simple as removing that querySelectorAll / foreach combo, and just init the Button class on the document element.
What was the environment where this issue occurred?
NHS.UK frontend package version: Anything 6.2.0 - 8.x has this issue.
The text was updated successfully, but these errors were encountered:
Bug Report
What is the issue?
On page load, the button component's javascript binds to all elements with
data-module="button"
in order to run the debouncing, and the spacebar activation for links as buttons.There's a comment in the code which says:
but this isn't true. The button code is invoked with individual button elements as follows:
which means that
$module
inside the code corresponds to an individual button, not to the document element. And so the events are bound directly to the individual buttons.This means that any buttons which are added after this JS has run will not have this behaviour.
I suspect the comment in the JS came across from govuk-frontend when it was ported over, but during refactoring to make it follow nhsuk-frontend JS patterns the bug has been introduced.
I think the fix should be as simple as removing that querySelectorAll / foreach combo, and just init the Button class on the document element.
What was the environment where this issue occurred?
The text was updated successfully, but these errors were encountered: