Socket
Socket
Sign inDemoInstall

govuk-frontend

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

govuk-frontend - npm Package Compare versions

Comparing version 3.7.0 to 3.8.0

24

govuk/components/character-count/character-count.js

@@ -1065,11 +1065,20 @@ (function (global, factory) {

// Bind event changes to the textarea
var boundChangeEvents = this.bindChangeEvents.bind(this);
boundChangeEvents();
// When the page is restored after navigating 'back' in some browsers the
// state of the character count is not restored until *after* the DOMContentLoaded
// event is fired, so we need to sync after the pageshow event in browsers
// that support it.
if ('onpageshow' in window) {
window.addEventListener('pageshow', this.sync.bind(this));
} else {
window.addEventListener('DOMContentLoaded', this.sync.bind(this));
}
// Update count message
var boundUpdateCountMessage = this.updateCountMessage.bind(this);
boundUpdateCountMessage();
this.sync();
};
CharacterCount.prototype.sync = function () {
this.bindChangeEvents();
this.updateCountMessage();
};
// Read data attributes

@@ -1120,4 +1129,3 @@ CharacterCount.prototype.getDataset = function (element) {

this.$textarea.oldValue = this.$textarea.value;
var boundUpdateCountMessage = this.updateCountMessage.bind(this);
boundUpdateCountMessage();
this.updateCountMessage();
}

@@ -1124,0 +1132,0 @@ };

@@ -92,2 +92,8 @@ [

{
"name": "spellcheck",
"type": "boolean",
"required": false,
"description": "Optional field to enable or disable the spellcheck attribute on the character count."
},
{
"name": "countMessage",

@@ -94,0 +100,0 @@ "type": "object",

@@ -1036,2 +1036,16 @@ (function (global, factory) {

/**
* Initialise Checkboxes
*
* Checkboxes can be associated with a 'conditionally revealed' content block –
* for example, a checkbox for 'Phone' could reveal an additional form field for
* the user to enter their phone number.
*
* These associations are made using a `data-aria-controls` attribute, which is
* promoted to an aria-controls attribute during initialisation.
*
* We also need to restore the state of any conditional reveals on the page (for
* example if the user has navigated back), and set up event handlers to keep
* the reveal in sync with the checkbox state.
*/
Checkboxes.prototype.init = function () {

@@ -1041,36 +1055,69 @@ var $module = this.$module;

/**
* Loop over all items with [data-controls]
* Check if they have a matching conditional reveal
* If they do, assign attributes.
**/
nodeListForEach($inputs, function ($input) {
var controls = $input.getAttribute('data-aria-controls');
var target = $input.getAttribute('data-aria-controls');
// Check if input controls anything
// Check if content exists, before setting attributes.
if (!controls || !$module.querySelector('#' + controls)) {
// Skip checkboxes without data-aria-controls attributes, or where the
// target element does not exist.
if (!target || !$module.querySelector('#' + target)) {
return
}
// If we have content that is controlled, set attributes.
$input.setAttribute('aria-controls', controls);
// Promote the data-aria-controls attribute to a aria-controls attribute
// so that the relationship is exposed in the AOM
$input.setAttribute('aria-controls', target);
$input.removeAttribute('data-aria-controls');
this.setAttributes($input);
}.bind(this));
});
// Handle events
// When the page is restored after navigating 'back' in some browsers the
// state of form controls is not restored until *after* the DOMContentLoaded
// event is fired, so we need to sync after the pageshow event in browsers
// that support it.
if ('onpageshow' in window) {
window.addEventListener('pageshow', this.syncAllConditionalReveals.bind(this));
} else {
window.addEventListener('DOMContentLoaded', this.syncAllConditionalReveals.bind(this));
}
// Although we've set up handlers to sync state on the pageshow or
// DOMContentLoaded event, init could be called after those events have fired,
// for example if they are added to the page dynamically, so sync now too.
this.syncAllConditionalReveals();
$module.addEventListener('click', this.handleClick.bind(this));
};
Checkboxes.prototype.setAttributes = function ($input) {
var inputIsChecked = $input.checked;
$input.setAttribute('aria-expanded', inputIsChecked);
/**
* Sync the conditional reveal states for all inputs in this $module.
*/
Checkboxes.prototype.syncAllConditionalReveals = function () {
nodeListForEach(this.$inputs, this.syncConditionalRevealWithInputState.bind(this));
};
var $content = this.$module.querySelector('#' + $input.getAttribute('aria-controls'));
if ($content) {
$content.classList.toggle('govuk-checkboxes__conditional--hidden', !inputIsChecked);
/**
* Sync conditional reveal with the input state
*
* Synchronise the visibility of the conditional reveal, and its accessible
* state, with the input's checked state.
*
* @param {HTMLInputElement} $input Checkbox input
*/
Checkboxes.prototype.syncConditionalRevealWithInputState = function ($input) {
var $target = this.$module.querySelector('#' + $input.getAttribute('aria-controls'));
if ($target && $target.classList.contains('govuk-checkboxes__conditional')) {
var inputIsChecked = $input.checked;
$input.setAttribute('aria-expanded', inputIsChecked);
$target.classList.toggle('govuk-checkboxes__conditional--hidden', !inputIsChecked);
}
};
/**
* Click event handler
*
* Handle a click within the $module – if the click occurred on a checkbox, sync
* the state of any associated conditional reveal with the checkbox state.
*
* @param {MouseEvent} event Click event
*/
Checkboxes.prototype.handleClick = function (event) {

@@ -1083,3 +1130,3 @@ var $target = event.target;

if (isCheckbox && hasAriaControls) {
this.setAttributes($target);
this.syncConditionalRevealWithInputState($target);
}

@@ -1086,0 +1133,0 @@ };

@@ -48,3 +48,3 @@ [

"required": false,
"description": "Attribute to [identify input purpose](https://www.w3.org/WAI/WCAG21/Understanding/identify-input-purpose.html), for instance \"postal-code\" or \"username\". See [autofill](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill) for full list of attributes that can be used."
"description": "Attribute to [identify input purpose](https://www.w3.org/WAI/WCAG21/Understanding/identify-input-purpose.html), for instance \"bday-day\". See [autofill](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill) for full list of attributes that can be used."
},

@@ -51,0 +51,0 @@ {

@@ -92,2 +92,8 @@ [

{
"name": "spellcheck",
"type": "boolean",
"required": false,
"description": "Optional field to enable or disable the spellcheck attribute on the input."
},
{
"name": "attributes",

@@ -94,0 +100,0 @@ "type": "object",

@@ -1033,28 +1033,53 @@ (function (global, factory) {

this.$module = $module;
this.$inputs = $module.querySelectorAll('input[type="radio"]');
}
/**
* Initialise Radios
*
* Radios can be associated with a 'conditionally revealed' content block – for
* example, a radio for 'Phone' could reveal an additional form field for the
* user to enter their phone number.
*
* These associations are made using a `data-aria-controls` attribute, which is
* promoted to an aria-controls attribute during initialisation.
*
* We also need to restore the state of any conditional reveals on the page (for
* example if the user has navigated back), and set up event handlers to keep
* the reveal in sync with the radio state.
*/
Radios.prototype.init = function () {
var $module = this.$module;
var $inputs = $module.querySelectorAll('input[type="radio"]');
var $inputs = this.$inputs;
/**
* Loop over all items with [data-controls]
* Check if they have a matching conditional reveal
* If they do, assign attributes.
**/
nodeListForEach($inputs, function ($input) {
var controls = $input.getAttribute('data-aria-controls');
var target = $input.getAttribute('data-aria-controls');
// Check if input controls anything
// Check if content exists, before setting attributes.
if (!controls || !$module.querySelector('#' + controls)) {
// Skip radios without data-aria-controls attributes, or where the
// target element does not exist.
if (!target || !$module.querySelector('#' + target)) {
return
}
// If we have content that is controlled, set attributes.
$input.setAttribute('aria-controls', controls);
// Promote the data-aria-controls attribute to a aria-controls attribute
// so that the relationship is exposed in the AOM
$input.setAttribute('aria-controls', target);
$input.removeAttribute('data-aria-controls');
this.setAttributes($input);
}.bind(this));
});
// When the page is restored after navigating 'back' in some browsers the
// state of form controls is not restored until *after* the DOMContentLoaded
// event is fired, so we need to sync after the pageshow event in browsers
// that support it.
if ('onpageshow' in window) {
window.addEventListener('pageshow', this.syncAllConditionalReveals.bind(this));
} else {
window.addEventListener('DOMContentLoaded', this.syncAllConditionalReveals.bind(this));
}
// Although we've set up handlers to sync state on the pageshow or
// DOMContentLoaded event, init could be called after those events have fired,
// for example if they are added to the page dynamically, so sync now too.
this.syncAllConditionalReveals();
// Handle events

@@ -1064,33 +1089,56 @@ $module.addEventListener('click', this.handleClick.bind(this));

Radios.prototype.setAttributes = function ($input) {
var $content = document.querySelector('#' + $input.getAttribute('aria-controls'));
/**
* Sync the conditional reveal states for all inputs in this $module.
*/
Radios.prototype.syncAllConditionalReveals = function () {
nodeListForEach(this.$inputs, this.syncConditionalRevealWithInputState.bind(this));
};
if ($content && $content.classList.contains('govuk-radios__conditional')) {
/**
* Sync conditional reveal with the input state
*
* Synchronise the visibility of the conditional reveal, and its accessible
* state, with the input's checked state.
*
* @param {HTMLInputElement} $input Radio input
*/
Radios.prototype.syncConditionalRevealWithInputState = function ($input) {
var $target = document.querySelector('#' + $input.getAttribute('aria-controls'));
if ($target && $target.classList.contains('govuk-radios__conditional')) {
var inputIsChecked = $input.checked;
$input.setAttribute('aria-expanded', inputIsChecked);
$content.classList.toggle('govuk-radios__conditional--hidden', !inputIsChecked);
$target.classList.toggle('govuk-radios__conditional--hidden', !inputIsChecked);
}
};
/**
* Click event handler
*
* Handle a click within the $module – if the click occurred on a radio, sync
* the state of the conditional reveal for all radio buttons in the same form
* with the same name (because checking one radio could have un-checked a radio
* in another $module)
*
* @param {MouseEvent} event Click event
*/
Radios.prototype.handleClick = function (event) {
var $clickedInput = event.target;
// We only want to handle clicks for radio inputs
// Ignore clicks on things that aren't radio buttons
if ($clickedInput.type !== 'radio') {
return
}
// Because checking one radio can uncheck a radio in another $module,
// we need to call set attributes on all radios in the same form, or document if they're not in a form.
//
// We also only want radios which have aria-controls, as they support conditional reveals.
// We only need to consider radios with conditional reveals, which will have
// aria-controls attributes.
var $allInputs = document.querySelectorAll('input[type="radio"][aria-controls]');
nodeListForEach($allInputs, function ($input) {
// Only inputs with the same form owner should change.
var hasSameFormOwner = ($input.form === $clickedInput.form);
var hasSameName = ($input.name === $clickedInput.name);
// In radios, only radios with the same name will affect each other.
var hasSameName = ($input.name === $clickedInput.name);
if (hasSameName && hasSameFormOwner) {
this.setAttributes($input);
this.syncConditionalRevealWithInputState($input);
}

@@ -1097,0 +1145,0 @@ }.bind(this));

@@ -15,2 +15,8 @@ [

{
"name": "spellcheck",
"type": "boolean",
"required": false,
"description": "Optional field to enable or disable the spellcheck attribute on the textarea."
},
{
"name": "rows",

@@ -17,0 +23,0 @@ "type": "string",

{
"name": "govuk-frontend",
"description": "GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.",
"version": "3.7.0",
"version": "3.8.0",
"main": "govuk/all.js",

@@ -6,0 +6,0 @@ "sass": "govuk/all.scss",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc