Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate alternative to [type=number] for the date input component #1449

Closed
NickColley opened this issue Jun 12, 2019 · 12 comments
Closed

Comments

@NickColley
Copy link
Contributor

We are aware of two issues with assistive technologies and their compatibility with [type=number]

We should investigate an alternative to this as we're aware of general issues with [type=number].

@hannalaakso has done a lot of investigation into this.

@hannalaakso
Copy link
Member

hannalaakso commented Jun 18, 2019

If collecting dates as numbers, one problem with type="number" is that it has native input validation in Chrome (desktop and Android) which prevents the typing of non-numeric values. This is not a bug but an implementation of the HTML spec. Unfortunately the user experience is poor when it comes to handling errors. We recommend the use of clear error messages, whereas there is no information given to user about what they’ve done wrong if they attempt to type the month as a number, for example.

type="number" also allows the user to increment numbers by pressing the up/down arrows. This could improve usability for some users (as long as the number should be incrementable - dates generally are) but also introduces the risk of some users accidentally incrementing a number using the arrow keys when trying to navigate a form. The incrementing behaviour can be disabled using Javascript but we prefer to avoid scripting solutions if possible.

There are other issues with type="number" that concern long numeric values being validated by browsers and making sure that users can enter "-" and "," signs; but these aren’t a concern for dates.

Alternative solution (we should test this across the board) is to use inputmode="numeric" combined with pattern:

<input type="text" pattern="[0-9]*" id="sometext" name="sometext" inputmode="numeric">

There is also type="tel" which has no browser validation, and brings up a numeric keypad on all mobile devices (the input should set autocomplete=off to stop the browser trying to complete it from the user’s address book). It's often used by payment providers to collect credit card numbers. However on Android devices the keyboard includes additional buttons for "Pause" and "Wait" which could be confusing for some users. Additionally, there is the (admittedly quite slim) possibility that browser vendors might in the future add validation to type="tel", for which reason if it was used on a service, there should be a team available to monitor the behaviour.

@NickColley
Copy link
Contributor Author

Just a note on the pattern attribute suggested, if someone has HTML5 validation enabled (something we do not recommend), it will show a message and stop the form from being submitted:

Screen Shot 2019-06-18 at 16 51 28

@36degrees
Copy link
Contributor

We are already using the pattern attribute for the date input so that wouldn't be a change?

Possibly another reason to move away from it though.

@36degrees
Copy link
Contributor

36degrees commented Jun 20, 2019

To summarise what we know so far:

At the minute for the date input component the individual inputs look like this:

<input […] type="number" pattern="[0-9]*">

We set the input type to type="number" so that Android browsers display a numeric keypad keyboard when the input is focussed.

iOS uses the full alphanumeric keyboard for type="number", so we add pattern="[0-9]*" which triggers the numeric keypad there too. This is technically invalid HTML, as the pattern attribute only applies to inputs of type text, search, url, tel and email, but is not known to cause any real-world issues.

However, there are a number of known issues with inputs of type="number":

(Bugs have been filed where appropriate)

In testing, using <input […] type="text" inputmode="numeric" pattern="[0-9]*"> mitigates these issues, with some minor drawbacks:

  • In iOS 12.2 and above, the numeric keypad with punctuation is displayed instead of the numeric keypad, but this looks like it has been changed in Webkit so this should hopefully change in a future iOS release (versions prior to 12.2 do not support inputmode, thus fallback to the pattern attribute, and continue to show the full numeric keypad.)
  • Firefox, UC Browser (and older versions of other browsers) on android support neither inputmode nor pattern, and so will use the full alphanumeric keypad until those browsers introduce support for inputmode. (Note: neither Firefox nor UC browser on Android are listed in our own browser support matrix nor the service manual)

We think that <input […] type="text" inputmode="numeric" pattern="[0-9]*"> is semantically correct and provides a better experience and so we should:

  • update the input component to accept an inputmode
  • update the date input component to use <input […] type="text" inputmode="numeric" pattern="[0-9]*">
  • add guidance to the Design System to help users understand how to ask for different types of numbers
  • publish a blog post explaining the change and why we're making it
  • consider removing the pattern attribute once traffic from iOS < 12.2+ drops off

@36degrees
Copy link
Contributor

Once we've done the above, we can also close alphagov/govuk-design-system#782

jonheslop added a commit to alphagov/pay-frontend that referenced this issue Jun 25, 2019
The Design System team have done some accessibility testing on `input
type="number"` and deemed them problematic. They have suggested using

`input type="text" inputmode="numeric" pattern="[0-9]*"`

instead as documented here alphagov/govuk-frontend#1449
jonheslop added a commit to alphagov/pay-products-ui that referenced this issue Jun 25, 2019
The Design System team have done some accessibility testing on `input
type="number"` and deemed them problematic. They have suggested using

`input type="text" inputmode="numeric" pattern="[0-9]*"`

instead as documented here alphagov/govuk-frontend#1449
jonheslop added a commit to alphagov/pay-selfservice that referenced this issue Jun 25, 2019
The Design System team have done some accessibility testing on `input
type="number"` and deemed them problematic. They have suggested using

`input type="text" inputmode="numeric" pattern="[0-9]*"`

instead as documented here alphagov/govuk-frontend#1449
jonheslop added a commit to alphagov/pay-selfservice that referenced this issue Jun 25, 2019
The Design System team have done some accessibility testing on `input
type="number"` and deemed them problematic. They have suggested using

`input type="text" inputmode="numeric" pattern="[0-9]*"`

instead as documented here alphagov/govuk-frontend#1449
jonheslop added a commit to alphagov/pay-products-ui that referenced this issue Jun 25, 2019
The Design System team have done some accessibility testing on `input
type="number"` and deemed them problematic. They have suggested using

`input type="text" inputmode="numeric" pattern="[0-9]*"`

instead as documented here alphagov/govuk-frontend#1449
jonheslop added a commit to alphagov/pay-selfservice that referenced this issue Jun 25, 2019
The Design System team have done some accessibility testing on `input
type="number"` and deemed them problematic. They have suggested using

`input type="text" inputmode="numeric" pattern="[0-9]*"`

instead as documented here alphagov/govuk-frontend#1449
jonheslop added a commit to alphagov/pay-selfservice that referenced this issue Jun 26, 2019
The Design System team have done some accessibility testing on `input
type="number"` and deemed them problematic. They have suggested using

`input type="text" inputmode="numeric" pattern="[0-9]*"`

instead as documented here alphagov/govuk-frontend#1449
jonheslop added a commit to alphagov/pay-products-ui that referenced this issue Jun 26, 2019
The Design System team have done some accessibility testing on `input
type="number"` and deemed them problematic. They have suggested using

`input type="text" inputmode="numeric" pattern="[0-9]*"`

instead as documented here alphagov/govuk-frontend#1449
jonheslop added a commit to alphagov/pay-selfservice that referenced this issue Jun 26, 2019
The Design System team have done some accessibility testing on `input
type="number"` and deemed them problematic. They have suggested using

`input type="text" inputmode="numeric" pattern="[0-9]*"`

instead as documented here alphagov/govuk-frontend#1449

But because `pattern="[0-9]"` causes some browsers to use native error
popups which suppress our better error handling we’re going to just add
`inputmode="numeric"`
peteryates added a commit to x-govuk/govuk-form-builder that referenced this issue Jul 4, 2019
This bug[0] highlights several usability problems with using
`type='number'` on the date segment inputs. This change addresses these
problems at the expense of removing some client-side validation.

[0] alphagov/govuk-frontend#1449
zheileman added a commit to ministryofjustice/gov_uk_date_fields that referenced this issue Aug 28, 2019
Following report of issues with assistive technologies and compatibility with input `type="number"` [0], this PR will make the recommended changes and convert these input to be of `type="text"` instead, also adding the extra attribute `inputmode="numeric"`.

Although this is a very minor change, the version of the gem has been bumped to 4.1.0 as it might be a breaking change for some code, previously relying on the type number.

[0] alphagov/govuk-frontend#1449
zheileman added a commit to ministryofjustice/disclosure-checker that referenced this issue Aug 28, 2019
The recommended way to use the numeric inputs is to be of type `text` but with pattern and inputmode attributes.

The dates gem has been updated to produce this new markup [0] following the reports of issues with previous markup [1].

Also updated the `conviction_length` step to produce an input of type `text`, instead of number, and add the `inputmode` attribute.

[0] https://github.com/ministryofjustice/gov_uk_date_fields/releases/tag/v4.1.0
[1] alphagov/govuk-frontend#1449
zheileman added a commit to ministryofjustice/disclosure-checker that referenced this issue Aug 28, 2019
The recommended way to use the numeric inputs is to be of type `text` but with pattern and inputmode attributes.

The dates gem has been updated to produce this new markup [0] following the reports of issues with previous markup [1].

Also updated the `conviction_length` step to produce an input of type `text`, instead of number, and add the `inputmode` attribute.

