govuk_frontend_toolkit
Advanced tools
Comparing version 5.0.0 to 5.0.1
@@ -0,1 +1,7 @@ | ||
# 5.0.1 | ||
- Fix role="button" click shim ([PR #347](https://github.com/alphagov/govuk_frontend_toolkit/pull/347)) | ||
- Make font variables lowercase ([PR #348](https://github.com/alphagov/govuk_frontend_toolkit/pull/348)) | ||
- Update selection button documentation ([PR #350](https://github.com/alphagov/govuk_frontend_toolkit/pull/350)) | ||
# 5.0.0 | ||
@@ -2,0 +8,0 @@ |
// javascript 'shim' to trigger the click event of element(s) | ||
// when the space key is pressed. | ||
// | ||
// usage instructions: | ||
// Created since some Assistive Technologies (for example some Screenreaders) | ||
// Will tell a user to press space on a 'button', so this functionality needs to be shimmed | ||
// See https://github.com/alphagov/govuk_elements/pull/272#issuecomment-233028270 | ||
// | ||
// Usage instructions: | ||
// GOVUK.shimLinksWithButtonRole.init(); | ||
// | ||
// If you want to customise the shim you can pass in a custom configuration | ||
// object with your own selector for the target elements and addional keyup | ||
// codes if there becomes a need to do so. For example: | ||
// GOVUK.shimLinksWithButtonRole.init({ selector: '[role="button"]' }); | ||
;(function (global) { | ||
@@ -19,36 +18,12 @@ 'use strict' | ||
// default configuration that can be overridden by passing object as second parameter to module | ||
config: { | ||
// the target element(s) to attach the shim event to | ||
selector: 'a[role="button"]', | ||
// array of keys to match against upon the keyup event | ||
keycodes: [ | ||
32 // spacekey | ||
] | ||
}, | ||
// event behaviour (not a typical anonymous function for resuse if needed) | ||
triggerClickOnTarget: function triggerClickOnTarget (event) { | ||
// if the code from this event is in the keycodes array then | ||
if ($.inArray(event.which, this.config.keycodes) !== -1) { | ||
event.preventDefault() | ||
// trigger the target's click event | ||
event.target.click() | ||
} | ||
}, | ||
// By default this will find all links with role attribute set to | ||
// 'button' and will trigger their click event when the space key (32) is pressed. | ||
// @method init | ||
// @param {Object} customConfig object to override default configuration | ||
// {String} customConfig.selector a selector for the elements to be 'clicked' | ||
// {Array} customConfig.keycodes an array of javascript keycode values to match against that when pressed will trigger the click | ||
init: function init (customConfig) { | ||
// extend the default config with any custom attributes passed in | ||
this.config = $.extend(this.config, customConfig) | ||
// if we have found elements then: | ||
if ($(this.config.selector).length > 0) { | ||
// listen to 'document' for keyup event on the elements and fire the triggerClickOnTarget | ||
$(document).on('keyup', this.config.selector, this.triggerClickOnTarget.bind(this)) | ||
} | ||
init: function init () { | ||
// listen to 'document' for keydown event on the any elements that should be buttons. | ||
$(document).on('keydown', '[role="button"]', function (event) { | ||
// if the keyCode (which) is 32 it's a space, let's simulate a click. | ||
if (event.which === 32) { | ||
event.preventDefault() | ||
// trigger the target's click event | ||
event.target.click() | ||
} | ||
}) | ||
} | ||
@@ -55,0 +30,0 @@ |
{ | ||
"name": "govuk_frontend_toolkit", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "npm package for using the GOV.UK frontend toolkit", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -1,1 +0,1 @@ | ||
5.0.0 | ||
5.0.1 |
Sorry, the diff of this file is not supported yet
475368
1393