Skip to content

Commit

Permalink
use accessible autocomplete instead of select_with_search
Browse files Browse the repository at this point in the history
Following an accessibility audit, the
select_with_search component was found not to meet
WCAG requirements - "Users should be able to
access this list using a keyboard or other input
methods, with each item being announced along with
a count of the total number of options."

It seems like on Safari Voice Over would not
read out the selected option at all, and in other
browsers would not read out the total count of
options.

I'm replacing the component with the autocomplete
component, which does not use the `Choices`
library and is based on the alphagov accessible
autocomplete, and seems to provide the same
functionality and the required Voice Over
behaviour. There are accessibility issues when
using this component with the `multiselect` option
(as Whitehall do)[1], but shouldn't be when just
using it as a combobox.

I've also had to change one of our feature specs,
because using the javascript helpers changes how
the `select` function works (it's designed for the
Choices library). We don't actually need to fill
in the form so I've just removed that step.

[1]
https://drive.google.com/file/d/1BgR9Tkpr9nEYoU3mrUwue306XjLAsZ7B/view?usp=sharing
(when the selected options appear below the combobox they are not
announced, and not keyboard navigable)
  • Loading branch information
Harriethw committed Jan 10, 2025
1 parent 65d4b0d commit 39ef096
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@
} %>
<% end %>

<%= render "components/select_with_search", {
<%= render "components/autocomplete", {
id: "#{parent_class}_lead_organisation",
name: "content_block/edition[organisation_id]",
label: "Lead organisation",
include_blank: true,
options: taggable_organisations_container.map do |name, id|
{
text: name,
value: id,
selected: id == @form.content_block_edition.edition_organisation&.organisation_id,
}
end,
error_message: errors_for_input(@form.content_block_edition.errors, "lead_organisation".to_sym),
label: {
text: "Lead organisation",
},
select: {
multiple: false,
options: [""] + taggable_organisations_container,
selected: @form.content_block_edition.edition_organisation&.organisation_id,
},
autocomplete_configuration_options: {
showAllValues: true,
},
} %>

<%= render "govuk_publishing_components/components/textarea", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Feature: Edit a content object
@javascript
Scenario: GDS editor can preview a host document
When I revisit the edit page
And I fill out the form
And I save and continue
Then I am shown where the changes will take place
And I see the rollup data for the dependent content
When I click on the first host document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_
page.switch_to_window(page.windows.last)
assert_text "Preview email address"
assert_text "Instances: 1"
assert_text "Email address: [email protected]"
assert_text "Email address: #{@email_address}"
within_frame "preview" do
assert_text @current_host_document["title"]
end
Expand All @@ -642,7 +642,7 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_
Then("I should see the content of the linked page") do
within_frame "preview" do
assert_text "other page"
assert_text "[email protected]"
assert_text @email_address
end
end

Expand Down

0 comments on commit 39ef096

Please sign in to comment.