Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Accessible Autocomplete a GOV.UK Prototype Kit plugin #598

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [Pull request #621: Handle query change when the text length does not change](https://github.com/alphagov/accessible-autocomplete/pull/621)
- [Pull request #620: Add `className` attribute to status component](https://github.com/alphagov/accessible-autocomplete/pull/620)
- [Pull request #591: Add menuAttributes to fix #361](https://github.com/alphagov/accessible-autocomplete/pull/591)
- [Pull request #598: Make Accessible Autocomplete a GOV.UK Prototype Kit plugin](https://github.com/alphagov/accessible-autocomplete/pull/598)

## 2.0.4 - 2022-02-07

Expand Down
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,47 @@ 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
```

To add the accessible autocomplete to a page in your prototype, first add a `select` component with your options. For example:

```html
<div class="govuk-form-group">
<label class="govuk-label" for="country">
Country
</label>
<select class="govuk-select" id="country" name="country">
<option value="England">England</option>
<option value="Northern Ireland">Northern Ireland</option>
<option value="Scotland">Scotland</option>
<option value="Wales">Wales</option>
</select>
</div>
```

Copy link
Contributor Author

@joelanman joelanman Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think relying on the class is a bit fragile, but if thats the approach I would suggest calling it out, something like:

Note that the class govuk-form-group is required to make the autocomplete look like GOV.UK.

Because if they use examples from elsewhere, it won't have it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the end of the same page add a `pageScripts` block for the JavaScript. This turns the `select` into an autocomplete.

```js
<% block pageScripts %>

<script>

accessibleAutocomplete.enhanceSelectElement({
selectElement: document.querySelector('#country')
})

</script>

<% endblock %>

```

### Styling the autocomplete

A stylesheet is included with the package at [dist/accessible-autocomplete.min.css](dist/accessible-autocomplete.min.css).
Expand Down
2 changes: 1 addition & 1 deletion dist/accessible-autocomplete.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/accessible-autocomplete.min.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions govuk-prototype-kit.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"meta": {
"description": "A component that helps users choose the right answer from a list as they type. It also helps you get more accurate and consistent answers from users.",
"urls": {
"releaseNotes": "https://github.com/alphagov/accessible-autocomplete/releases/tag/v{{version}}",
"documentation": "https://github.com/alphagov/accessible-autocomplete#readme",
"versionHistory": "https://github.com/alphagov/accessible-autocomplete/releases"
}
},
"assets": [
"/dist",
"/dist/accessible-autocomplete.min.js.map"
],
"scripts": [
"/dist/accessible-autocomplete.min.js"
],
"stylesheets": [
"/dist/accessible-autocomplete.min.css"
]
}
9 changes: 9 additions & 0 deletions src/autocomplete.css
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@
font-weight: 400;
}

/* Try font "GDS Transport" for GOV.UK form groups */
.govuk-form-group .autocomplete__hint,
.govuk-form-group .autocomplete__input,
.govuk-form-group .autocomplete__option {
font-family: "GDS Transport", arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
Comment on lines +155 to +162
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add to what @romaricpascal was saying:

This could instead be part of a separate autocomplete-govuk.css (or better named) stylesheet that is referenced in govuk-prototype-kit.config.json.

That way autocomplete users can choose from:

  • GOVUK styling autocomplete-govuk.css
  • Default styling autocomplete.css
  • No styling (DIY)

Also wanted to mention: the historic reason for why the autocomplete doesn't use GOVUK Frontend classes is because it precedes v0.1 of GOVUK Frontend. It's also a nice feature which has allowed it to be adopted in places outside Gov such as FT or Wordpress. So yes, keeping the "Default styling" agnostic is still worth doing. 👍

Copy link
Contributor Author

@joelanman joelanman Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this might work:

.govuk-template .autocomplete__hint,
...
  • simpler to have one css file, people working on govuk things don't have to think about config
  • one request is better for performance
  • .govuk-template is always present in the Prototype Kit (and many other GOV.UK projects), whereas there may not be a parent .govuk-form-group


.autocomplete__hint,
.autocomplete__option {
padding: 5px;
Expand Down