govuk_frontend_toolkit 5.0.0 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff8f1703a8d15e9962e1a8c93c443accd075c4c6
4
- data.tar.gz: a494d718895df6b12456aad04b7dd88ad91990d6
3
+ metadata.gz: 9323b826f363ecc6b9568dcc5db77a364425fac2
4
+ data.tar.gz: db6f03750e7435ee005300a65deabb26bc5cd136
5
5
  SHA512:
6
- metadata.gz: d780600b4e3d022d7c7ca4ba0a9bf093f5a87d1c89e98362f51db2441132a0c5e12d4b89d686d3ca4c4efe6dcdb8db36add955f8d21c123e5231b12a190f6593
7
- data.tar.gz: 3899d64d9b3d12e427ba54b728767af1ed1e6a709bd68c140b4a2ef9045b140ed23ec03a5d0a1ce7614c99230251c83d88cb080acbb58bfc65377fc521b07250
6
+ metadata.gz: 4eef6173b14e493c9f8e2c82346663c793769b005574db6bd8778c5e7366a0bae880a0b65b23c9723009ea46ada2d60343b52edd24291e82f6f8b0c6cd082e02
7
+ data.tar.gz: 9fab80347956b8e584c7d4bf46da2de0a72ca36362c90d1de4fb72ee32762844f73a9e04c759c7b29051843a76538276262ed48f8c84b962bcd3cbe1efe49dd0
@@ -1,3 +1,9 @@
1
+ # 5.0.1
2
+
3
+ - Fix role="button" click shim ([PR #347](https://github.com/alphagov/govuk_frontend_toolkit/pull/347))
4
+ - Make font variables lowercase ([PR #348](https://github.com/alphagov/govuk_frontend_toolkit/pull/348))
5
+ - Update selection button documentation ([PR #350](https://github.com/alphagov/govuk_frontend_toolkit/pull/350))
6
+
1
7
  # 5.0.0
2
8
 
3
9
  This release includes two breaking changes:
@@ -1 +1 @@
1
- 5.0.0
1
+ 5.0.1
@@ -51,7 +51,7 @@ The simplest module looks like:
51
51
  ```javascript
52
52
  ;(function(Modules) {
53
53
  'use strict'
54
-
54
+
55
55
  Modules.SomeModule = function() {
56
56
  this.start = function($element) {
57
57
  // module code
@@ -342,40 +342,67 @@ and stop the elements before they get to the bottom.
342
342
 
343
343
  ## Selection buttons
344
344
 
345
- Script to support a design of radio buttons and checkboxes requiring them to be wrapped in `<label>` tags:
345
+ `GOVUK.SelectionButtons` adds classes to a parent `<label>` of a radio button or checkbox, allowing you to style it based on the input’s state. Given this example HTML structure:
346
346
 
347
- <label>
348
- <input type="radio" name="size" value="medium" />
349
- </label>
347
+ ```html
348
+ <label>
349
+ <input type="radio" name="size" value="medium" />
350
+ Medium size
351
+ </label>
352
+ ```
350
353
 
351
- When the input is focused or its `checked` attribute is set, classes are added to their parent labels so their styling can show this.
354
+ When the input is focused or its `checked` attribute is set, representative classes are added to the label.
352
355
 
353
356
  ### Usage
354
357
 
355
358
  #### GOVUK.SelectionButtons
356
359
 
357
- To apply this behaviour to elements with the above HTML pattern, call the `GOVUK.SelectionButtons` constructor with their inputs:
360
+ To apply this behaviour to elements that follow the above HTML, call the `GOVUK.SelectionButtons` constructor with a jQuery collection of the inputs:
358
361
 
359
- ```
360
- var $buttons = $("label input[type='radio'], label input[type='checkbox']")
362
+ ```javascript
363
+ var $buttons = $('label input[type=radio], label input[type=checkbox]')
361
364
  var selectionButtons = new GOVUK.SelectionButtons($buttons)
362
365
  ```
363
366
 
364
- You can also call `GOVUK.SelectionButtons` with a selector:
367
+ If you want to bind your events to the document instead of the elements directly (delegated events) you can call `GOVUK.SelectionButtons` with a selector string:
365
368
 
369
+ ```javascript
370
+ var selectionButtons = new GOVUK.SelectionButtons('label input[type=radio], label input[type=checkbox]')
366
371
  ```
367
- var selectionButtons = new GOVUK.SelectionButtons("label input[type='radio'], label input[type='checkbox']")
372
+
373
+ This will bind all events to the document meaning any new elements (for example, by AJAX) that match this selector will automatically gain this functionality.
374
+
375
+ If you do add elements that need this functionality dynamically to the page, you will need to initialise their state. You can do this by calling `SelectionButtons.setInitialState` with the same selector string:
376
+
377
+ ```javascript
378
+ var buttonSelector = 'label input[type=radio], label input[type=checkbox]'
379
+ var selectionButtons = new GOVUK.SelectionButtons(buttonSelector)
368
380
  ```
369
381
 
370
- This will bind all events to the document, meaning any changes to content (for example, by AJAX) will not effect the button's behaviour.
382
+ then later, after adding more elements:
383
+
384
+ ```javascript
385
+ selectionButtons.setInitialState(buttonSelector)
386
+ ```
371
387
 
372
388
  The classes that get added to the `<label>` tags can be passed in as options:
373
389
 
390
+ ```javascript
391
+ var $buttons = $('label input[type=radio], label input[type=checkbox]')
392
+ var selectionButtons = new GOVUK.SelectionButtons($buttons, {
393
+ focusedClass: 'selectable-focused',
394
+ selectedClass: 'selectable-selected'
395
+ })
374
396
  ```
375
- var $buttons = $("label input[type='radio'], label input[type='checkbox']")
376
- var selectionButtons = new GOVUK.SelectionButtons($buttons, { focusedClass : 'selectable-focused', selectedClass : 'selectable-selected' })
377
397
 
378
- var selectionButtons = new GOVUK.SelectionButtons("label input[type='radio'], label input[type='checkbox']", { focusedClass : 'selectable-focused', selectedClass : 'selectable-selected' })
398
+ or, using delegated events:
399
+
400
+ ```javascript
401
+ var buttonSelector = 'label input[type=radio], label input[type=checkbox]'
402
+ var selectionButtons = new GOVUK.SelectionButtons($buttonSelector, {
403
+ focusedClass: 'selectable-focused',
404
+ selectedClass: 'selectable-selected'
405
+ })
379
406
  ```
380
407
 
381
408
  #### destroy method
@@ -384,7 +411,7 @@ The returned instance object includes a `destroy` method to remove all events bo
384
411
 
385
412
  Using any of the `selectionButtons` objects created above, it can be called like so:
386
413
 
387
- ```
414
+ ```javascript
388
415
  selectionButtons.destroy();
389
416
  ```
390
417
 
@@ -392,7 +419,7 @@ selectionButtons.destroy();
392
419
 
393
420
  The previous method of calling selection buttons is now deprecated. If you need to call them using this method, you will need to define this function:
394
421
 
395
- ```
422
+ ```javascript
396
423
  GOVUK.selectionButtons = function (elms, opts) {
397
424
  new GOVUK.SelectionButtons(elms, opts)
398
425
  }
@@ -1,13 +1,12 @@
1
1
  // javascript 'shim' to trigger the click event of element(s)
2
2
  // when the space key is pressed.
3
3
  //
4
- // usage instructions:
5
- // GOVUK.shimLinksWithButtonRole.init();
4
+ // Created since some Assistive Technologies (for example some Screenreaders)
5
+ // Will tell a user to press space on a 'button', so this functionality needs to be shimmed
6
+ // See https://github.com/alphagov/govuk_elements/pull/272#issuecomment-233028270
6
7
  //
7
- // If you want to customise the shim you can pass in a custom configuration
8
- // object with your own selector for the target elements and addional keyup
9
- // codes if there becomes a need to do so. For example:
10
- // GOVUK.shimLinksWithButtonRole.init({ selector: '[role="button"]' });
8
+ // Usage instructions:
9
+ // GOVUK.shimLinksWithButtonRole.init();
11
10
  ;(function (global) {
12
11
  'use strict'
13
12
 
@@ -16,40 +15,16 @@
16
15
 
17
16
  GOVUK.shimLinksWithButtonRole = {
18
17
 
19
- // default configuration that can be overridden by passing object as second parameter to module
20
- config: {
21
- // the target element(s) to attach the shim event to
22
- selector: 'a[role="button"]',
23
- // array of keys to match against upon the keyup event
24
- keycodes: [
25
- 32 // spacekey
26
- ]
27
- },
28
-
29
- // event behaviour (not a typical anonymous function for resuse if needed)
30
- triggerClickOnTarget: function triggerClickOnTarget (event) {
31
- // if the code from this event is in the keycodes array then
32
- if ($.inArray(event.which, this.config.keycodes) !== -1) {
33
- event.preventDefault()
34
- // trigger the target's click event
35
- event.target.click()
36
- }
37
- },
38
-
39
- // By default this will find all links with role attribute set to
40
- // 'button' and will trigger their click event when the space key (32) is pressed.
41
- // @method init
42
- // @param {Object} customConfig object to override default configuration
43
- // {String} customConfig.selector a selector for the elements to be 'clicked'
44
- // {Array} customConfig.keycodes an array of javascript keycode values to match against that when pressed will trigger the click
45
- init: function init (customConfig) {
46
- // extend the default config with any custom attributes passed in
47
- this.config = $.extend(this.config, customConfig)
48
- // if we have found elements then:
49
- if ($(this.config.selector).length > 0) {
50
- // listen to 'document' for keyup event on the elements and fire the triggerClickOnTarget
51
- $(document).on('keyup', this.config.selector, this.triggerClickOnTarget.bind(this))
52
- }
18
+ init: function init () {
19
+ // listen to 'document' for keydown event on the any elements that should be buttons.
20
+ $(document).on('keydown', '[role="button"]', function (event) {
21
+ // if the keyCode (which) is 32 it's a space, let's simulate a click.
22
+ if (event.which === 32) {
23
+ event.preventDefault()
24
+ // trigger the target's click event
25
+ event.target.click()
26
+ }
27
+ })
53
28
  }
54
29
 
55
30
  }
@@ -7,7 +7,7 @@ describe('shim-links-with-button-role', function () {
7
7
  var GOVUK = window.GOVUK
8
8
 
9
9
  var $buttonLink
10
- var keyupEvent
10
+ var keyDownEvent
11
11
 
12
12
  beforeEach(function () {
13
13
  $buttonLink = $('<a role="button">Button</a>')
@@ -15,8 +15,8 @@ describe('shim-links-with-button-role', function () {
15
15
  $buttonLink.addClass('clicked')
16
16
  })
17
17
  $(document.body).append($buttonLink)
18
- keyupEvent = $.Event('keyup')
19
- keyupEvent.target = $buttonLink.get(0)
18
+ keyDownEvent = $.Event('keydown')
19
+ keyDownEvent.target = $buttonLink.get(0)
20
20
  GOVUK.shimLinksWithButtonRole.init()
21
21
  })
22
22
 
@@ -28,14 +28,14 @@ describe('shim-links-with-button-role', function () {
28
28
  it('should trigger event on space', function () {
29
29
  // Ideally we’d test the page loading functionality but that seems hard to
30
30
  // do within a Jasmine context. Settle for checking a bound event trigger.
31
- keyupEvent.which = 32 // Space character
32
- $(document).trigger(keyupEvent)
31
+ keyDownEvent.which = 32 // Space character
32
+ $(document).trigger(keyDownEvent)
33
33
  expect($buttonLink.hasClass('clicked')).toBe(true)
34
34
  })
35
35
 
36
36
  it('should not trigger event on tab', function () {
37
- keyupEvent.which = 9 // Tab character
38
- $(document).trigger(keyupEvent)
37
+ keyDownEvent.which = 9 // Tab character
38
+ $(document).trigger(keyDownEvent)
39
39
  expect($buttonLink.hasClass('clicked')).toBe(false)
40
40
  })
41
41
  })
@@ -1,19 +1,25 @@
1
1
  // GOV.UK font stacks, referred to in typography.scss
2
2
 
3
- // Allow uppercase letters in font stack variable names
4
- // scss-lint:disable NameFormat
5
-
6
3
  // New Transport Light
7
- $NTA-Light: "nta", Arial, sans-serif;
8
- $NTA-Light-Tabular: "ntatabularnumbers", $NTA-Light;
4
+ $nta-light: "nta", Arial, sans-serif;
5
+ $nta-light-tabular: "ntatabularnumbers", $nta-light;
9
6
 
10
7
  // Helvetica Regular
11
- $Helvetica-Regular: "HelveticaNeue", "Helvetica Neue", "Arial", "Helvetica", sans-serif;
8
+ $helvetica-regular: "HelveticaNeue", "Helvetica Neue", "Arial", "Helvetica", sans-serif;
12
9
 
13
10
  // Allow font stack to be overridden
14
11
  // Not all apps using toolkit use New Transport
15
- $toolkit-font-stack: $NTA-Light !default;
16
- $toolkit-font-stack-tabular: $NTA-Light-Tabular !default;
12
+ $toolkit-font-stack: $nta-light !default;
13
+ $toolkit-font-stack-tabular: $nta-light-tabular !default;
17
14
 
18
15
  // Font reset for print
19
- $Print-reset: sans-serif;
16
+ $print-reset: sans-serif;
17
+
18
+ // Fallback variable names after renaming previous uppercase names to be lowercase
19
+ // @deprecated, please only use the lowercase versions
20
+ // Make an exception to the linting as these are still used a lot
21
+ // scss-lint:disable NameFormat
22
+ $NTA-Light: $nta-light;
23
+ $NTA-Light-Tabular: $nta-light-tabular;
24
+ $Helvetica-Regular: $helvetica-regular;
25
+ $Print-reset: $print-reset;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_frontend_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-25 00:00:00.000000000 Z
11
+ date: 2016-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails