Skip to content

Commit

Permalink
add prototype kit instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
joelanman committed Aug 27, 2023
1 parent e95884b commit f21c097
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,50 @@ You can copy the [dist/accessible-autocomplete.min.js](dist/accessible-autocompl
<script type="text/javascript" src="assets/js/accessible-autocomplete.min.js"></script>
```

### As a GOV.UK Prototype Kit plugin

In your prototype folder, run:

```bash
npm install accessible-autocomplete
```

This will load the accessible autocomplete CSS and JavaScript for you.

Then on the page you want to add the accessible autocomplete:

```html
<label for="my-autocomplete">Select your country</label>
<div id="my-autocomplete-container"></div>
```

At the end of the file add a `pageScripts` block for the JavaScript:

```js
<% block pageScripts %>

<script>

const countries = [
'France',
'Germany',
'United Kingdom'
]

accessibleAutocomplete({
element: document.querySelector('#my-autocomplete-container'),
id: 'my-autocomplete', // To match it to the existing <label>.
source: countries
})

</script>

<% endblock %>

```

If you want to use it as a replacement for a `<select>` element, read the [Progressive enhancement](#progressive-enhancement) section.

### Styling the autocomplete

A stylesheet is included with the package at [dist/accessible-autocomplete.min.css](dist/accessible-autocomplete.min.css).
Expand Down

0 comments on commit f21c097

Please sign in to comment.