fix: align with guidance on input type for numbers (NumberField) #1298
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Bring the NumberField component inline with the GOV.UK design system guidance on how to ask for numbers.
Update the HTML attribute
type
from"number"
to"text"
which stops the browser from restricting which type of characters can be entered into the input - this restriction can be confusing for users, limit the ability to copy & paste and has proven problematic for screen readers.As the current NumberField component uses
joi.number()
as the base schema there will already be server side validation ensuring that if anything that can't be parsed byNumber()
is entered (text or invalid decimals) the user will be prompted to enter a number.Setting the
inputmode
attribute to "numeric" will still prompt mobile browsers to provide a keyboard specifically for numbers and decimals (note on the mobile browsers I've tried this change against the keyboard behaviour is currently identical to if thetype
attribute was set tonumber
).This change does still fallback to the
type
"number"
if theprecision
option is set on the components schema. Although I wouldn't advise this was used thestep
attribute which is set on the HTML input will not work if thetype
is set to"text"
. Adding custom server side validation to validate and clearly feedback on incorrect decimal precision seemed well out of the scope of this fix and this should allow existing configurations to work as-is. (Note from an early review it looks like setting theprecision
option doesn't actually appropriately set different granularities ofstep
but I'll look to raise that as a separate issue).This change aims to bring the NumberField inline with the guidance found here: https://design-system.service.gov.uk/components/text-input/#numbers
Specifically attempting to fix the issues described by: https://design-system.service.gov.uk/components/text-input/#avoid-using-inputs-with-a-type-of-number
A more detailed description of why the guidance was set was published in Feb 2020:
https://technology.blog.gov.uk/2020/02/24/why-the-gov-uk-design-system-team-changed-the-input-type-for-numbers/
Note that because the date part and date time part components use the
govuk-frontend
macrogovukDateInput
directly (by passingitems
into the macro options) those components are already asking for numbers using the appropriatetype
"text" andinputmode
"numeric".Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Although the form builder is used in my department this issue was identified during an internal demo between designers and developers. It was not flagged as an issue by end users.
This commit updates to try and align the code to the design system guidance but has not been tried in a real world scenario with users submitting data.
Checklist: