govuk-frontend
Update date input to use `type=text` and `inputmode=numeric`
#1704
Merged

Update date input to use `type=text` and `inputmode=numeric` #1704

36degrees
36degrees5 years ago (edited 5 years ago)👍 3

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. 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" – many of which were found in research and documented by @hannalaakso :

(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 nor the service manual)

Closes #1700

NickColley
NickColley commented on 2020-01-20
Conversation is marked as resolved
Show resolved
src/govuk/components/date-input/template.test.js
153 expect($firstInput.attr('type')).toEqual('text')
154 })
155
156
it('renders inputs with inputmode="numric"', () => {
NickColley5 years ago
Suggested change
it('renders inputs with inputmode="numric"', () => {
it('renders inputs with inputmode="numeric"', () => {
NickColley
NickColley approved these changes on 2020-01-20
NickColley5 years ago

Great work, long time coming. Love the list of references that back this change.

36degrees Update date input to type=text, inputmode=numeric
cfabd7dc
36degrees Fix typo
bdf68ca7
36degrees Document in changelog
c4897c47
36degrees 36degrees force pushed from eb6857ad to c4897c47 5 years ago
36degrees 36degrees merged 39a35f03 into master 5 years ago
36degrees 36degrees deleted the date-input-type-text-inputmode-numeric branch 5 years ago
vanitabarrett vanitabarrett changed the title Update date input to type=text, inputmode=numeric Update date input to use `type=text` and `inputmode=numeric` 3 years ago

Login to write a write a comment.

Login via GitHub

Reviewers
Assignees
No one assigned
Labels
Milestone