[0] https://github.com/ministryofjustice/gov_uk_date_fields/releases/tag/v4.1.0
[1] alphagov/govuk-frontend#1449
@36degrees
Copy link
Contributor

  • In iOS 12.2 and above, the numeric keypad with punctuation is displayed instead of the numeric keypad, but this looks like it has been changed in Webkit so this should hopefully change in a future iOS release (versions prior to 12.2 do not support inputmode, thus fallback to the pattern attribute, and continue to show the full numeric keypad.)

Just to confirm that iOS 13 now shows the numeric keypad.

hannalaakso added a commit to adamsilver/govuk-design-system that referenced this issue Oct 17, 2019
We've done some investigation to show that now in certain
scenarios this is the best way of collecting numeric data from users. We have a
bunch of changes to make to roll this out in GOV.UK Frontend:
alphagov/govuk-frontend#1449 (comment)
After that, we can set this in the input component itself instead of using the
`attributes` object.

Following our above investigation, GOV.UK Pay introduced this change for
collecting credit card details:
alphagov/govuk-frontend#1449 They haven't seen
any issues so we are sufficiently confident to make the same change
in the Design System.

This is only applied to sort code and account number as the other data collected
is alphanumeric.

Tested on iOS 12 and 13, Android 9 and 8.
hannalaakso added a commit to adamsilver/govuk-design-system that referenced this issue Oct 17, 2019
We've done some investigation to show that now in certain
scenarios this is the best way of collecting numeric data from users. We have a
bunch of changes to make to roll this out in GOV.UK Frontend:
alphagov/govuk-frontend#1449 (comment)
After that, we can set this in the input component itself instead of using the
`attributes` object.

Following our above investigation, GOV.UK Pay introduced this change for
collecting credit card details:
alphagov/pay-frontend#921 They haven't seen
any issues so we are sufficiently confident to make the same change
in the Design System.

This is only applied to sort code and account number as the other data collected
is alphanumeric.

Tested on iOS 12 and 13, Android 9 and 8.
@kellylee-gds
Copy link
Contributor

@36degrees close this card and create new one with what we want to do

@36degrees
Copy link
Contributor

Closing this as I believe we've finished the investigation and now have cards representing these actions:

36degrees added a commit that referenced this issue Jan 20, 2020
Within the date input component the individual inputs look like this:

```
<input […] type="number" pattern="[0-9]*">
```

We set the input to `type="number"` so that Android browsers display a numeric keypad keyboard when the input is focussed.

iOS uses the full alphanumeric keyboard for `type="number"`, so we add `pattern="[0-9]*"` which triggers the numeric keypad there too [1]. This is technically invalid HTML, as the pattern attribute only applies to inputs of type `text`, `search`, `url`, `tel` and `email` [2], but is not known to cause any real-world issues.

However, there are a number of known issues with inputs of `type="number"`:

- they silently discard non-numeric input in Chrome [3] (except the letter 'e')
- users can accidentally increment or decrement the number using the arrow keys without realising [4]
- users can accidentally increment or decrement the number using the scroll wheel on the mouse or the scroll gesture on their trackpad [5]
- they appear as unlabeled in NVDA's element list [6]
- in NVDA's object navigation they are seen as a spin button which has an edit field and two buttons inside. Those buttons are unlabeled, but decrease/increase the value [7]
- when tabbing to the field NVDA using pressing nvda+tab they are reported as unlabeled edit fields [7]
- users of Dragon Naturally Speaking cannot dictate into them as expected [8]

(Bugs have been filed where appropriate)

In testing, using `<input […] type="text" inputmode="numeric" pattern="[0-9]*">` mitigates these issues, with some minor drawbacks:

- Between iOS 12.2 and 13.0, the numeric keypad with punctuation is displayed instead of the numeric keypad. Versions prior to 12.2 do not support `inputmode`, thus fallback to the `pattern` attribute, and continue to show the full numeric keypad. iOS 13 updates inputmode="numeric" to use the numeric keypad without punctuation.
- Firefox, UC Browser (and older versions of other browsers) on android support neither `inputmode` nor `pattern`, and so will use the full alphanumeric keypad until those browsers introduce support for `inputmode`. (Note: neither Firefox nor UC browser on Android are listed in our own browser support matrix [9] nor the service manual [10])

---

[1]: http://bradfrost.com/blog/post/better-numerical-inputs-for-mobile-forms/
[2]: https://html.spec.whatwg.org/multipage/input.html#input-type-attr-summary
[3]: #1449 (comment)
[4]: #1449 (comment)
[5]: http://bradfrost.com/blog/post/you-probably-dont-need-input-typenumber/
[6]: alphagov/reported-bugs#41
[7]: nvaccess/nvda#9675 (comment)
[8]: alphagov/reported-bugs#34
[9]: https://github.com/alphagov/govuk-frontend#browser-and-assistive-technology-support
[10]: https://www.gov.uk/service-manual/technology/designing-for-different-browsers-and-devices#browsers-to-test-in

Co-authored-by: Colin Oakley <colin@htmlandbacon.com>
36degrees added a commit that referenced this issue Jan 20, 2020
Within the date input component the individual inputs look like this:

```
<input […] type="number" pattern="[0-9]*">
```

We set the input to `type="number"` so that Android browsers display a numeric keypad keyboard when the input is focussed.

iOS uses the full alphanumeric keyboard for `type="number"`, so we add `pattern="[0-9]*"` which triggers the numeric keypad there too [1]. This is technically invalid HTML, as the pattern attribute only applies to inputs of type `text`, `search`, `url`, `tel` and `email` [2], but is not known to cause any real-world issues.

However, there are a number of known issues with inputs of `type="number"`:

- they silently discard non-numeric input in Chrome [3] (except the letter 'e')
- users can accidentally increment or decrement the number using the arrow keys without realising [4]
- users can accidentally increment or decrement the number using the scroll wheel on the mouse or the scroll gesture on their trackpad [5]
- they appear as unlabeled in NVDA's element list [6]
- in NVDA's object navigation they are seen as a spin button which has an edit field and two buttons inside. Those buttons are unlabeled, but decrease/increase the value [7]
- when tabbing to the field NVDA using pressing nvda+tab they are reported as unlabeled edit fields [7]
- users of Dragon Naturally Speaking cannot dictate into them as expected [8]

(Bugs have been filed where appropriate)

In testing, using `<input […] type="text" inputmode="numeric" pattern="[0-9]*">` mitigates these issues, with some minor drawbacks:

- Between iOS 12.2 and 13.0, the numeric keypad with punctuation is displayed instead of the numeric keypad. Versions prior to 12.2 do not support `inputmode`, thus fallback to the `pattern` attribute, and continue to show the full numeric keypad. iOS 13 updates inputmode="numeric" to use the numeric keypad without punctuation.
- Firefox, UC Browser (and older versions of other browsers) on android support neither `inputmode` nor `pattern`, and so will use the full alphanumeric keypad until those browsers introduce support for `inputmode`. (Note: neither Firefox nor UC browser on Android are listed in our own browser support matrix [9] nor the service manual [10])

---

[1]: http://bradfrost.com/blog/post/better-numerical-inputs-for-mobile-forms/
[2]: https://html.spec.whatwg.org/multipage/input.html#input-type-attr-summary
[3]: #1449 (comment)
[4]: #1449 (comment)
[5]: http://bradfrost.com/blog/post/you-probably-dont-need-input-typenumber/
[6]: alphagov/reported-bugs#41
[7]: nvaccess/nvda#9675 (comment)
[8]: alphagov/reported-bugs#34
[9]: https://github.com/alphagov/govuk-frontend#browser-and-assistive-technology-support
[10]: https://www.gov.uk/service-manual/technology/designing-for-different-browsers-and-devices#browsers-to-test-in

Co-authored-by: Colin Oakley <colin@htmlandbacon.com>
@tempertemper
Copy link

A bit late to this, but I was wondering why inputmode="numeric" was used instead of inputmode="decimal". It's the same keyboard either way on Android, but on iOS numeric uses the same keyboard as type="number" (with the numbers in a row and lots of punctuation options), but if we're only asking for a number, the number-pad style (a 3 x 4 grid with numbers 0 to 9) feels more appropriate. The touch targets are also much larger, which can only be a good thing.

@hannalaakso
Copy link
Member

Thanks for your comment @tempertemper. See #1449 (comment) - iOS 12.2, 12.3 and 12.4 display the keypad with punctuation that you describe but this was fixed in iOS 13 which displays the large numbered keypad with numeric. Are you on one of the above mentioned versions of iOS?

@tempertemper
Copy link

@hannalaakso I totally missed that one – I had been testing with iOS 12 so saw the other keyboard. Numeric is perfect 😄 I've attached a couple of screenshots (taken from @adamliptrot-oc's excellent test page) for posterity: the difference is that decimal has a decimal point and numeric doesn't. So numeric is the right choice as the . it's always going to be a whole number. Thanks for keeping me right 🙂

Decimal:
decimal

Numeric:
numeric

@hannalaakso
Copy link
Member

@tempertemper No worries at all, glad we got it figured out 🙂

kr8n3r added a commit to alphagov/paas-admin that referenced this issue Dec 16, 2021
There are some known issues with inputs of type="number". Read our research into the issues with type="number" alphagov/govuk-frontend#1449 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants