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 +4 -4
- data/app/assets/CHANGELOG.md +6 -0
- data/app/assets/VERSION.txt +1 -1
- data/app/assets/docs/javascript.md +44 -17
- data/app/assets/javascripts/govuk/shim-links-with-button-role.js +15 -40
- data/app/assets/spec/unit/shim-links-with-button-role.spec.js +7 -7
- data/app/assets/stylesheets/_font_stack.scss +15 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9323b826f363ecc6b9568dcc5db77a364425fac2
|
4
|
+
data.tar.gz: db6f03750e7435ee005300a65deabb26bc5cd136
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4eef6173b14e493c9f8e2c82346663c793769b005574db6bd8778c5e7366a0bae880a0b65b23c9723009ea46ada2d60343b52edd24291e82f6f8b0c6cd082e02
|
7
|
+
data.tar.gz: 9fab80347956b8e584c7d4bf46da2de0a72ca36362c90d1de4fb72ee32762844f73a9e04c759c7b29051843a76538276262ed48f8c84b962bcd3cbe1efe49dd0
|
data/app/assets/CHANGELOG.md
CHANGED
@@ -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:
|
data/app/assets/VERSION.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.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
|
-
|
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
|
-
|
348
|
-
|
349
|
-
|
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
|
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
|
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 = $(
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
//
|
5
|
-
//
|
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
|
-
//
|
8
|
-
//
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
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
|
-
|
19
|
-
|
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
|
-
|
32
|
-
$(document).trigger(
|
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
|
-
|
38
|
-
$(document).trigger(
|
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
|
-
$
|
8
|
-
$
|
4
|
+
$nta-light: "nta", Arial, sans-serif;
|
5
|
+
$nta-light-tabular: "ntatabularnumbers", $nta-light;
|
9
6
|
|
10
7
|
// Helvetica Regular
|
11
|
-
$
|
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: $
|
16
|
-
$toolkit-font-stack-tabular: $
|
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
|
-
$
|
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.
|
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-
|
11
|
+
date: 2016-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|