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

Retire the 'select with search' component in favour of 'autocomplete' #9970

Closed
wants to merge 6 commits into from

Conversation

ChrisBAshton
Copy link
Contributor

@ChrisBAshton ChrisBAshton commented Feb 21, 2025

This PR is superseded by #9959.


This is a POC PR that removes the 'select_with_search' component and migrates all existing usage to either:

  1. the 'select' component (if the list of options was small and search functionality not essential), converting the 'grouped options' to a flat list with prefixes
  2. the 'autocomplete' (if the list of options was big and search functionality still needed), since 'grouped options' aren't very useful in a very long list anyway

Before merging, we would need to fix the issue whereby autocomplete auto-selects the first option (when 'multiple' isn't set) and you have to clear it to even see what the other options are:

Screenshot 2025-02-21 at 15 41 07

Trello: https://trello.com/c/pmbL2yId/3411-consolidate-the-autocomplete-selectwithsearch-components-in-whitehall


⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

Follow these steps if you are doing a Rails upgrade.

It made no sense for this to be a "Grouped option" select (which
is only officially supported by the 'select with search'
component), as at time of writing there are over 1200 orgs in
total. No publisher is going to benefit from scrolling all the
way down the long list of orgs to see which ones sit under
"Live organisations" vs which ones sit under "Closed
organisations". They're simply going to search for the relevant
org - something that is fully supported by the 'autocomplete'
component provided we go with `options` rather than
`grouped_options`.

It looks like the decision to put these into grouped options
was made 11 years ago, primarily to avoid having two separate
dropdown inputs. It's not clear whether one simple input without
group options was ever considered:
8b02269
This dropdown has just 20 options, so doesn't particularly need
search functionality. It does have a nice grouping of publication
types as to whether they're commonly used, less commonly used, or
'use discouraged'.

I tried simply swapping 'select with search' out for 'select', but
the govuk_publishing_components [select component](https://components.publishing.service.gov.uk/component-guide/select)
doesn't support grouped options. Ideally we would port the
existing 'select with search' grouped options styles over to the
'select' component and then release a new version of
'govuk_publishing_components', but there's little evidence it
would be used outside of just two cases in Whitehall, so it may
be a difficult case to make, and in the meantime, we want to
retire the 'select with search' component.

I've therefore swapped this over to use the 'autocomplete'
component instead. We lose the nice 'grouping' of options, but
I've added a prefix to the 'less common' and 'use discouraged'
publication types to keep some degree of visual separation.
NB: I've reworded the latter to 'deprecated' as it works better
as a prefix, and because if the use of these types is discouraged
then they are by definition not well supported.
Rife with problems I'm afraid:

On page load it looks ok:
![on page load](https://github.com/user-attachments/assets/af5415e4-b2d9-45d9-8946-21d113daa331)

But on focus, it looks as though there are no options available:
![on focus](https://github.com/user-attachments/assets/7ee7ac5e-a60f-4edb-9e0c-b40376566715)

You then have to delete the pre-selected option to see what's available:
![on delete](https://github.com/user-attachments/assets/87d70137-f76a-4a7e-9c2a-dd7876a31cb2)

NB, here's what the 'subtypes' look like now we don't have grouped options:
![subtypes](https://github.com/user-attachments/assets/410efe0a-f09a-45ba-b8b9-e9259eb70507)
These didn't have 'grouped_options' so were simple enough to port
across.
@ChrisBAshton ChrisBAshton force-pushed the remove-select_with_search branch from 06d5e76 to 3d5452a Compare February 24, 2025 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant