GithubHelp home page GithubHelp logo

alphagov / govuk-country-and-territory-autocomplete Goto Github PK

View Code? Open in Web Editor NEW
36.0 22.0 19.0 3.74 MB

An autocomplete widget that uses data from Country and Territory Register.

Home Page: https://alphagov.github.io/govuk-country-and-territory-autocomplete/examples/

License: MIT License

JavaScript 100.00%
portfolio govuk-design-system-team

govuk-country-and-territory-autocomplete's Introduction

GOV.UK country and territory autocomplete - what it is and how to use it

The country and territory autocomplete is a component that helps users choose countries and territories in answers. You should only use this component for services where users have to provide their country or territory.

This component includes complete functionality to make it faster and easier for users to find a location. For example, to select their country of birth or their current location.

For other types of question, you should use the accessible autocomplete. To find information about this component, go to the accessible-autocomplete README.

The autocomplete uses data from the UK government's country and territory registers. To configure the data used in the autocomplete to suit the specific needs of your product or service, please raise an issue.

The autocomplete itself follows the common look and feel of GOV.UK in line with the design principles, and should work with recommended browsers and assistive technologies.

A screenshot of the new country and territory autocomplete

This guide will show you how to:

  • populate the autocomplete field
  • use the autocomplete's data file

Try out the example.


Support

The GOV.UK Design System team maintains the country and territory autocomplete. However, we’re only able to put in minimal work to support it.

Read about our plans to maintain this component.

Read more about the types of support we can provide.


Integration process

To integrate an application with the autocomplete, you'll need to:

  • use the data from the country and territory registers
  • create an accessible autocomplete widget
  • keep the data up to date

Add location data from country and territory registers

To use register data in the autocomplete, you will need two files:

The location-autocomplete-graph.json file only contains examples of synonyms, abbreviations, endonyms and typos you might want to consider. It is not a comprehensive list. You may wish to add or remove items based on your own user research.

Copy both files to your application. The location-autocomplete-graph.json file must be exposed as a public asset.

You can also install the location autocomplete using npm:

$ npm install govuk-country-and-territory-autocomplete
$ ls node_modules/govuk-country-and-territory-autocomplete/dist/
location-autocomplete-canonical-list.json
location-autocomplete-graph.json
location-autocomplete.min.css
location-autocomplete.min.js
location-autocomplete.min.js.map

The location-autocomplete-canonical-list.json file contains an array of arrays containing the location names and ISO codes:

> JSON.parse(fs.readFileSync('data/location-autocomplete-canonical-list.json', 'utf8'))
[["Abu Dhabi", "territory:AE-AZ"], ["Afghanistan", "country:AF"], ]

You should parse this file on your application's server or as part of the build process to produce a plain HTML <select> dropdown. This is your progressive enhancement fallback. You should render something that looks like this:

<select id="location-autocomplete">
  <option value="territory:AE-AZ">Abu Dhabi</option>
  <option value="country:AF">Afghanistan</option></select>

Create an accessible autocomplete widget

To make it easier for users to find a location using the autocomplete, you should progressively enhance the front-end to add auto-complete functionality. As a user types, the autocomplete will suggest a list of possible locations for the user to choose from.

On the page where you're rendering the previous <select> dropdown, include the following HTML, updating the /assets/ URLs as needed for your application:

<!-- In your <head> -->
<link rel="stylesheet" href="/assets/location-autocomplete.min.css" />

<!-- At the end of your <body> -->
<script type="text/javascript" src="/assets/location-autocomplete.min.js"></script>
<script type="text/javascript">
  openregisterLocationPicker({
    selectElement: document.getElementById('location-autocomplete'),
    url: '/assets/location-autocomplete-graph.json'
  })
</script>

This will render the same <select> menu as before on the server, but hides it and progressively enhances to a autocomplete when JavaScript kicks in. When the user selects something in the autocomplete, the hidden <select> menu is still updated, so everything works as before.

If you prefer to learn by reading the source, try out the example.

Adding additional entries and synonyms

You can pass in custom entries and synonyms using the additionalEntries and additionalSynonyms option:

<script type="text/javascript">
  openregisterLocationPicker({
    additionalEntries: [
      { name: 'Atlantis', code: 'country:AN' }
    ],
    additionalSynonyms: [
      { name: 'Albion', code: 'country:GB' }
    ],
    selectElement: document.getElementById('location-autocomplete'),
    url: '/assets/location-autocomplete-graph.json'
  })
</script>

You can additionally specify custom synonyms on the <option> elements by using the data-additional-synonyms attribute:

<select id="location-autocomplete">
  <option value="territory:GB" data-additional-synonyms='["Blighty"]'>United Kingdom</option>
  <option value="country:RO" data-additional-synonyms='["Dacia"]'>Romania</option>
</select>

Keep the data up to date

Government Digital Service will publish new versions of the govuk-country-and-territory-autocomplete package when the data changes, such as when countries are renamed.

To keep up to date, you can use dependency monitoring tools, such as:

  • Greenkeeper, a GitHub bot that will submit pull requests to your open source project when there are new versions of your dependencies
  • David, a command line tool that can be configured to run on your continuous integration environment and return a non-zero status when there are new versions of your dependencies

Glossary

country register - A list of British English-language names and descriptive terms for countries.

location - A country or territory.

autocomplete - A widget that allows you to choose from items in a register.

register - A list of information designed to be an accurate and up-to-date source of data from government. Once entered into a register, the contents can only be added to, they cannot be deleted or rewritten.

territory - An administrative or geographical entity that isn't recognised as a country by the UK.

territory register - A list of British English-language names and descriptive terms for political, administrative and geographical entities that aren’t recognised as countries by the UK.

Releasing

  • Update CHANGELOG
  • Update package.json
  • npm version
  • Merge to main
  • Create GitHub release tag
  • npm publish

govuk-country-and-territory-autocomplete's People

Contributors

36degrees avatar colinrotherham avatar dependabot[bot] avatar domoscargin avatar eoinshaughnessy avatar gidsg avatar greenkeeper[bot] avatar injms avatar j-lambo avatar jonheslop avatar lfdebrux avatar matmoore avatar nickcolley avatar tvararu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

govuk-country-and-territory-autocomplete's Issues

Support for locales other than en-gb

Hi, does this package support languages other than English? (we have a requirement to make our service available in Welsh as well as English). At first glance it looks like the openregister-picker-engine dependency has some code to deal with other locales (although it's not clear if it's complete or tested) but hardcodes the locale to en-gb so I'm guessing we're stuck with English if using this package.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Should this repo be renamed?

Should this repo be called openregister-location-picker?

Possible suggestions:
govuk-country-and-territory-autocomplete
govuk-country-and-territory-picker
govuk-country-territory-autocomplete
govuk-country-territory-picker

Thoughts?

Feature: show historic names when countries change name

We've seen at least two cases in user research of users being confused by the country Czechia when searching for The Czech Republic. The country name changed in April 2016, but this is probably not well known.

This is what the picker currently looks like when you search for Czech:
screen shot 2017-04-25 at 13 09 33

From the user's point of view, neither is correct. The first they've never heard of, and the second doesn't exist any more (but people may still think it more relevant). The second probably shouldn't show unless services explicitly want historic countries.

If the user types the full name they know, it works better:
screen shot 2017-04-25 at 13 11 54
This is better, but unless they type enough characters, they don't get the name they're familiar with.

Possible solution

When a country name changes, for a period of time after that (3-5 years?), show the historic name as well:
screen shot 2017-04-25 at 12 56 14
This feels like quite a nice use of registers - the correct current name is used, but users are 'eased' in to the new name.

input element's margin removed

If the location picker is applied on an input element with a margin then that margin disappears (before any interaction)

Types of support we can provide.

govuk-country-and-territory-autocomplete is maintained by the GOV.UK Design System team as a standalone component. We’re only able to put in minimal work to support it.

We provide support for:

  • accessibility issues that block usage
  • security issues
  • broken functionality that blocks usage for most users
  • dependency updates to keep tests working so we can make changes safely
  • documentation updates

We cannot currently provide support for:

  • adding new features
  • smaller functionality issues that do not block usage
  • issues caused by users customising the country and territory autocomplete
  • issues with browsers and assistive technologies not mentioned in the GOV.UK Service Manual
  • complex issues with React

Make it work on IE11 out of the box

While progressive enhancement should give users something to use, it would be great if we could include instructions on how to add the required polyfills for IE11, as a lot of AT users rely on that browser.

Rename default branch to `main`

What

Rename the default branch from master to main.

Why

Many communities on GitHub are considering renaming the default branch name of their repository from master, as this terminology can be offensive. Statements and guidance have been published by Git here and GitHub here.

New GitHub repositories use main as the name for the default branch, so it makes sense that we should follow this convention, as well as matching what other teams within GDS are doing so we are consistent.

Additional Info

GitHub have made it easier for teams to rename branches. When we rename the branch, we get the following for "free" without having to do anything ourselves:

  • Open PRs and branch protection rules changed automatically
  • Web requests for the old branch name are redirected to the new branch name
  • API requests for the old branch name return a Moved Permanently response
  • A notice is shown on the repository homepage to notify contributors, maintainers and admins to update their local copies of the repo
  • A notice is shown to contributors who git push to the old branch

Who needs to know about this

Developers

Steps to follow

  • Raise PR to switch functionality that relies on master and to update any documentation
  • Once the PR has been approved (not merged!), rename the master branch to main in the Github UI
  • Double check branch protection rules
  • Double check webhooks
  • Double check any deploy systems, e.g: GitHub pages, that may have it's own config
  • If the repo uses Travis: Travis has its own idea of what the 'default branch' is which is synced once a day. You can manually trigger a sync by going to https://travis-ci.com/account/repositories and pressing 'sync account'.
  • Merge the PR
  • Check everything is still working as expected, e.g: build and deploy. If so, double check there is a main branch present and no old master branch present.

Done when

  • The default branch is named main
  • Documentation has been updated to refer to main rather than master
  • Check GitHub pages settings to ensure it's deploying from main branch
  • Check local setups still work

Côte d'Ivoire not recognized with circumflex

Raised by @Smylers in this issue.

Ivory Coast is also known by its French name of Côte d'Ivoire, but your picker doesn't recognize it, not matching anything after ‘Cô’:
Screen shot showing ‘no results found’ after typing ‘Cô’
It does work if you Asciify it as ‘Cote’ rather than ‘Côte’, but if somebody's going to use the French name they may expect it to have the French accent on it.

You could either add ‘Côte d'Ivoire’, and its longer form ‘The Republic of Côte d'Ivoire’, as additional endonyms. Or fix this more generally by ignoring all diacritics when matching.

Make clear how this repo relates to accessible autocomplete

I don't think it's clear how this repo relates to accessible autocomplete. Both should be clear.

I've come across two cases of GDS teams using the accessible autocomplete when they probably wanted to be using this repo. Can we make the differences and the link between them clearer?

Locations with hyphens can't be chosen

The following countries/territories can't be selected if you type the hyphen:

Guinea-Bissau
Ras al-Khaimah
Saint-Martin (French part)
Umm al-Quwain

Before you type the hyphen, you can choose an item:

no-hyphen

As soon as you type the hyphen, the results vanish:

hyphen

Probably also related to #40 @NickColley

Use GreenKeeper

This would allow us to keep dependencies up to date more easily.

Edge-case select is not updated

In standard GDS pages, with a single question per page, If the user types in the whole of the entry, and does not select from the list, and then submits without blurring from the input, the select is not updated, so the value is not submitted. (This may also be an issue with accessible-autocomplete )

Allow supplying of a cut-off date for historic countries

Often this will be used for supplying current or recent domicile data. As such historic countries will either not be wanted or else only a sub-set will be required. For example when address is required for a particular year, all historic countries which ceased to exist before that date would not be wanted in the results.

The ability to specify the cut-off date would mean users are not presented with potentially confusing options and services would not have to handle those erroneous results.

Make clear whether this repo is ready for production use.

Is this repo ready for production use? If not, we should be explicit about it.

The accessible autocomplete has not had a follow up accessibility audit - a step I feel should happen. I'm also not sure we have a good process for continually supporting it. Until those things are in place, should it be used in production?

firefox 45 support

Hi @tvararu - could you please update the accessible-autocomplete version to 1.2.1 and publish a new version?

v1.2.1 has changes to make progressive enhancement work in firefox 45.

Thanks

Process for importing data is broken

When following the instructions in CONTRIBUTING.md to update the data, I noticed that the generated graph doesn't include all the names in the existing JSON (possibly all the synonyms have been removed). Meaning that we can't just update the data by running this script.

Turns out there used to be another thing, https://github.com/openregister-attic/kibitz which originally generated these files. This also includes additional synonyms that are not part of the registers themselves. This was then replaced by https://github.com/openregister/generate-picker-data-file (the lambda function we're calling here). This has outstanding issues that need to be addressed, for example https://github.com/openregister/generate-picker-data-file/issues/11

In the short term, I can work around this, but I'm raising this issue just to acknowledge that the instructions are misleading and we (the register team) need to fix it.

Incorrect information in the README

in the README it says that npm install will put the required files in node_modules/openregister-location-autocomplete/dist/, in reality, the files end up in node_modulesgovuk-country-and-territory-autocomplete/dist/.

Record limitations of the current countries and territories dataset

What

Document the limitations of the current countries and territories dataset and make it clear that users may need to curate the list to their specific use case, for example: if a service is asking for place of birth, they may need historic countries and territories.

Semi-related to #14

Feature: show when a country is historic

We've seen in user research that users can be confused when historic countries appear in the picker. This causes concern that our data is out of date - as users don't immediately realise why the historic country is showing.

Hopefully the picker will be configurable so it doesn't display historic countries when not needed - but when they are needed, we could communicate their status better.

Idea

We could append extra text to historic countries:
screen shot 2017-04-25 at 14 41 09
screen shot 2017-04-25 at 13 28 54

Deleting country from input field does not reset select value

To reproduce:
On a form with the country picker,
type "fr" into country picker,
select "france",
delete "france" from the input field,
submit the form

Actual outcome
The country value will be "france"

Expected outcome:
The country value should be ""

Commas break matching

When a country name has commas in it then it is not possible to enter that country name into the text input and find a match, however omitting commas will find the match - this will not be clear to users who may just paste in, or quickly type a country name and find no matches, for example "Pitcairn, Henderson, Ducie and Oeno Islands" will not be found if entered but "Pitcairn Henderson Ducie and Oeno Islands" will.

Our plans to maintain this component

Later in 2022, we’ll carry out research to understand how we can support services that use this component.

We’ll work with other teams in GDS to find the best way to keep the component up-to-date with the latest technologies and for accessibility.

We hope to find out more about:

  • services that use the current autocomplete
  • their different use cases
  • customisations or ‘hacks’ that teams have made
  • datasets in use
  • accessibility work service teams have done, and what needs they’ve discovered

If you’d like to help or share your experiences, leave a comment in the Accessible autocomplete repo or contact the team.

Synonyms are not always shown in the results list

In the example below you can see that when typing 'un', 'Burma' is returned as a result, but with no alias given, which makes it hard to understand why it's in the list (same goes for 'Egypt').

image

If you look in the data you’ll see:

  1. A country code, MM, which is named ‘Burma’
  2. A synonym for MM, which is named ‘Union of Burma’

So it appears to be matching the ‘Un’ of ‘Union of Burma’, but not outputting the synonym in the list. This may be a design choice rather than a bug, but in this example it's producing a confusing result.

East Germany

Is it on purpose the data contains and displays former East Germany, while other countries are updated and renamed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.