`
*
@@ -1888,7 +1890,32 @@ ErrorSummary.prototype.getAssociatedLegendOrLabel = function ($input) {
var legends = $fieldset.getElementsByTagName('legend');
if (legends.length) {
- return legends[0]
+ var $candidateLegend = legends[0];
+
+ // If the input type is radio or checkbox, always use the legend if there
+ // is one.
+ if ($input.type === 'checkbox' || $input.type === 'radio') {
+ return $candidateLegend
+ }
+
+ // For other input types, only scroll to the fieldset’s legend (instead of
+ // the label associated with the input) if the input would end up in the
+ // top half of the screen.
+ //
+ // This should avoid situations where the input either ends up off the
+ // screen, or obscured by a software keyboard.
+ var legendTop = $candidateLegend.getBoundingClientRect().top;
+ var inputRect = $input.getBoundingClientRect();
+
+ // If the browser doesn't support Element.getBoundingClientRect().height
+ // or window.innerHeight (like IE8), bail and just link to the label.
+ if (inputRect.height && window.innerHeight) {
+ var inputBottom = inputRect.top + inputRect.height;
+
+ if (inputBottom - legendTop < window.innerHeight / 2) {
+ return $candidateLegend
+ }
+ }
}
}
diff --git a/package/govuk/components/checkboxes/template.njk b/package/govuk/components/checkboxes/template.njk
index fd4086cf5d..57df1cd760 100644
--- a/package/govuk/components/checkboxes/template.njk
+++ b/package/govuk/components/checkboxes/template.njk
@@ -16,7 +16,7 @@
{% set isConditional = false %}
{% for item in params.items %}
- {% if item.conditional %}
+ {% if item.conditional.html %}
{% set isConditional = true %}
{% endif %}
{% endfor %}
@@ -75,7 +75,7 @@
{{ govukLabel({
@@ -95,7 +95,7 @@
}) | indent(6) | trim }}
{% endif %}
- {% if item.conditional %}
+ {% if item.conditional.html %}
{{ item.conditional.html | safe }}
diff --git a/package/govuk/components/date-input/macro-options.json b/package/govuk/components/date-input/macro-options.json
index f7b9dcb30a..54afc88780 100644
--- a/package/govuk/components/date-input/macro-options.json
+++ b/package/govuk/components/date-input/macro-options.json
@@ -14,7 +14,7 @@
{
"name": "items",
"type": "array",
- "required": true,
+ "required": false,
"description": "An array of input objects with name, value and classes.",
"params": [
{
diff --git a/package/govuk/components/error-summary/error-summary.js b/package/govuk/components/error-summary/error-summary.js
index 1049407463..a91c0c4e5b 100644
--- a/package/govuk/components/error-summary/error-summary.js
+++ b/package/govuk/components/error-summary/error-summary.js
@@ -798,7 +798,9 @@ ErrorSummary.prototype.getFragmentFromUrl = function (url) {
*
* Returns the first element that exists from this list:
*
- * - The `` associated with the closest ` ` ancestor
+ * - The `` associated with the closest ` ` ancestor, as long
+ * as the top of it is no more than half a viewport height away from the
+ * bottom of the input
* - The first `` that is associated with the input using for="inputId"
* - The closest parent ``
*
@@ -813,7 +815,32 @@ ErrorSummary.prototype.getAssociatedLegendOrLabel = function ($input) {
var legends = $fieldset.getElementsByTagName('legend');
if (legends.length) {
- return legends[0]
+ var $candidateLegend = legends[0];
+
+ // If the input type is radio or checkbox, always use the legend if there
+ // is one.
+ if ($input.type === 'checkbox' || $input.type === 'radio') {
+ return $candidateLegend
+ }
+
+ // For other input types, only scroll to the fieldset’s legend (instead of
+ // the label associated with the input) if the input would end up in the
+ // top half of the screen.
+ //
+ // This should avoid situations where the input either ends up off the
+ // screen, or obscured by a software keyboard.
+ var legendTop = $candidateLegend.getBoundingClientRect().top;
+ var inputRect = $input.getBoundingClientRect();
+
+ // If the browser doesn't support Element.getBoundingClientRect().height
+ // or window.innerHeight (like IE8), bail and just link to the label.
+ if (inputRect.height && window.innerHeight) {
+ var inputBottom = inputRect.top + inputRect.height;
+
+ if (inputBottom - legendTop < window.innerHeight / 2) {
+ return $candidateLegend
+ }
+ }
}
}
diff --git a/package/govuk/components/header/_header.scss b/package/govuk/components/header/_header.scss
index f5377e69ea..29bf93074a 100644
--- a/package/govuk/components/header/_header.scss
+++ b/package/govuk/components/header/_header.scss
@@ -42,6 +42,7 @@
}
.govuk-header__logotype {
+ display: inline-block;
margin-right: govuk-spacing(1);
}
diff --git a/package/govuk/components/header/template.njk b/package/govuk/components/header/template.njk
index ff78b6c91a..c9e999aa6d 100644
--- a/package/govuk/components/header/template.njk
+++ b/package/govuk/components/header/template.njk
@@ -60,7 +60,7 @@