Browse Source
* Include accessible autoselect package * Test type ahead functionality * Add CSS * Disabled null value * Fix answer options so they match validations * Disabled * Only english LAs for current LA * Rubocoppull/180/head
baarkerlounger
3 years ago
committed by
GitHub
13 changed files with 1432 additions and 950 deletions
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,11 @@ |
|||||||
<%= answers = question.answer_options.map { |key, value| OpenStruct.new(id:key, name: value) } |
<%= answers = question.answer_options.map { |key, value| OpenStruct.new(id: key, name: value) } |
||||||
f.govuk_collection_select question.id.to_sym, |
f.govuk_collection_select question.id.to_sym, |
||||||
answers, |
answers, |
||||||
:name, |
:id, |
||||||
:name, |
:name, |
||||||
caption: caption && !page_header.present? ? { text: caption.html_safe, size: "l" } : nil, |
caption: caption && !page_header.present? ? { text: caption.html_safe, size: "l" } : nil, |
||||||
label: { text: question.header, size: !page_header.present? ? "l" : "m", tag: !page_header.present? ? "h1" : "h2" }, |
label: { text: question.header, size: !page_header.present? ? "l" : "m", tag: !page_header.present? ? "h1" : "h2" }, |
||||||
hint: { text: question.hint_text&.html_safe } |
hint: { text: question.hint_text&.html_safe }, |
||||||
|
options: { disabled: [""] }, |
||||||
|
"data-controller": "accessible-autocomplete" |
||||||
%> |
%> |
||||||
|
@ -0,0 +1,12 @@ |
|||||||
|
import { Controller } from "@hotwired/stimulus" |
||||||
|
import accessibleAutocomplete from "accessible-autocomplete" |
||||||
|
import 'accessible-autocomplete/dist/accessible-autocomplete.min.css' |
||||||
|
|
||||||
|
export default class extends Controller { |
||||||
|
connect() { |
||||||
|
accessibleAutocomplete.enhanceSelectElement({ |
||||||
|
defaultValue: '', |
||||||
|
selectElement: this.element |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
.autocomplete__wrapper, |
||||||
|
.autocomplete__input, |
||||||
|
.autocomplete__hint { |
||||||
|
font-family: $govuk-font-family; |
||||||
|
} |
||||||
|
|
||||||
|
.govuk-form-group--error { |
||||||
|
.autocomplete__input { |
||||||
|
border-color: $govuk-error-colour; |
||||||
|
} |
||||||
|
|
||||||
|
.autocomplete__input--focused { |
||||||
|
border-color: $govuk-input-border-colour; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
.autocomplete__dropdown-arrow-down { |
||||||
|
pointer-events: none; |
||||||
|
z-index: 0; |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
require "rails_helper" |
||||||
|
require_relative "helpers" |
||||||
|
require_relative "../../request_helper" |
||||||
|
|
||||||
|
RSpec.describe "Accessible Automcomplete" do |
||||||
|
include Helpers |
||||||
|
let(:user) { FactoryBot.create(:user) } |
||||||
|
let(:case_log) do |
||||||
|
FactoryBot.create( |
||||||
|
:case_log, |
||||||
|
:in_progress, |
||||||
|
owning_organisation: user.organisation, |
||||||
|
managing_organisation: user.organisation, |
||||||
|
) |
||||||
|
end |
||||||
|
|
||||||
|
before do |
||||||
|
RequestHelper.stub_http_requests |
||||||
|
sign_in user |
||||||
|
end |
||||||
|
|
||||||
|
it "allows type ahead filtering", js: true do |
||||||
|
visit("/logs/#{case_log.id}/accessible-select") |
||||||
|
find("#case-log-la-field").click.native.send_keys("T", "h", "a", "n", :down, :enter) |
||||||
|
expect(find("#case-log-la-field").value).to eq("Thanet") |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue