govuk_publishing_components 58.1.0 → 58.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/images/select-with-search/cross-icon.svg +6 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-search-tracker.js +4 -0
- data/app/assets/javascripts/govuk_publishing_components/components/select-with-search.js +57 -0
- data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_layout-super-navigation-header.scss +7 -2
- data/app/assets/stylesheets/govuk_publishing_components/components/_select-with-search.scss +168 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_select.scss +6 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_contact.scss +10 -10
- data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_typography.scss +3 -16
- data/app/views/govuk_publishing_components/components/_add_another.html.erb +0 -1
- data/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_select.html.erb +22 -23
- data/app/views/govuk_publishing_components/components/_select_with_search.html.erb +14 -0
- data/app/views/govuk_publishing_components/components/docs/select.yml +11 -0
- data/app/views/govuk_publishing_components/components/docs/select_with_search.yml +196 -0
- data/lib/govuk_publishing_components/presenters/select_helper.rb +8 -5
- data/lib/govuk_publishing_components/presenters/select_with_search_helper.rb +92 -0
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/lib/govuk_publishing_components.rb +1 -0
- data/node_modules/choices.js/LICENSE +21 -0
- data/node_modules/choices.js/README.md +1360 -0
- data/node_modules/choices.js/package.json +173 -0
- data/node_modules/choices.js/public/assets/scripts/choices.js +5230 -0
- data/node_modules/choices.js/public/assets/scripts/choices.min.js +2 -0
- data/node_modules/choices.js/public/assets/scripts/choices.mjs +5222 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-basic.js +4748 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-basic.min.js +2 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-basic.mjs +4740 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-kmp.js +3631 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-kmp.min.js +2 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-kmp.mjs +3623 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-prefix.js +3590 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-prefix.min.js +2 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-prefix.mjs +3582 -0
- data/node_modules/choices.js/public/assets/styles/base.css +180 -0
- data/node_modules/choices.js/public/assets/styles/base.css.map +1 -0
- data/node_modules/choices.js/public/assets/styles/base.min.css +1 -0
- data/node_modules/choices.js/public/assets/styles/choices.css +338 -0
- data/node_modules/choices.js/public/assets/styles/choices.css.map +1 -0
- data/node_modules/choices.js/public/assets/styles/choices.min.css +1 -0
- data/node_modules/choices.js/public/types/src/index.d.ts +6 -0
- data/node_modules/choices.js/public/types/src/scripts/actions/choices.d.ts +30 -0
- data/node_modules/choices.js/public/types/src/scripts/actions/groups.d.ts +8 -0
- data/node_modules/choices.js/public/types/src/scripts/actions/items.d.ts +17 -0
- data/node_modules/choices.js/public/types/src/scripts/choices.d.ts +210 -0
- data/node_modules/choices.js/public/types/src/scripts/components/container.d.ts +36 -0
- data/node_modules/choices.js/public/types/src/scripts/components/dropdown.d.ts +21 -0
- data/node_modules/choices.js/public/types/src/scripts/components/index.d.ts +7 -0
- data/node_modules/choices.js/public/types/src/scripts/components/input.d.ts +37 -0
- data/node_modules/choices.js/public/types/src/scripts/components/list.d.ts +14 -0
- data/node_modules/choices.js/public/types/src/scripts/components/wrapped-element.d.ts +21 -0
- data/node_modules/choices.js/public/types/src/scripts/components/wrapped-input.d.ts +3 -0
- data/node_modules/choices.js/public/types/src/scripts/components/wrapped-select.d.ts +20 -0
- data/node_modules/choices.js/public/types/src/scripts/constants.d.ts +1 -0
- data/node_modules/choices.js/public/types/src/scripts/defaults.d.ts +4 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/action-type.d.ts +13 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/build-flags.d.ts +11 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/choice-full.d.ts +23 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/class-names.d.ts +61 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/event-choice.d.ts +7 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/event-type.d.ts +14 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/group-full.d.ts +10 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/index.d.ts +14 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/input-choice.d.ts +15 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/input-group.d.ts +10 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/item.d.ts +17 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/keycode-map.d.ts +13 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/options.d.ts +566 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/passed-element-type.d.ts +7 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/passed-element.d.ts +95 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/position-options-type.d.ts +1 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/search.d.ts +11 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/state.d.ts +10 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/store.d.ts +64 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/string-pre-escaped.d.ts +3 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/string-untrusted.d.ts +4 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/templates.d.ts +29 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/types.d.ts +18 -0
- data/node_modules/choices.js/public/types/src/scripts/lib/choice-input.d.ts +9 -0
- data/node_modules/choices.js/public/types/src/scripts/lib/html-guard-statements.d.ts +4 -0
- data/node_modules/choices.js/public/types/src/scripts/lib/utils.d.ts +31 -0
- data/node_modules/choices.js/public/types/src/scripts/reducers/choices.d.ts +8 -0
- data/node_modules/choices.js/public/types/src/scripts/reducers/groups.d.ts +8 -0
- data/node_modules/choices.js/public/types/src/scripts/reducers/items.d.ts +9 -0
- data/node_modules/choices.js/public/types/src/scripts/search/fuse.d.ts +14 -0
- data/node_modules/choices.js/public/types/src/scripts/search/index.d.ts +3 -0
- data/node_modules/choices.js/public/types/src/scripts/search/kmp.d.ts +11 -0
- data/node_modules/choices.js/public/types/src/scripts/search/prefix-filter.d.ts +11 -0
- data/node_modules/choices.js/public/types/src/scripts/store/store.d.ts +59 -0
- data/node_modules/choices.js/public/types/src/scripts/templates.d.ts +8 -0
- data/node_modules/choices.js/src/entry.js +3 -0
- data/node_modules/choices.js/src/icons/cross-inverse.svg +1 -0
- data/node_modules/choices.js/src/icons/cross.svg +1 -0
- data/node_modules/choices.js/src/index.ts +8 -0
- data/node_modules/choices.js/src/scripts/actions/choices.ts +59 -0
- data/node_modules/choices.js/src/scripts/actions/groups.ts +14 -0
- data/node_modules/choices.js/src/scripts/actions/items.ts +34 -0
- data/node_modules/choices.js/src/scripts/choices.ts +2364 -0
- data/node_modules/choices.js/src/scripts/components/container.ts +157 -0
- data/node_modules/choices.js/src/scripts/components/dropdown.ts +50 -0
- data/node_modules/choices.js/src/scripts/components/index.ts +8 -0
- data/node_modules/choices.js/src/scripts/components/input.ts +146 -0
- data/node_modules/choices.js/src/scripts/components/list.ts +89 -0
- data/node_modules/choices.js/src/scripts/components/wrapped-element.ts +89 -0
- data/node_modules/choices.js/src/scripts/components/wrapped-input.ts +3 -0
- data/node_modules/choices.js/src/scripts/components/wrapped-select.ts +115 -0
- data/node_modules/choices.js/src/scripts/constants.ts +1 -0
- data/node_modules/choices.js/src/scripts/defaults.ts +93 -0
- data/node_modules/choices.js/src/scripts/interfaces/action-type.ts +15 -0
- data/node_modules/choices.js/src/scripts/interfaces/build-flags.ts +17 -0
- data/node_modules/choices.js/src/scripts/interfaces/choice-full.ts +30 -0
- data/node_modules/choices.js/src/scripts/interfaces/class-names.ts +61 -0
- data/node_modules/choices.js/src/scripts/interfaces/event-choice.ts +9 -0
- data/node_modules/choices.js/src/scripts/interfaces/event-type.ts +16 -0
- data/node_modules/choices.js/src/scripts/interfaces/group-full.ts +12 -0
- data/node_modules/choices.js/src/scripts/interfaces/index.ts +14 -0
- data/node_modules/choices.js/src/scripts/interfaces/input-choice.ts +17 -0
- data/node_modules/choices.js/src/scripts/interfaces/input-group.ts +11 -0
- data/node_modules/choices.js/src/scripts/interfaces/item.ts +17 -0
- data/node_modules/choices.js/src/scripts/interfaces/keycode-map.ts +13 -0
- data/node_modules/choices.js/src/scripts/interfaces/options.ts +619 -0
- data/node_modules/choices.js/src/scripts/interfaces/passed-element-type.ts +9 -0
- data/node_modules/choices.js/src/scripts/interfaces/passed-element.ts +96 -0
- data/node_modules/choices.js/src/scripts/interfaces/position-options-type.ts +1 -0
- data/node_modules/choices.js/src/scripts/interfaces/search.ts +12 -0
- data/node_modules/choices.js/src/scripts/interfaces/state.ts +12 -0
- data/node_modules/choices.js/src/scripts/interfaces/store.ts +84 -0
- data/node_modules/choices.js/src/scripts/interfaces/string-pre-escaped.ts +3 -0
- data/node_modules/choices.js/src/scripts/interfaces/string-untrusted.ts +5 -0
- data/node_modules/choices.js/src/scripts/interfaces/templates.ts +66 -0
- data/node_modules/choices.js/src/scripts/interfaces/types.ts +21 -0
- data/node_modules/choices.js/src/scripts/lib/choice-input.ts +88 -0
- data/node_modules/choices.js/src/scripts/lib/html-guard-statements.ts +7 -0
- data/node_modules/choices.js/src/scripts/lib/utils.ts +230 -0
- data/node_modules/choices.js/src/scripts/reducers/choices.ts +86 -0
- data/node_modules/choices.js/src/scripts/reducers/groups.ts +32 -0
- data/node_modules/choices.js/src/scripts/reducers/items.ts +86 -0
- data/node_modules/choices.js/src/scripts/search/fuse.ts +59 -0
- data/node_modules/choices.js/src/scripts/search/index.ts +17 -0
- data/node_modules/choices.js/src/scripts/search/kmp.ts +87 -0
- data/node_modules/choices.js/src/scripts/search/prefix-filter.ts +42 -0
- data/node_modules/choices.js/src/scripts/store/store.ts +184 -0
- data/node_modules/choices.js/src/scripts/templates.ts +409 -0
- data/node_modules/choices.js/src/styles/base.scss +189 -0
- data/node_modules/choices.js/src/styles/choices.scss +414 -0
- data/node_modules/choices.js/src/tsconfig.json +22 -0
- metadata +134 -1
@@ -0,0 +1,196 @@
|
|
1
|
+
name: Select with search (experimental)
|
2
|
+
description: A dropdown select with search
|
3
|
+
body: |
|
4
|
+
A Javascript enhanced dropdown select. This component is progressively enhanced, if
|
5
|
+
Javascript is unavailable then it will use the select component.
|
6
|
+
|
7
|
+
This is an experimental component as it currently fails WCAG compliance for keyboard navigation. The total number of options are not
|
8
|
+
announced when using Voice Over.
|
9
|
+
accessibility_criteria: |
|
10
|
+
- accept focus
|
11
|
+
- be focusable with a keyboard
|
12
|
+
- be usable with a keyboard
|
13
|
+
- indicate when it has focus
|
14
|
+
examples:
|
15
|
+
default:
|
16
|
+
data:
|
17
|
+
id: dropdown-default
|
18
|
+
label: My Dropdown
|
19
|
+
options:
|
20
|
+
- text: Option one
|
21
|
+
value: option1
|
22
|
+
- text: Option two
|
23
|
+
value: option2
|
24
|
+
- text: Option three
|
25
|
+
value: option3
|
26
|
+
with_blank_option:
|
27
|
+
description: Include a blank option
|
28
|
+
data:
|
29
|
+
id: dropdown-with-blank
|
30
|
+
label: With blank option
|
31
|
+
include_blank: true
|
32
|
+
options:
|
33
|
+
- text: Option one
|
34
|
+
value: option1
|
35
|
+
- text: Option two
|
36
|
+
value: option2
|
37
|
+
- text: Option three
|
38
|
+
value: option3
|
39
|
+
with_grouped_options:
|
40
|
+
description: Options can be grouped
|
41
|
+
data:
|
42
|
+
id: dropdown-with-grouped-options
|
43
|
+
label: Select a city
|
44
|
+
grouped_options:
|
45
|
+
- - England
|
46
|
+
- - text: Bath
|
47
|
+
value: bath
|
48
|
+
- text: Bristol
|
49
|
+
value: bristol
|
50
|
+
- text: London
|
51
|
+
value: london
|
52
|
+
- text: Manchester
|
53
|
+
value: manchester
|
54
|
+
- - Northern Ireland
|
55
|
+
- - text: Bangor
|
56
|
+
value: bangor
|
57
|
+
- text: Belfast
|
58
|
+
value: belfast
|
59
|
+
- - Scotland
|
60
|
+
- - text: Dundee
|
61
|
+
value: dundee
|
62
|
+
- text: Edinburgh
|
63
|
+
value: edinburgh
|
64
|
+
- text: Glasgow
|
65
|
+
value: glasgow
|
66
|
+
- - Wales
|
67
|
+
- - text: Cardiff
|
68
|
+
value: cardiff
|
69
|
+
- text: Swansea
|
70
|
+
value: swansea
|
71
|
+
with_grouped_options_and_blank_option:
|
72
|
+
description: Options can be grouped and include a blank option
|
73
|
+
data:
|
74
|
+
id: dropdown-with-grouped-options-and-blank
|
75
|
+
label: Select a city
|
76
|
+
include_blank: true
|
77
|
+
grouped_options:
|
78
|
+
- - England
|
79
|
+
- - text: Bath
|
80
|
+
value: bath
|
81
|
+
- text: Bristol
|
82
|
+
value: bristol
|
83
|
+
- text: London
|
84
|
+
value: london
|
85
|
+
- text: Manchester
|
86
|
+
value: manchester
|
87
|
+
- - Northern Ireland
|
88
|
+
- - text: Bangor
|
89
|
+
value: bangor
|
90
|
+
- text: Belfast
|
91
|
+
value: belfast
|
92
|
+
- - Scotland
|
93
|
+
- - text: Dundee
|
94
|
+
value: dundee
|
95
|
+
- text: Edinburgh
|
96
|
+
value: edinburgh
|
97
|
+
- text: Glasgow
|
98
|
+
value: glasgow
|
99
|
+
- - Wales
|
100
|
+
- - text: Cardiff
|
101
|
+
value: cardiff
|
102
|
+
- text: Swansea
|
103
|
+
value: swansea
|
104
|
+
with_different_id_and_name:
|
105
|
+
description: If no name is provided, name defaults to the (required) value of id.
|
106
|
+
data:
|
107
|
+
id: dropdown-with-different-id-and-name
|
108
|
+
label: My Dropdown
|
109
|
+
name: dropdown[1]
|
110
|
+
options:
|
111
|
+
- text: Option one
|
112
|
+
value: option1
|
113
|
+
- text: Option two
|
114
|
+
value: option2
|
115
|
+
with_data_attributes:
|
116
|
+
data:
|
117
|
+
id: dropdown-with-data-attributes
|
118
|
+
data_attributes:
|
119
|
+
module: not-a-module
|
120
|
+
loose: moose
|
121
|
+
label: Select your country
|
122
|
+
options:
|
123
|
+
- text: France
|
124
|
+
value: fr
|
125
|
+
- text: Germany
|
126
|
+
value: de
|
127
|
+
- text: United Kingdom
|
128
|
+
value: uk
|
129
|
+
with_preselect:
|
130
|
+
data:
|
131
|
+
id: dropdown-with-preselect
|
132
|
+
label: Option 2 preselected
|
133
|
+
options:
|
134
|
+
- text: Option one
|
135
|
+
value: option1
|
136
|
+
- text: Option two
|
137
|
+
value: option2
|
138
|
+
selected: true
|
139
|
+
- text: Option three
|
140
|
+
value: option3
|
141
|
+
with_hint:
|
142
|
+
description: When a hint is included the `aria-describedby` attribute of the select is included to point to the hint. When an error and a hint are present, that attribute includes the IDs of both the hint and the error.
|
143
|
+
data:
|
144
|
+
id: dropdown-with-hint
|
145
|
+
label: Choose your preferred thing
|
146
|
+
hint: You might need some more information here
|
147
|
+
hint_id: optional-hint-id
|
148
|
+
options:
|
149
|
+
- text: Something
|
150
|
+
value: option1
|
151
|
+
- text: Something else
|
152
|
+
value: option2
|
153
|
+
with_error:
|
154
|
+
description: An arbitrary number of separate error items can be passed to the component.
|
155
|
+
data:
|
156
|
+
id: dropdown-with-error
|
157
|
+
label: How will you be travelling to the conference?
|
158
|
+
error_items:
|
159
|
+
- text: Please choose an option
|
160
|
+
include_blank: true
|
161
|
+
options:
|
162
|
+
- text: Public transport
|
163
|
+
value: option1
|
164
|
+
- text: Will make own arrangements
|
165
|
+
value: option2
|
166
|
+
with_custom_label_size:
|
167
|
+
description: Make the label different sizes. Valid options are `s`, `m`, `l` and `xl`.
|
168
|
+
data:
|
169
|
+
id: dropdown-with-custom-label-size
|
170
|
+
label: Bigger!
|
171
|
+
heading_size: xl
|
172
|
+
options:
|
173
|
+
- text: Option one
|
174
|
+
value: option1
|
175
|
+
- text: Option two
|
176
|
+
value: option2
|
177
|
+
- text: Option three
|
178
|
+
value: option3
|
179
|
+
with_multiple_select_enabled:
|
180
|
+
description: Allow multiple items to be selected and de-selected.
|
181
|
+
data:
|
182
|
+
id: dropdown-with-multiple
|
183
|
+
label: Select your country
|
184
|
+
include_blank: true
|
185
|
+
multiple: true
|
186
|
+
options:
|
187
|
+
- text: France
|
188
|
+
value: fr
|
189
|
+
selected: false
|
190
|
+
- text: Germany
|
191
|
+
value: de
|
192
|
+
selected: false
|
193
|
+
- text: The United Kingdom of Great Britain and Northern Ireland
|
194
|
+
value: uk
|
195
|
+
- text: Democratic Republic of the Congo
|
196
|
+
value: cg
|
@@ -1,23 +1,26 @@
|
|
1
1
|
module GovukPublishingComponents
|
2
2
|
module Presenters
|
3
3
|
class SelectHelper
|
4
|
-
|
4
|
+
include ActionView::Helpers::FormOptionsHelper
|
5
|
+
|
6
|
+
attr_reader :options, :options_markup, :error_items, :error_id, :hint, :hint_id, :describedby
|
5
7
|
|
6
8
|
def initialize(local_assigns)
|
7
9
|
@options = local_assigns[:options] || []
|
8
|
-
@
|
10
|
+
@error_items = local_assigns[:error_items] || []
|
11
|
+
@error_items << { text: local_assigns[:error_message] } if local_assigns[:error_message]
|
9
12
|
@error_id = local_assigns[:error_id] || nil
|
10
13
|
@hint = local_assigns[:hint] || nil
|
11
14
|
@hint_id = local_assigns[:hint_id] || nil
|
12
15
|
@heading_size = local_assigns[:heading_size]
|
13
16
|
@full_width = local_assigns[:full_width] || false
|
14
|
-
@
|
17
|
+
@options_markup = options_for_select(get_options, @selected_option)
|
15
18
|
@describedby = get_describedby
|
16
19
|
end
|
17
20
|
|
18
21
|
def css_classes
|
19
22
|
classes = %w[govuk-form-group gem-c-select]
|
20
|
-
classes << "govuk-form-group--error" if @
|
23
|
+
classes << "govuk-form-group--error" if @error_items.present?
|
21
24
|
classes
|
22
25
|
end
|
23
26
|
|
@@ -66,7 +69,7 @@ module GovukPublishingComponents
|
|
66
69
|
def get_describedby
|
67
70
|
describedby = %w[]
|
68
71
|
|
69
|
-
if @
|
72
|
+
if @error_items.present? || @error_id
|
70
73
|
@error_id ||= "error-#{SecureRandom.hex(4)}"
|
71
74
|
describedby << @error_id
|
72
75
|
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
##
|
2
|
+
# Helper methods for use with the "select-with-search" component.
|
3
|
+
# This wraps and extends the Select component's helper methods to add support for option groups.
|
4
|
+
##
|
5
|
+
module GovukPublishingComponents
|
6
|
+
module Presenters
|
7
|
+
class SelectWithSearchHelper
|
8
|
+
include ActionView::Helpers::FormOptionsHelper
|
9
|
+
|
10
|
+
attr_reader :options, :selected_options, :aria, :options_markup
|
11
|
+
|
12
|
+
delegate :describedby,
|
13
|
+
:hint_id,
|
14
|
+
:hint,
|
15
|
+
:label_classes,
|
16
|
+
:select_classes,
|
17
|
+
:error_items,
|
18
|
+
:error_id,
|
19
|
+
to: :@select_helper
|
20
|
+
|
21
|
+
def initialize(local_assigns)
|
22
|
+
@select_helper = SelectHelper.new(local_assigns.except(:options, :grouped_options))
|
23
|
+
@options = local_assigns[:options]
|
24
|
+
@grouped_options = local_assigns[:grouped_options]
|
25
|
+
@include_blank = local_assigns[:include_blank]
|
26
|
+
@selected_options = []
|
27
|
+
@options_markup = get_options
|
28
|
+
@local_assigns = local_assigns
|
29
|
+
end
|
30
|
+
|
31
|
+
def css_classes
|
32
|
+
classes = @select_helper.css_classes
|
33
|
+
classes << "gem-c-select-with-search"
|
34
|
+
classes
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def get_options
|
40
|
+
blank_option_if_include_blank +
|
41
|
+
if @grouped_options.present?
|
42
|
+
grouped_and_ungrouped_options_for_select(@grouped_options)
|
43
|
+
elsif @options.present?
|
44
|
+
options_for_select(
|
45
|
+
transform_options(@options),
|
46
|
+
selected_options,
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def grouped_and_ungrouped_options_for_select(unsorted_options)
|
52
|
+
# Filter out the 'single option' options and treat them as simply `<option>`
|
53
|
+
# The remainder should be treated as true 'grouped options', i.e. `<optgroup>`
|
54
|
+
single_options = []
|
55
|
+
grouped_options = []
|
56
|
+
unsorted_options.each_with_index do |(group, options), _index|
|
57
|
+
if group == ""
|
58
|
+
single_options << options
|
59
|
+
else
|
60
|
+
grouped_options << [group, options]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
single_options.flatten!
|
64
|
+
|
65
|
+
options_for_select(transform_options(single_options), selected_options) +
|
66
|
+
grouped_options_for_select(transform_grouped_options(grouped_options), selected_options)
|
67
|
+
end
|
68
|
+
|
69
|
+
def transform_options(options)
|
70
|
+
options.map do |option|
|
71
|
+
@selected_options << option[:value] if option[:selected]
|
72
|
+
[
|
73
|
+
option[:text],
|
74
|
+
option[:value],
|
75
|
+
]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def transform_grouped_options(grouped_options)
|
80
|
+
grouped_options.map do |(group, options)|
|
81
|
+
[group, transform_options(options)]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def blank_option_if_include_blank
|
86
|
+
return "".html_safe if @include_blank.blank?
|
87
|
+
|
88
|
+
options_for_select([["", ""]])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -27,6 +27,7 @@ require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_org
|
|
27
27
|
require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons"
|
28
28
|
require "govuk_publishing_components/presenters/checkboxes_helper"
|
29
29
|
require "govuk_publishing_components/presenters/select_helper"
|
30
|
+
require "govuk_publishing_components/presenters/select_with_search_helper"
|
30
31
|
require "govuk_publishing_components/presenters/meta_tags"
|
31
32
|
require "govuk_publishing_components/presenters/content_item"
|
32
33
|
require "govuk_publishing_components/presenters/translation_nav_helper"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Josh Johnson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|