govuk_publishing_components 21.2.0 → 21.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 622487f061b5e3ce6b708c87a4ff7ef21044fcce36df2b7fd195a093dcd94dc0
4
- data.tar.gz: '0164998fd0707382bab460b9dd702e985d7ebc50d76270870f6f2fa5174fe2be'
3
+ metadata.gz: fbcad820792648c45683e5b4226a47f17353ec7c8018089dd375e239db1ee43e
4
+ data.tar.gz: 30e3861a060a0c9c476a3f0d0ee2628753e7fcd7972ce638f2ea7ec5ea33a5de
5
5
  SHA512:
6
- metadata.gz: 2f63af3bdcc9fadf1653a7070627ac89e914f9ff32828cb60eb1ea17ba3cac7e6941e5a46075b95275d707a33dcde372a8225648a0aa0eb0bd340a3309164755
7
- data.tar.gz: 51463c1b48991a4b5db28a663e2bb271d0baa6b5cf88457b073d463612129cca5bc86d6ee44ae4cd40787510cb6b91b8d83b62079fb9fed59e579e132c5e6ae9
6
+ metadata.gz: 2a77463ccd09451691c92bcf2a10fac990b9ce93d37320a1a9b300626b9902d6c054ac8afd26aae9b330f37460f0113e9e1f8a75297fb7f4a89438a4a64a0b5f
7
+ data.tar.gz: 8dccc6978ed550e5ee4718ab0e3bdd08752b1738dc1cefa3b914eff872ae6ce541e965b1548315ac7a102be4fb9251bf08dbb0bf2ae90b426980dfd9d05ecb85
@@ -3,13 +3,33 @@
3
3
  describedby ||= nil
4
4
  role ||= nil
5
5
  heading_size = false unless ['s', 'm', 'l', 'xl'].include?(heading_size)
6
+ error_message ||= nil
7
+ error_id ||= nil
8
+
9
+ if error_message
10
+ error_id = "error-#{SecureRandom.hex(4)}" unless error_id
11
+ describedby = error_id
12
+ end
13
+
14
+ css_classes = %w(gem-c-fieldset govuk-form-group)
15
+ css_classes << "govuk-form-group--error" if error_message
16
+
17
+ fieldset_classes = %w(govuk-fieldset)
6
18
 
7
19
  legend_classes = %w(govuk-fieldset__legend)
8
20
  legend_classes << "govuk-fieldset__legend--#{heading_size}" if heading_size
9
21
  %>
10
- <%= tag.fieldset class: "gem-c-fieldset govuk-fieldset", aria: { describedby: describedby }, role: role do %>
11
- <%= tag.legend class: legend_classes do %>
12
- <%= legend_text %>
22
+ <%= tag.div class: css_classes do %>
23
+ <%= tag.fieldset class: fieldset_classes, aria: { describedby: describedby }, role: role do %>
24
+ <%= tag.legend class: legend_classes do %>
25
+ <%= legend_text %>
26
+ <% end %>
27
+ <% if error_message %>
28
+ <%= render "govuk_publishing_components/components/error_message", {
29
+ text: error_message,
30
+ id: error_id
31
+ } %>
32
+ <% end %>
33
+ <%= text %>
13
34
  <% end %>
14
- <%= text %>
15
35
  <% end %>
@@ -21,6 +21,7 @@
21
21
  hint_id = "hint-#{SecureRandom.hex(4)}"
22
22
  error_id = "error-#{SecureRandom.hex(4)}"
23
23
  search_icon ||= nil
24
+ heading_size = false unless ['s', 'm', 'l', 'xl'].include?(heading_size)
24
25
 
25
26
  css_classes = %w(gem-c-input govuk-input)
26
27
  css_classes << "govuk-input--error" if has_error
@@ -42,7 +43,8 @@
42
43
  <%= content_tag :div, class: form_group_css_classes do %>
43
44
  <% if label %>
44
45
  <%= render "govuk_publishing_components/components/label", {
45
- html_for: id
46
+ html_for: id,
47
+ heading_size: heading_size
46
48
  }.merge(label.symbolize_keys) %>
47
49
  <% end %>
48
50
 
@@ -2,10 +2,12 @@
2
2
  hint_text ||= ''
3
3
  is_radio_label ||= false
4
4
  bold ||= false
5
+ heading_size = false unless ['s', 'm', 'l', 'xl'].include?(heading_size)
5
6
 
6
7
  css_classes = %w( gem-c-label govuk-label )
7
8
  css_classes << "govuk-label--s" if bold
8
9
  css_classes << "govuk-radios__label" if is_radio_label
10
+ css_classes << "govuk-label--#{heading_size}" if heading_size
9
11
 
10
12
  hint_text_css_classes = %w( govuk-hint )
11
13
  hint_text_css_classes << "govuk-radios__hint" if is_radio_label
@@ -5,18 +5,38 @@
5
5
  full_width ||= false
6
6
  name ||= id
7
7
  heading_size = false unless ['s', 'm', 'l', 'xl'].include?(heading_size)
8
+ error_message ||= nil
9
+ error_id ||= nil
10
+
11
+ if error_message || error_id
12
+ error_id = "error-#{SecureRandom.hex(4)}" unless error_id
13
+ aria_describedby = { describedby: error_id }
14
+ end
15
+
16
+ css_classes = %w(govuk-form-group gem-c-select)
17
+ css_classes << "govuk-form-group--error" if error_message
18
+
19
+ select_classes = %w(govuk-select)
20
+ select_classes << "gem-c-select__select--full-width" if full_width
21
+ select_classes << "govuk-select--error" if error_id
8
22
 
9
23
  label_classes = %w(govuk-label)
10
24
  label_classes << "govuk-label--#{heading_size}" if heading_size
11
25
 
12
26
  select_helper = GovukPublishingComponents::Presenters::SelectHelper.new(options)
13
- data_module = "data-module=track-select-change" unless select_helper.data_tracking?.eql?(false)
27
+ data_module = { module: "track-select-change" } unless select_helper.data_tracking?.eql?(false)
14
28
  %>
15
29
  <% if options.any? && id && label %>
16
- <div class="govuk-form-group gem-c-select">
30
+ <%= content_tag :div, class: css_classes do %>
17
31
  <%= label_tag(id, label, class: label_classes) %>
18
- <select class="govuk-select <%= 'gem-c-select__select--full-width' if full_width %>" id="<%= id %>" name="<%= name %>" <%= data_module %> >
19
- <%= options_for_select(select_helper.option_markup, select_helper.selected_option) %>
20
- </select>
21
- </div>
32
+
33
+ <% if error_message %>
34
+ <%= render "govuk_publishing_components/components/error_message", {
35
+ id: error_id,
36
+ text: error_message
37
+ } %>
38
+ <% end %>
39
+
40
+ <%= select_tag name, options_for_select(select_helper.option_markup, select_helper.selected_option), id: id, class: select_classes, data: data_module, aria: aria_describedby %>
41
+ <% end %>
22
42
  <% end %>
@@ -7,13 +7,14 @@ accessibility_criteria: |
7
7
 
8
8
  Error message must:
9
9
 
10
- - be associated with an input. The `error_message_id` must match the `aria-describedby` property on the input your label is associated with.
10
+ - be associated with an input. The `error_message_id` must match the `aria-describedby` property on the input your label is associated with. Note that if `id` is not passed to the component an id will be generated automatically.
11
11
 
12
12
  If error message is within a label it will be announced in its entirety by screen readers. By associating error messages with inputs using `aria-describedby`, then screen readers will read the label, describe the type of input (eg radio) and then read additional text. It means users of screen readers can scan and skip options as easy as people making choices with sight.
13
13
  examples:
14
14
  default:
15
15
  data:
16
16
  text: "Please enter your National Insurance Number"
17
+ id: "error_id"
17
18
  with_items:
18
19
  description: Error items are a common pattern where a collection of error is passed with each item having a text attribute of the error
19
20
  data:
@@ -12,10 +12,10 @@ examples:
12
12
  legend_text: 'Do you have a passport?'
13
13
  text: |
14
14
  <!-- Use the radio component, this is hardcoded only for this example -->
15
- <input type="radio" id="default-yes" name="default"t>
15
+ <input type="radio" id="default-yes" name="default">
16
16
  <label for="default-yes">Yes</label>
17
17
 
18
- <input type="radio" id="default-no" name="default"t>
18
+ <input type="radio" id="default-no" name="default">
19
19
  <label for="default-no">No</label>
20
20
  with_custom_legend_size:
21
21
  description: Make the legend different sizes. Valid options are 's', 'm', 'l' and 'xl'.
@@ -24,10 +24,10 @@ examples:
24
24
  heading_size: 'l'
25
25
  text: |
26
26
  <!-- Use the radio component, this is hardcoded only for this example -->
27
- <input type="radio" id="size-yes" name="default"t>
27
+ <input type="radio" id="size-yes" name="default">
28
28
  <label for="size-yes">Yes</label>
29
29
 
30
- <input type="radio" id="size-no" name="default"t>
30
+ <input type="radio" id="size-no" name="default">
31
31
  <label for="size-no">No</label>
32
32
  with_html_legend:
33
33
  description: 'If you only have one fieldset on the page you might want to include the title of the page as the legend text. Used with a [captured](http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#method-i-capture) [title](http://components.publishing.service.gov.uk/component-guide/title)'
@@ -44,3 +44,15 @@ examples:
44
44
 
45
45
  <input type="radio" id="html-legend-no" name="html-legend">
46
46
  <label for="html-legend-no">No</label>
47
+ with_error_message:
48
+ description: The component also accepts an error_id, or generates one automatically.
49
+ data:
50
+ legend_text: 'Do you have a passport?'
51
+ error_message: 'Please choose an option'
52
+ text: |
53
+ <!-- Use the radio component, this is hardcoded only for this example -->
54
+ <input type="radio" id="default2-yes" name="default2">
55
+ <label for="default2-yes">Yes</label>
56
+
57
+ <input type="radio" id="default2-no" name="default2">
58
+ <label for="default2-no">No</label>
@@ -69,9 +69,7 @@ examples:
69
69
  name: "name"
70
70
  error_items:
71
71
  - text: Descriptive link to the question with an error 1
72
- href: '#example-error-1'
73
72
  - text: Descriptive link to the question with an error 2
74
- href: '#example-error-2'
75
73
  with_value:
76
74
  data:
77
75
  label:
@@ -120,3 +118,10 @@ examples:
120
118
  name: "search-box"
121
119
  type: "search"
122
120
  search_icon: true
121
+ with_custom_label_size:
122
+ description: Make the label different sizes. Valid options are 's', 'm', 'l' and 'xl'.
123
+ data:
124
+ label:
125
+ text: "What is your name?"
126
+ name: "name"
127
+ heading_size: "l"
@@ -27,6 +27,12 @@ examples:
27
27
  html_for: "id-that-matches-input"
28
28
  hint_id: "should-match-aria-describedby-input"
29
29
  hint_text: "It’s on your National Insurance card, benefit letter, payslip or P60. For example, ‘QQ 12 34 56 C’."
30
+ with_custom_label_size:
31
+ description: Make the label different sizes. Valid options are 's', 'm', 'l' and 'xl'.
32
+ data:
33
+ text: "Surname"
34
+ html_for: "id-that-matches-input"
35
+ heading_size: "xl"
30
36
  bold_with_hint:
31
37
  data:
32
38
  bold: true
@@ -90,6 +90,33 @@ examples:
90
90
  value: 'option2'
91
91
  - text: 'Option three'
92
92
  value: 'option3'
93
+ with_error:
94
+ description: If the user has to select an option, it is recommended that a radio button is used instead of a select, but this is not always possible. Note that error_id is optional, if it is not passed one will be generated automatically.
95
+ data:
96
+ id: 'dropdown4-1'
97
+ label: 'How will you be travelling to the conference?'
98
+ error_message: 'Please choose an option'
99
+ error_id: 'error_id'
100
+ options:
101
+ - text: ""
102
+ value: ""
103
+ - text: 'Public transport'
104
+ value: 'option1'
105
+ - text: 'Will make own arrangements'
106
+ value: 'option2'
107
+ with_error_id_but_no_message:
108
+ description: For some selects the error message should be rendered separately but an error state is still required (currently required in smart answers). In this scenario an error_id can be passed without an error_message to highlight the component and set aria-describedby correctly.
109
+ data:
110
+ id: 'dropdown4-2'
111
+ label: 'What lunch option would you like?'
112
+ error_id: 'error_id'
113
+ options:
114
+ - text: ""
115
+ value: ""
116
+ - text: 'Vegetarian'
117
+ value: 'option1'
118
+ - text: 'Meat'
119
+ value: 'option2'
93
120
  full_width:
94
121
  description: Make the select width 100%. This is used for facets in finder-frontend's search.
95
122
  data:
@@ -24,7 +24,9 @@ module GovukPublishingComponents
24
24
  end
25
25
 
26
26
  def questions_and_answers_markup
27
- question_and_answers(page.body).map do |question, value|
27
+ question_and_answers(page.body)
28
+ .select { |_, value| value[:answer].present? }
29
+ .map do |question, value|
28
30
  q_and_a_url = section_url(value[:anchor])
29
31
 
30
32
  {
@@ -42,7 +44,7 @@ module GovukPublishingComponents
42
44
 
43
45
  # Generates a hash of questions and associated information:
44
46
  # - question: the text in the h2 tag preceding other markup. Questions are
45
- # used to key the hash. "Summary" is set as the default, as
47
+ # used to key the hash. The page title is set as the default, as
46
48
  # there is often a preamble in guides before any h2 is set.
47
49
  #
48
50
  # - :answer: the markup that is not an h2 tag. It is associated with the
@@ -53,7 +55,7 @@ module GovukPublishingComponents
53
55
  def question_and_answers(html)
54
56
  doc = Nokogiri::HTML(html)
55
57
 
56
- question = "Summary"
58
+ question = page.title
57
59
 
58
60
  # rubocop:disable Style/IfInsideElse
59
61
  doc.xpath("html/body").children.each_with_object({}) do |element, q_and_as|
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = '21.2.0'.freeze
2
+ VERSION = '21.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 21.2.0
4
+ version: 21.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-25 00:00:00.000000000 Z
11
+ date: 2019-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gds-api-adapters