alphagov / govuk-frontend

GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.
https://frontend.design-system.service.gov.uk/
MIT License
1.18k stars 325 forks source link

Fix input value not being set if the value was '0' #4963

Closed patrickpatrickpatrick closed 6 months ago

patrickpatrickpatrick commented 6 months ago

What

Input component now uses the govukAttributes macro to validate and format attributes. Test and example added for edge-case outlined in issue https://github.com/alphagov/govuk-frontend/issues/4669.

Why

Issue https://github.com/alphagov/govuk-frontend/issues/4669 outlines a case where setting 'value' of the Input component to 0 (integer) would not set the value of the input component. This is because the template logic would see '0' as false-y and so not set the value attribute. The govukAttributes takes this case into account and so using it means that this no longer occurs.

This is based from https://github.com/alphagov/govuk-frontend/pull/4770. It adds tests and the input wrapper classes and attributes back.

github-actions[bot] commented 6 months ago

:clipboard: Stats

File sizes

File Size
dist/govuk-frontend-development.min.css 113.32 KiB
dist/govuk-frontend-development.min.js 42.21 KiB
packages/govuk-frontend/dist/govuk/all.bundle.js 87.21 KiB
packages/govuk-frontend/dist/govuk/all.bundle.mjs 81.95 KiB
packages/govuk-frontend/dist/govuk/all.mjs 4.17 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs 359 B
packages/govuk-frontend/dist/govuk/govuk-frontend.min.css 113.3 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend.min.js 42.2 KiB
packages/govuk-frontend/dist/govuk/i18n.mjs 5.55 KiB

Modules

File Size (bundled) Size (minified)
all.mjs 77.67 KiB 40.19 KiB
accordion.mjs 22.71 KiB 12.85 KiB
button.mjs 5.98 KiB 2.69 KiB
character-count.mjs 22.4 KiB 9.92 KiB
checkboxes.mjs 5.83 KiB 2.83 KiB
error-summary.mjs 7.89 KiB 3.46 KiB
exit-this-page.mjs 17.1 KiB 9.26 KiB
header.mjs 4.46 KiB 2.6 KiB
notification-banner.mjs 6.26 KiB 2.62 KiB
password-input.mjs 15.15 KiB 7.25 KiB
radios.mjs 4.83 KiB 2.38 KiB
skip-link.mjs 4.39 KiB 2.18 KiB
tabs.mjs 10.13 KiB 6.11 KiB

View stats and visualisations on the review app


Action run for 913b77176d327095f9bf4d860d1919898e115f2e

github-actions[bot] commented 6 months ago

Other changes to npm package

diff --git a/packages/govuk-frontend/dist/govuk/components/input/fixtures.json b/packages/govuk-frontend/dist/govuk/components/input/fixtures.json
index b30288cf5..5b5223d03 100644
--- a/packages/govuk-frontend/dist/govuk/components/input/fixtures.json
+++ b/packages/govuk-frontend/dist/govuk/components/input/fixtures.json
@@ -468,6 +468,21 @@
             "previewLayoutModifiers": [],
             "html": "<div class=\"govuk-form-group\">\n  <label class=\"govuk-label\" for=\"with-value\">\n    With value\n  </label>\n  <input class=\"govuk-input\" id=\"with-value\" name=\"with-value\" type=\"text\" value=\"QQ 12 34 56 C\">\n</div>"
         },
+        {
+            "name": "zero value",
+            "options": {
+                "id": "with-zero-value",
+                "name": "with-zero-value",
+                "label": {
+                    "text": "With zero value"
+                },
+                "value": 0
+            },
+            "hidden": true,
+            "description": "",
+            "previewLayoutModifiers": [],
+            "html": "<div class=\"govuk-form-group\">\n  <label class=\"govuk-label\" for=\"with-zero-value\">\n    With zero value\n  </label>\n  <input class=\"govuk-input\" id=\"with-zero-value\" name=\"with-zero-value\" type=\"text\" value=\"0\">\n</div>"
+        },
         {
             "name": "with describedBy",
             "options": {

Action run for 913b77176d327095f9bf4d860d1919898e115f2e