govuk_publishing_components 15.1.0 → 15.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/govuk_publishing_components/components/accessible-autocomplete.js +24 -16
- data/app/assets/stylesheets/govuk_publishing_components/components/_accessible-autocomplete.scss +27 -1
- data/app/views/govuk_publishing_components/components/_accessible_autocomplete.html.erb +12 -2
- data/app/views/govuk_publishing_components/components/_subscription-links.html.erb +8 -5
- data/app/views/govuk_publishing_components/components/docs/accessible_autocomplete.yml +15 -0
- data/app/views/govuk_publishing_components/components/docs/subscription-links.yml +6 -0
- data/config/locales/en.yml +2 -0
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/node_modules/accessible-autocomplete/dist/accessible-autocomplete.min.css +1 -1
- data/node_modules/accessible-autocomplete/dist/accessible-autocomplete.min.js +1 -1
- data/node_modules/accessible-autocomplete/dist/accessible-autocomplete.min.js.map +1 -1
- data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.preact.min.js +1 -1
- data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.preact.min.js.map +1 -1
- data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.react.min.js +1 -1
- data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.react.min.js.map +1 -1
- data/node_modules/accessible-autocomplete/examples/index.html +49 -0
- data/node_modules/accessible-autocomplete/examples/multiselect.html +134 -0
- data/node_modules/accessible-autocomplete/package-lock.json +14491 -0
- data/node_modules/accessible-autocomplete/package.json +34 -53
- data/node_modules/accessible-autocomplete/src/autocomplete.css +49 -7
- data/node_modules/accessible-autocomplete/src/autocomplete.js +101 -1
- data/node_modules/accessible-autocomplete/src/wrapper.js +13 -1
- metadata +4 -2
@@ -2,49 +2,56 @@
|
|
2
2
|
"_args": [
|
3
3
|
[
|
4
4
|
{
|
5
|
-
"raw": "accessible-autocomplete
|
5
|
+
"raw": "accessible-autocomplete@git://github.com/alphagov/accessible-autocomplete.git#add-multiselect-support",
|
6
6
|
"scope": null,
|
7
7
|
"escapedName": "accessible-autocomplete",
|
8
8
|
"name": "accessible-autocomplete",
|
9
|
-
"rawSpec": "
|
10
|
-
"spec": "
|
11
|
-
"type": "
|
9
|
+
"rawSpec": "git://github.com/alphagov/accessible-autocomplete.git#add-multiselect-support",
|
10
|
+
"spec": "git://github.com/alphagov/accessible-autocomplete.git#add-multiselect-support",
|
11
|
+
"type": "hosted",
|
12
|
+
"hosted": {
|
13
|
+
"type": "github",
|
14
|
+
"ssh": "git@github.com:alphagov/accessible-autocomplete.git#add-multiselect-support",
|
15
|
+
"sshUrl": "git+ssh://git@github.com/alphagov/accessible-autocomplete.git#add-multiselect-support",
|
16
|
+
"httpsUrl": "git+https://github.com/alphagov/accessible-autocomplete.git#add-multiselect-support",
|
17
|
+
"gitUrl": "git://github.com/alphagov/accessible-autocomplete.git#add-multiselect-support",
|
18
|
+
"shortcut": "github:alphagov/accessible-autocomplete#add-multiselect-support",
|
19
|
+
"directUrl": "https://raw.githubusercontent.com/alphagov/accessible-autocomplete/add-multiselect-support/package.json"
|
20
|
+
}
|
12
21
|
},
|
13
22
|
"/var/lib/jenkins/workspace/ublishing_components_master-N4FWJIUY4CIFHKGZOAAEVVXODRY3YBORQOPIBBXWX72VUPSGJRRQ"
|
14
23
|
]
|
15
24
|
],
|
16
|
-
"_from": "accessible-autocomplete
|
17
|
-
"_hasShrinkwrap": false,
|
25
|
+
"_from": "git://github.com/alphagov/accessible-autocomplete.git#add-multiselect-support",
|
18
26
|
"_id": "accessible-autocomplete@1.6.2",
|
19
27
|
"_inCache": true,
|
20
28
|
"_location": "/accessible-autocomplete",
|
21
|
-
"_nodeVersion": "8.9.4",
|
22
|
-
"_npmOperationalInternal": {
|
23
|
-
"host": "s3://npm-registry-packages",
|
24
|
-
"tmp": "tmp/accessible-autocomplete_1.6.2_1542120962811_0.125232612907197"
|
25
|
-
},
|
26
|
-
"_npmUser": {
|
27
|
-
"name": "alphagov",
|
28
|
-
"email": "govuk-dev@digital.cabinet-office.gov.uk"
|
29
|
-
},
|
30
|
-
"_npmVersion": "5.6.0",
|
31
29
|
"_phantomChildren": {},
|
32
30
|
"_requested": {
|
33
|
-
"raw": "accessible-autocomplete
|
31
|
+
"raw": "accessible-autocomplete@git://github.com/alphagov/accessible-autocomplete.git#add-multiselect-support",
|
34
32
|
"scope": null,
|
35
33
|
"escapedName": "accessible-autocomplete",
|
36
34
|
"name": "accessible-autocomplete",
|
37
|
-
"rawSpec": "
|
38
|
-
"spec": "
|
39
|
-
"type": "
|
35
|
+
"rawSpec": "git://github.com/alphagov/accessible-autocomplete.git#add-multiselect-support",
|
36
|
+
"spec": "git://github.com/alphagov/accessible-autocomplete.git#add-multiselect-support",
|
37
|
+
"type": "hosted",
|
38
|
+
"hosted": {
|
39
|
+
"type": "github",
|
40
|
+
"ssh": "git@github.com:alphagov/accessible-autocomplete.git#add-multiselect-support",
|
41
|
+
"sshUrl": "git+ssh://git@github.com/alphagov/accessible-autocomplete.git#add-multiselect-support",
|
42
|
+
"httpsUrl": "git+https://github.com/alphagov/accessible-autocomplete.git#add-multiselect-support",
|
43
|
+
"gitUrl": "git://github.com/alphagov/accessible-autocomplete.git#add-multiselect-support",
|
44
|
+
"shortcut": "github:alphagov/accessible-autocomplete#add-multiselect-support",
|
45
|
+
"directUrl": "https://raw.githubusercontent.com/alphagov/accessible-autocomplete/add-multiselect-support/package.json"
|
46
|
+
}
|
40
47
|
},
|
41
48
|
"_requiredBy": [
|
42
49
|
"/"
|
43
50
|
],
|
44
|
-
"_resolved": "
|
45
|
-
"_shasum": "
|
51
|
+
"_resolved": "git://github.com/alphagov/accessible-autocomplete.git#0c518b4fa79b9a95b544410858486ed9e6403c84",
|
52
|
+
"_shasum": "13aa3d1cdc2e88f8d67b6974cc5f76c06e6aed45",
|
46
53
|
"_shrinkwrap": null,
|
47
|
-
"_spec": "accessible-autocomplete
|
54
|
+
"_spec": "accessible-autocomplete@git://github.com/alphagov/accessible-autocomplete.git#add-multiselect-support",
|
48
55
|
"_where": "/var/lib/jenkins/workspace/ublishing_components_master-N4FWJIUY4CIFHKGZOAAEVVXODRY3YBORQOPIBBXWX72VUPSGJRRQ",
|
49
56
|
"author": {
|
50
57
|
"name": "Government Digital Service",
|
@@ -98,7 +105,7 @@
|
|
98
105
|
"karma-sourcemap-loader": "^0.3.7",
|
99
106
|
"karma-webpack": "^4.0.0-rc.2",
|
100
107
|
"mocha": "^5.2.0",
|
101
|
-
"npm-run-all": "^4.1.
|
108
|
+
"npm-run-all": "^4.1.5",
|
102
109
|
"puppeteer": "^1.10.0",
|
103
110
|
"replace-bundle-webpack-plugin": "^1.0.0",
|
104
111
|
"sinon": "^6.3.5",
|
@@ -119,16 +126,7 @@
|
|
119
126
|
"webpack-dev-server": "^3.1.10",
|
120
127
|
"webpack-sources": "^1.3.0"
|
121
128
|
},
|
122
|
-
"
|
123
|
-
"dist": {
|
124
|
-
"integrity": "sha512-7S+6Vi82LQFSSd5feKedu46tiY2/DShpdXiRp0NY3cLwc+DKe1ayWd66mb3JVi8LTQubRM7jco+u92e6w0bbvg==",
|
125
|
-
"shasum": "cb69d37748ba5b0351c84422468538890e25759c",
|
126
|
-
"tarball": "https://registry.npmjs.org/accessible-autocomplete/-/accessible-autocomplete-1.6.2.tgz",
|
127
|
-
"fileCount": 37,
|
128
|
-
"unpackedSize": 540441,
|
129
|
-
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb6uYDCRA9TVsSAnZWagAAo6sP/igz39UbvmkraVAOGsF2\nqyHQ8DzJv6pIU9qXyZ7mEVk9gTpBtZQVKLtK2X9Pi9ZitKOO4P9+R04CuYur\n6EYrD1YAwrIcuK4Rr7nsnmfsRQxijdmuXTSRQI/nXCeRsqPMuaCphpVdnBkV\nsuOV40I+zuWDQn+2tK9JS/SyW0UF9kAf54uk/VntpricZK9BPESt/40uUYKn\nqSxG3grkfwvE7DoJlI2HuZ0Q1/CR9xHBYtmUu7oYbyO1KWSEzjdZvNf7+zb9\nuEHWTzueLO1O572XxEp8rjLJB1U5W/cu7GLQBDD1/5ShGK3ghJnea2zpCEGn\nEZAK/llomb6X4jdUqsh8glyhhq4qwm/7JGPRrraTODzSIAXgpCZ/a88FSJ+x\n58ZEzB+bCA/h+YRpG5yehWiObLCz0lHMcSW38vZwX0xgrtVBgxzFS88r+QR8\ntKLfoTTJWa7cjlbWfFCIip6H3oSYKKg3uW8wKCqFt91sMp2//9ctFUfmavJm\nkQzvSpDcCz5C7Na11XDlsdz3x5RoYUGnhBXlNEtpZ/SN5cA7XZFyEa6hSu9J\nZzCpaxK7HdXx01i7yCx83oZxPkwXcOzwEVB1B/3kssKZgtuO6pAW+17s8HTA\nwpVJX6g2Wrrfgr/6uBqznlS4E8LhMwceJLSy2gbTD/8Akn9Lv8ntwyNyGomA\nQ6iu\r\n=i6eo\r\n-----END PGP SIGNATURE-----\r\n"
|
130
|
-
},
|
131
|
-
"gitHead": "70af963ba97f840025a6ee0569b2e9a687e904f9",
|
129
|
+
"gitHead": "0c518b4fa79b9a95b544410858486ed9e6403c84",
|
132
130
|
"homepage": "https://github.com/alphagov/accessible-autocomplete#readme",
|
133
131
|
"husky": {
|
134
132
|
"hooks": {
|
@@ -146,27 +144,10 @@
|
|
146
144
|
],
|
147
145
|
"license": "MIT",
|
148
146
|
"main": "dist/accessible-autocomplete.min.js",
|
149
|
-
"maintainers": [
|
150
|
-
{
|
151
|
-
"name": "alphagov",
|
152
|
-
"email": "govuk-dev@digital.cabinet-office.gov.uk"
|
153
|
-
},
|
154
|
-
{
|
155
|
-
"name": "carolinegreen",
|
156
|
-
"email": "caroline.green@digital.cabinet-office.gov.uk"
|
157
|
-
},
|
158
|
-
{
|
159
|
-
"name": "danmitchell-",
|
160
|
-
"email": "dan@digitalreflow.co.uk"
|
161
|
-
},
|
162
|
-
{
|
163
|
-
"name": "tvararu",
|
164
|
-
"email": "theo@vararu.org"
|
165
|
-
}
|
166
|
-
],
|
167
147
|
"name": "accessible-autocomplete",
|
168
148
|
"optionalDependencies": {},
|
169
|
-
"readme": "ERROR: No README data found!",
|
149
|
+
"readme": "# Accessible autocomplete\n\n[![npm version](https://img.shields.io/npm/v/accessible-autocomplete.svg)](http://npm.im/accessible-autocomplete)\n[![Build Status](https://travis-ci.org/alphagov/accessible-autocomplete.svg?branch=master)](https://travis-ci.org/alphagov/accessible-autocomplete)\n[![Coverage Status](https://coveralls.io/repos/github/alphagov/accessible-autocomplete/badge.svg?branch=master)](https://coveralls.io/github/alphagov/accessible-autocomplete?branch=master)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![Greenkeeper badge](https://badges.greenkeeper.io/alphagov/accessible-autocomplete.svg)](https://greenkeeper.io/)\n[![gzip size](http://img.badgesize.io/https://unpkg.com/accessible-autocomplete/dist/accessible-autocomplete.min.js?compression=gzip)](https://unpkg.com/accessible-autocomplete/dist/accessible-autocomplete.min.js)\n\n[![Sauce Labs Build Status](https://saucelabs.com/browser-matrix/tvararu-alphagov.svg)](https://saucelabs.com/u/tvararu-alphagov)\n\n`accessible-autocomplete` is a JavaScript autocomplete built from the ground up to be accessible. The design goals are:\n\n- **Accessibility**: Following WAI-ARIA best practices and testing with assistive technologies.\n- **User experience**: Supporting a wide variety of user needs.\n- **Compatibility**: Working with as many browsers, devices, and assistive technologies as possible.\n\n[Try out the examples!](https://alphagov.github.io/accessible-autocomplete/examples/)\n\n## Installation / usage\n\n### Using npm and a module system\n\nInstall it by running:\n\n```bash\nnpm install --save accessible-autocomplete\n```\n\nThe `accessibleAutocomplete` function will render an autocomplete `<input>` and its accompanying suggestions and `aria-live` region. Your page should provide a `<label>` and a container element:\n\n```html\n<label for=\"my-autocomplete\">Select your country</label>\n<div id=\"my-autocomplete-container\"></div>\n```\n\nThen import it using a module system like Browserify / Webpack / Rollup, and call the `accessibleAutocomplete` function, providing an array of values:\n\n```js\nimport accessibleAutocomplete from 'accessible-autocomplete'\n\nconst countries = [\n 'France',\n 'Germany',\n 'United Kingdom'\n]\n\naccessibleAutocomplete({\n element: document.querySelector('#my-autocomplete-container'),\n id: 'my-autocomplete', // To match it to the existing <label>.\n source: countries\n})\n```\n\nIf you want to use it as a replacement for a `<select>` element, read the [Progressive enhancement](#progressive-enhancement) section.\n\n### As a plain JavaScript module\n\nYou can copy the [dist/accessible-autocomplete.min.js](dist/accessible-autocomplete.min.js) file to your JavaScript folder and import it into the browser:\n\n```html\n<script type=\"text/javascript\" src=\"assets/js/accessible-autocomplete.min.js\"></script>\n```\n\n### Styling the autocomplete\n\nA stylesheet is included with the package at [dist/accessible-autocomplete.min.css](dist/accessible-autocomplete.min.css).\n\nYou can copy it to your stylesheets folder and import it into the browser:\n\n```html\n<link rel=\"stylesheet\" href=\"assets/css/accessible-autocomplete.min.css\" />\n```\n\nYou can also import it using Sass:\n\n```css\n@import \"accessible-autocomplete\";\n```\n\n### Using with Preact\n\nIf you already use Preact in your application, you can import a bundle that will use that:\n\n```js\nimport preact from 'preact'\nimport Autocomplete from 'accessible-autocomplete/preact'\n\npreact.render(\n <Autocomplete id='autocomplete' source={suggest} />,\n document.querySelector('#container')\n)\n```\n\n[Try out the Preact example!](https://alphagov.github.io/accessible-autocomplete/examples/preact/)\n\n### Using with React\n\nIf you already use React in your application, you can import a bundle that will use that:\n\n```js\nimport React from 'react'\nimport ReactDOM from 'react-dom'\nimport Autocomplete from 'accessible-autocomplete/react'\n\nReactDOM.render(\n <Autocomplete id='autocomplete' source={suggest} />,\n document.querySelector('#container')\n)\n```\n\n[Try out the React example!](https://alphagov.github.io/accessible-autocomplete/examples/react/)\n\n#### React versions\n\nReact v15.5.4 has been tested to work with the Accessible Autocomplete - although make sure to check\nout [documented issues](https://github.com/alphagov/accessible-autocomplete/issues).\n\nReact v15.6.2 and 16.0 have been incompletely tested with the Accessible Autocomplete: while no undocumented issues were found, we recommend you carry out thorough testing if you wish to use these or later versions of React.\n\n## API documentation\n\n### Required options\n\n#### `element`\n\nType: `HTMLElement`\n\nThe container element in which the autocomplete will be rendered in.\n\n#### `id`\n\nType: `string`\n\nThe `id` to assign to the autocomplete input field, to use with a `<label for=id>`. Not required if using `enhanceSelectElement`.\n\n#### `source`\n\nType: `Array | Function`\n\nAn array of values to search when the user types in the input field, or a function to take what the user types and call a callback function with the results to be displayed.\n\nAn example of an array of values:\n\n```js\nconst countries = [\n 'France',\n 'Germany',\n 'United Kingdom'\n]\n```\n\nIf `source` is a function, the arguments are: `query: string, populateResults: Function`\n\nSimilar to the [`source` argument for typeahead.js](https://github.com/corejavascript/typeahead.js/blob/47d46b40cb834d8285ac9328c4b436e5eccf7197/doc/jquery_typeahead.md#datasets), a backing data source for suggestions. `query` is what gets typed into the input field, which will callback to `populateResults` synchronously with the array of string results to display in the menu.\n\nAn example of a simple suggestion engine:\n\n```js\nfunction suggest (query, populateResults) {\n const results = [\n 'France',\n 'Germany',\n 'United Kingdom'\n ]\n const filteredResults = results.filter(result => result.indexOf(query) !== -1)\n populateResults(filteredResults)\n}\n```\n\n### Other options\n\n#### `autoselect` (default: `false`)\n\nType: `Boolean`\n\nSet to true to highlight the first option when the user types in something and receives results. Pressing enter will select it.\n\n#### `confirmOnBlur` (default: `true`)\n\nType: `Boolean`\n\nThe autocomplete will confirm the currently selected option when the user clicks outside of the component. Set to `false` to disable.\n\n#### `cssNamespace` (default: `'autocomplete'`)\n\nType: `string`\n\nUse this property to override the [BEM](http://getbem.com/) block name that the JavaScript component will use. You will need to rewrite the CSS class names to use your specified block name.\n\n#### `defaultValue` (default: `''`)\n\nType: `string`\n\nSpecify a string to prefill the autocomplete with.\n\n#### `displayMenu` (default: `'inline'`)\n\nType: `'inline' | 'overlay'`\n\nYou can set this property to specify the way the menu should appear, whether inline or as an overlay.\n\n#### `minLength` (default: `0`)\n\nType: `number`\n\nThe minimum number of characters that should be entered before the autocomplete will attempt to suggest options. When the query length is under this, the aria status region will also provide helpful text to the user informing them they should type in more.\n\n#### `name` (default: `'input-autocomplete'`)\n\nType: `string`\n\nThe `name` for the autocomplete input field, to use with a parent `<form>`.\n\n#### `onConfirm` (default: `() => {}`)\n\nType: `Function`\n\nArguments: `confirmed: Object`\n\nThis function will be called when the user confirms an option, with the option they've confirmed.\n\n#### `placeholder` (default: `''`) :warning: not recommended :warning:\n\nType: `string`\n\nThis option will populate the `placeholder` attribute on the input element.\n\nWe think [placeholders have usability issues](http://adamsilver.io/articles/placeholders-are-problematic/) and that there are [better alternatives to input placeholder text](https://govuk-elements.herokuapp.com/form-elements/#form-hint-text), so we do not recommend using this option.\n\n#### `required` (default: `false`)\n\nType: `Boolean`\n\nThe input field will be rendered with a `required` attribute, see [W3C `required` attribute definition](https://www.w3.org/TR/html5/forms.html#the-required-attribute).\n\n#### `showAllValues` (default: `false`)\n\nType: `Boolean`\n\nIf this is set to `true`, all values are shown when the user clicks the input. This is similar\nto a default dropdown, so the autocomplete is rendered with a dropdown arrow to convey\nthis behaviour.\n\n#### `showNoOptionsFound` (default: `true`)\n\nType: `Boolean`\n\nThe autocomplete will display a \"No results found\" template when there are no results. Set to `false` to disable.\n\n#### `templates` (default: `undefined`)\n\nType:\n\n```js\n{\n inputValue: Function,\n suggestion: Function\n}\n```\n\nThis object defines templates (functions) that are used for displaying parts of the autocomplete.\n\n`inputValue` is a function that receives one argument, the currently selected suggestion. It returns the string value to be inserted into the input.\n\n`suggestion` is a function that receives one argument, a suggestion to be displayed. It is used when rendering suggestions, and should return a string, which can contain HTML. :warning: **Caution:** because this function allows you to output arbitrary HTML, you should [make sure it's trusted](https://en.wikipedia.org/wiki/Cross-site_scripting), and accessible.\n\n#### `dropdownArrow` (default: A rectangle pointing down)\n\nType: `Function`\n\nA function that gets passed an object with the property `className` (`{ className: '' }`) and should return a string of HTML or a (P)React element. :warning: **Caution:** because this function allows you to output arbitrary HTML, you should [make sure it's trusted](https://en.wikipedia.org/wiki/Cross-site_scripting), and accessible.\n\n### Internationalization\n\n#### `tNoResults` (default: `() => 'No results found'`)\n\nType: `Function`\n\nA function that receives no arguments and should return the text used in the dropdown to indicate that there are no results.\n\n#### `tStatusQueryTooShort` (default: `` (minQueryLength) => `Type in ${minQueryLength} or more characters for results.` ``)\n\nType: `Function`\n\nA function that receives one argument that indicates the minimal amount of characters needed for the dropdown to trigger and should return the text used in the accessibility hint to indicate that the query is too short.\n\n#### `tStatusNoResults` (default: `() => 'No search results.'`)\n\nType: `Function`\n\nA function that receives no arguments and should return the text that is used in the accessibility hint to indicate that there are no results.\n\n#### `tStatusSelectedOption` (default: `` (selectedOption, length, index) => `${selectedOption} (${index + 1} of ${length}) is selected.` ``)\n\nType: `Function`\n\nA function that receives two arguments, the selectedOption and the amount of available options, and it should return the text used in the accessibility hint to indicate which option is selected.\n\n#### `tStatusResults`\n\nDefault:\n\n```js\n(length, contentSelectedOption) => {\n const words = {\n result: (length === 1) ? 'result' : 'results',\n is: (length === 1) ? 'is' : 'are'\n }\n\n return <span>{length} {words.result} {words.is} available. {contentSelectedOption}</span>\n}\n```\n\nType: `Function`\n\nA function that receives two arguments, the count of available options and the return value of `tStatusSelectedOption`, and should return the text used in the accessibility hint to indicate which options are available and which is selected.\n\n## Progressive enhancement\n\nIf your autocomplete is meant to select from a small list of options (a few hundred), we strongly suggest that you render a `<select>` menu on the server, and use progressive enhancement.\n\nIf you have the following HTML:\n\n```html\n<select id=\"location-picker\">\n <option value=\"fr\">France</option>\n <option value=\"de\">Germany</option>\n <option value=\"gb\">United Kingdom</option>\n</select>\n```\n\nYou can use the `accessibleAutocomplete.enhanceSelectElement` function to enhance it into an autocomplete:\n\n```js\naccessibleAutocomplete.enhanceSelectElement({\n selectElement: document.querySelector('#location-picker')\n})\n```\n\nThis will:\n\n- Place an autocomplete input field after the specified `<select>`\n- Default the autocomplete `autoselect` to `true`\n- Default the autocomplete `defaultValue` to the select's `option[selected]`\n- Default the autocomplete `id` to the `<select>`'s `id`\n- Default the autocomplete `name` attribute to `''` to prevent it being included in form submissions\n- Default the autocomplete `source` to use existing `<option>`s from the `<select>`\n- Hide the `<select>` using inline `display: none`\n- Set the `<select>`'s `id` to `${id}-select` to decouple from any `<label>`\n- Upon confirming a value in the autocomplete, update the original `<select>`\n\nThis function takes the same options as `accessibleAutocomplete`, with the only difference being that it uses `selectElement` instead of `element`, which needs to be an instance of `HTMLSelectElement`.\n\n> **Note**: The `accessibleAutocomplete.enhanceSelectElement` function is fairly light and wraps the public API for `accessibleAutocomplete`. If your use case doesn't fit the above defaults, try [reading the source](src/wrapper.js) and seeing if you can write your own.\n\n### Null options\n\nIf your `<select>` element has a \"null\" option - a default option with no value - then you can pass a `defaultValue` option to `enhanceSelectElement` which will replace the label of this option when it is selected.\n\nWith the following HTML:\n\n```html\n<select id=\"location-picker\">\n <option value=\"\">Select a country</option>\n <option value=\"fr\">France</option>\n <option value=\"de\">Germany</option>\n <option value=\"gb\">United Kingdom</option>\n</select>\n```\n\nThen passing a `defaultValue` option of `''` will then leave the autocomplete blank if the null option is selected.\n\n```js\naccessibleAutocomplete.enhanceSelectElement({\n defaultValue: '',\n selectElement: document.querySelector('#location-picker')\n})\n```\n\nAny null options will also be filtered out of the options used to populate the `source` of the autocomplete element. To preserve options with no value in the autcomplete then pass a `preserveNullOptions` flag of `true` to `enhanceSelectElement`.\n\n## Analytics and tracking\n\nThe following events get triggered on the input element during the life cycle of the autocomplete:\n\n- `onConfirm` - This function will be called when the user confirms an option, with the option they've chosen.\n\nExample usage:\n\n```js\naccessibleAutocomplete({\n // additional options\n onConfirm: (val) => {\n track(val)\n }\n})\n```\n\n## Why another autocomplete?\n\n`accessible-autocomplete` was built after studying many existing solutions and prototyping patches to fix user experience or accessibility issues. It draws heavy inspiration from the following (and a lot of others):\n\n- [ljwatson/design-patterns](http://ljwatson.github.io/design-patterns/autocomplete/index.html): great accessible experience\n- [corejavascript/corejs-typeahead](https://github.com/corejavascript/typeahead.js): flexible autocomplete/suggestion engine architecture\n- [JamieAppleseed/selectToAutocomplete](https://github.com/JamieAppleseed/selectToAutocomplete): ease of use\n\n## Developing locally\n\nCheck out the [CONTRIBUTING](CONTRIBUTING.md) guide for instructions.\n\nIf you want to help and want to get more familiar with the codebase, try starting with the [\"good for beginners\"](https://github.com/alphagov/accessible-autocomplete/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+for+beginners%22) issues.\n\n## License\n\n[MIT](LICENSE.txt).\n",
|
150
|
+
"readmeFilename": "README.md",
|
170
151
|
"repository": {
|
171
152
|
"type": "git",
|
172
153
|
"url": "git+https://github.com/alphagov/accessible-autocomplete.git"
|
@@ -4,14 +4,21 @@
|
|
4
4
|
|
5
5
|
.autocomplete__hint,
|
6
6
|
.autocomplete__input {
|
7
|
-
-webkit-
|
8
|
-
|
9
|
-
|
7
|
+
-webkit-font-smoothing: antialiased;
|
8
|
+
-moz-osx-font-smoothing: grayscale;
|
9
|
+
font-weight: 400;
|
10
|
+
font-size: 16px;
|
11
|
+
line-height: 1.25;
|
10
12
|
box-sizing: border-box;
|
11
|
-
-moz-box-sizing: border-box;
|
12
|
-
-webkit-box-sizing: border-box;
|
13
|
-
margin-bottom: 0; /* BUG: Safari 10 on macOS seems to add an implicit margin. */
|
14
13
|
width: 100%;
|
14
|
+
height: 40px;
|
15
|
+
padding: 5px;
|
16
|
+
border: 2px solid #0b0c0c;
|
17
|
+
border-radius: 0;
|
18
|
+
-webkit-appearance: none;
|
19
|
+
-moz-appearance: none;
|
20
|
+
appearance: none;
|
21
|
+
margin-bottom: 0;
|
15
22
|
}
|
16
23
|
|
17
24
|
.autocomplete__input {
|
@@ -28,7 +35,8 @@
|
|
28
35
|
padding: 4px;
|
29
36
|
}
|
30
37
|
|
31
|
-
.autocomplete__input--focused
|
38
|
+
.autocomplete__input--focused,
|
39
|
+
.autocomplete__input:focus {
|
32
40
|
outline-offset: 0;
|
33
41
|
outline: 3px solid #ffbf47;
|
34
42
|
}
|
@@ -139,3 +147,37 @@
|
|
139
147
|
line-height: 1.31579;
|
140
148
|
}
|
141
149
|
}
|
150
|
+
|
151
|
+
.autocomplete__list {
|
152
|
+
list-style-type: none;
|
153
|
+
padding: 0;
|
154
|
+
margin: 0;
|
155
|
+
}
|
156
|
+
|
157
|
+
.autocomplete__list .autocomplete__option,
|
158
|
+
.autocomplete__list .autocomplete__option:hover {
|
159
|
+
color: #0b0c0c;
|
160
|
+
padding: 3px 6px 6px;
|
161
|
+
margin-top: 10px !important;
|
162
|
+
border: 1px solid #bfc1c3;
|
163
|
+
background: #f8f8f8;
|
164
|
+
}
|
165
|
+
|
166
|
+
.autocomplete__list .autocomplete__option:focus {
|
167
|
+
outline-offset: 0;
|
168
|
+
outline: 3px solid #ffbf47;
|
169
|
+
}
|
170
|
+
|
171
|
+
.autocomplete__list .autocomplete__option:before {
|
172
|
+
display: inline-block;
|
173
|
+
content: '×';
|
174
|
+
padding: 2px 3px 0;
|
175
|
+
margin-right: 3px;
|
176
|
+
font-size: 24px;
|
177
|
+
color: inherit;
|
178
|
+
line-height: 1;
|
179
|
+
}
|
180
|
+
|
181
|
+
.autocomplete__list-item-description {
|
182
|
+
display: none;
|
183
|
+
}
|
@@ -45,6 +45,7 @@ export default class Autocomplete extends Component {
|
|
45
45
|
static defaultProps = {
|
46
46
|
autoselect: false,
|
47
47
|
cssNamespace: 'autocomplete',
|
48
|
+
customAttributes: {},
|
48
49
|
defaultValue: '',
|
49
50
|
displayMenu: 'inline',
|
50
51
|
minLength: 0,
|
@@ -55,7 +56,10 @@ export default class Autocomplete extends Component {
|
|
55
56
|
showNoOptionsFound: true,
|
56
57
|
showAllValues: false,
|
57
58
|
required: false,
|
59
|
+
multiple: false,
|
60
|
+
selectedOptions: {},
|
58
61
|
tNoResults: () => 'No results found',
|
62
|
+
tSelectedOptionDescription: () => 'press Enter or Space to remove selection',
|
59
63
|
dropdownArrow: DropdownArrowDown
|
60
64
|
}
|
61
65
|
|
@@ -70,6 +74,7 @@ export default class Autocomplete extends Component {
|
|
70
74
|
clicked: null,
|
71
75
|
menuOpen: false,
|
72
76
|
options: props.defaultValue ? [props.defaultValue] : [],
|
77
|
+
selectedOptions: props.selectedOptions ? [props.selectedOptions] : [],
|
73
78
|
query: props.defaultValue,
|
74
79
|
selected: null
|
75
80
|
}
|
@@ -88,6 +93,9 @@ export default class Autocomplete extends Component {
|
|
88
93
|
this.handleOptionFocus = this.handleOptionFocus.bind(this)
|
89
94
|
this.handleOptionMouseEnter = this.handleOptionMouseEnter.bind(this)
|
90
95
|
|
96
|
+
this.handleSelectedOptionClick = this.handleSelectedOptionClick.bind(this)
|
97
|
+
this.handleSelectedOptionKeyDown = this.handleSelectedOptionKeyDown.bind(this)
|
98
|
+
|
91
99
|
this.handleInputBlur = this.handleInputBlur.bind(this)
|
92
100
|
this.handleInputChange = this.handleInputChange.bind(this)
|
93
101
|
this.handleInputFocus = this.handleInputFocus.bind(this)
|
@@ -174,6 +182,15 @@ export default class Autocomplete extends Component {
|
|
174
182
|
query: newQuery,
|
175
183
|
selected: null
|
176
184
|
})
|
185
|
+
|
186
|
+
if (this.props.selectElement && this.props.selectElement.multiple) {
|
187
|
+
// Reset input state
|
188
|
+
this.setState({
|
189
|
+
menuOpen: false,
|
190
|
+
selected: null,
|
191
|
+
query: ''
|
192
|
+
})
|
193
|
+
}
|
177
194
|
}
|
178
195
|
|
179
196
|
handleListMouseLeave (event) {
|
@@ -280,9 +297,54 @@ export default class Autocomplete extends Component {
|
|
280
297
|
query: newQuery,
|
281
298
|
selected: -1
|
282
299
|
})
|
300
|
+
if (this.props.selectElement && this.props.selectElement.multiple) {
|
301
|
+
this.updateMultiselect(selectedOption)
|
302
|
+
}
|
303
|
+
this.forceUpdate()
|
304
|
+
}
|
305
|
+
|
306
|
+
updateMultiselect (selectedOption) {
|
307
|
+
if (selectedOption) {
|
308
|
+
// Update select state for option
|
309
|
+
const addedSelectOption = [].filter.call(this.props.selectElement.options, option => option.textContent === selectedOption)[0]
|
310
|
+
if (addedSelectOption) { addedSelectOption.selected = true }
|
311
|
+
|
312
|
+
// Update multiselect list
|
313
|
+
let availableOptions = [].filter.call(this.props.selectElement.options, option => option.textContent)
|
314
|
+
this.props.selectedOptions = availableOptions.filter(option => option.selected === true)
|
315
|
+
|
316
|
+
// Reset input state
|
317
|
+
this.setState({
|
318
|
+
menuOpen: false,
|
319
|
+
selected: null,
|
320
|
+
query: ''
|
321
|
+
})
|
322
|
+
}
|
323
|
+
}
|
324
|
+
|
325
|
+
handleSelectedOptionClick (event, index) {
|
326
|
+
// Remove from the list
|
327
|
+
const removedOption = this.props.selectedOptions[index]
|
328
|
+
this.props.selectedOptions = this.props.selectedOptions.filter(e => e !== removedOption)
|
329
|
+
|
330
|
+
// Update select state for option
|
331
|
+
const removedSelectOption = [].filter.call(this.props.selectElement.options, option => option.textContent === removedOption.textContent)[0]
|
332
|
+
if (removedSelectOption) { removedSelectOption.selected = false }
|
333
|
+
|
283
334
|
this.forceUpdate()
|
284
335
|
}
|
285
336
|
|
337
|
+
handleSelectedOptionKeyDown (event, index) {
|
338
|
+
switch (keyCodes[event.keyCode]) {
|
339
|
+
case 'space':
|
340
|
+
this.handleSelectedOptionClick(event, index)
|
341
|
+
break
|
342
|
+
case 'enter':
|
343
|
+
this.handleSelectedOptionClick(event, index)
|
344
|
+
break
|
345
|
+
}
|
346
|
+
}
|
347
|
+
|
286
348
|
handleUpArrow (event) {
|
287
349
|
event.preventDefault()
|
288
350
|
const { menuOpen, selected } = this.state
|
@@ -392,13 +454,16 @@ export default class Autocomplete extends Component {
|
|
392
454
|
name,
|
393
455
|
placeholder,
|
394
456
|
required,
|
457
|
+
multiple,
|
395
458
|
showAllValues,
|
396
459
|
tNoResults,
|
397
460
|
tStatusQueryTooShort,
|
398
461
|
tStatusNoResults,
|
399
462
|
tStatusSelectedOption,
|
400
463
|
tStatusResults,
|
401
|
-
|
464
|
+
tSelectedOptionDescription,
|
465
|
+
dropdownArrow: dropdownArrowFactory,
|
466
|
+
customAttributes
|
402
467
|
} = this.props
|
403
468
|
const { focused, hovered, menuOpen, options, query, selected } = this.state
|
404
469
|
const autoselect = this.hasAutoselect()
|
@@ -426,6 +491,8 @@ export default class Autocomplete extends Component {
|
|
426
491
|
|
427
492
|
const optionClassName = `${cssNamespace}__option`
|
428
493
|
|
494
|
+
const selectedOptionsClassName = `${cssNamespace}__list`
|
495
|
+
|
429
496
|
const hintClassName = `${cssNamespace}__hint`
|
430
497
|
const selectedOptionText = this.templateInputValue(options[selected])
|
431
498
|
const optionBeginsWithQuery = selectedOptionText &&
|
@@ -482,6 +549,7 @@ export default class Autocomplete extends Component {
|
|
482
549
|
role='textbox'
|
483
550
|
required={required}
|
484
551
|
value={query}
|
552
|
+
{...customAttributes}
|
485
553
|
/>
|
486
554
|
|
487
555
|
{dropdownArrow}
|
@@ -518,6 +586,38 @@ export default class Autocomplete extends Component {
|
|
518
586
|
<li className={`${optionClassName} ${optionClassName}--no-results`}>{tNoResults()}</li>
|
519
587
|
)}
|
520
588
|
</ul>
|
589
|
+
|
590
|
+
{multiple && (
|
591
|
+
<ul
|
592
|
+
className={`${selectedOptionsClassName}`}
|
593
|
+
id={`${id}__list`}
|
594
|
+
role='listbox'
|
595
|
+
>
|
596
|
+
{this.props.selectedOptions.map((option, index) => {
|
597
|
+
return (
|
598
|
+
<li
|
599
|
+
aria-selected='true'
|
600
|
+
aria-label={`${this.templateSuggestion(option.textContent)}, selected`}
|
601
|
+
aria-describedBy={`${id}__list-item-description`}
|
602
|
+
className={`${optionClassName}`}
|
603
|
+
dangerouslySetInnerHTML={{ __html: this.templateSuggestion(option.textContent) }}
|
604
|
+
id={`${id}__option--${index}`}
|
605
|
+
key={index}
|
606
|
+
onClick={(event) => this.handleSelectedOptionClick(event, index)}
|
607
|
+
onKeyDown={(event) => this.handleSelectedOptionKeyDown(event, index)}
|
608
|
+
role='option'
|
609
|
+
tabIndex='0'
|
610
|
+
/>
|
611
|
+
)
|
612
|
+
})}
|
613
|
+
{showNoOptionsFound && (
|
614
|
+
<li className={`${optionClassName} ${optionClassName}--no-results`}>{tNoResults()}</li>
|
615
|
+
)}
|
616
|
+
</ul>
|
617
|
+
)}
|
618
|
+
{multiple && (
|
619
|
+
<span class='autocomplete__list-item-description' id={`${id}__list-item-description`}>{tSelectedOptionDescription()}</span>
|
620
|
+
)}
|
521
621
|
</div>
|
522
622
|
)
|
523
623
|
}
|
@@ -23,6 +23,14 @@ accessibleAutocomplete.enhanceSelectElement = (configurationOptions) => {
|
|
23
23
|
if (!configurationOptions.source) {
|
24
24
|
let availableOptions = [].filter.call(configurationOptions.selectElement.options, option => (option.value || configurationOptions.preserveNullOptions))
|
25
25
|
configurationOptions.source = availableOptions.map(option => option.textContent || option.innerText)
|
26
|
+
|
27
|
+
// Store selected options
|
28
|
+
if (configurationOptions.selectElement.multiple) {
|
29
|
+
configurationOptions.multiple = true
|
30
|
+
configurationOptions.confirmOnBlur = false
|
31
|
+
configurationOptions.showNoOptionsFound = false
|
32
|
+
configurationOptions.selectedOptions = availableOptions.filter(option => option.selected)
|
33
|
+
}
|
26
34
|
}
|
27
35
|
configurationOptions.onConfirm = configurationOptions.onConfirm || (query => {
|
28
36
|
const requestedOption = [].filter.call(configurationOptions.selectElement.options, option => (option.textContent || option.innerText) === query)[0]
|
@@ -31,7 +39,11 @@ accessibleAutocomplete.enhanceSelectElement = (configurationOptions) => {
|
|
31
39
|
|
32
40
|
if (configurationOptions.selectElement.value || configurationOptions.defaultValue === undefined) {
|
33
41
|
const option = configurationOptions.selectElement.options[configurationOptions.selectElement.options.selectedIndex]
|
34
|
-
configurationOptions.
|
42
|
+
if (configurationOptions.selectElement.multiple) {
|
43
|
+
configurationOptions.defaultValue = ''
|
44
|
+
} else if (option.textContent || option.innerText) {
|
45
|
+
configurationOptions.defaultValue = option.textContent || option.innerText
|
46
|
+
}
|
35
47
|
}
|
36
48
|
|
37
49
|
if (configurationOptions.name === undefined) configurationOptions.name = ''
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_publishing_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 15.
|
4
|
+
version: 15.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: govspeak
|
@@ -638,8 +638,10 @@ files:
|
|
638
638
|
- node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.react.min.js.map
|
639
639
|
- node_modules/accessible-autocomplete/examples/form.html
|
640
640
|
- node_modules/accessible-autocomplete/examples/index.html
|
641
|
+
- node_modules/accessible-autocomplete/examples/multiselect.html
|
641
642
|
- node_modules/accessible-autocomplete/examples/preact/index.html
|
642
643
|
- node_modules/accessible-autocomplete/examples/react/index.html
|
644
|
+
- node_modules/accessible-autocomplete/package-lock.json
|
643
645
|
- node_modules/accessible-autocomplete/package.json
|
644
646
|
- node_modules/accessible-autocomplete/preact.js
|
645
647
|
- node_modules/accessible-autocomplete/react.js
|