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

Add inputmode to a note on type="number" #5271

Merged

Conversation

hannalaakso
Copy link
Contributor

@hannalaakso hannalaakso commented Feb 11, 2020

This adds inputmode to a note on type=”number”. It also makes a stronger recommendation to use inputmode and pattern when type=”number” is not appropriate.

What problem does this solve?

The current guidance advises to use type=”text” with pattern when type=”number” is not appropriate. However, this solution does not bring up the numeric keypad on mobile devices, apart from iOS where the number keypad is shown with pattern="[0-9]*".

We can improve the guidance by including inputmode which has good cross browser support for showing the numeric keypad on mobile, including more recent versions of iOS.

Making the guidance more clearly worded (removing “probably” and “possibly”) makes this recommendation to use inputmode and pattern clearer.

Further detail

inputmode is the semantically correct way of setting the input mode when type="number" is not appropriate. pattern is useful for iOS backwards compatibility for showing the number keypad on mobile.

There are various problems with using type=”number” when it’s not appropriate. Our team (the GOV.UK Design System team) have investigated this: alphagov/govuk-frontend#1704.

Government Digital Service (GDS) has signed the Participation Agreement.


/acknowledgements.html ( diff )
/input.html ( diff )

@domenic
Copy link
Member

domenic commented Feb 11, 2020

Thanks for this contribution! However, I'm having a hard time understanding the connection between the extensive discussion in your post, and the actual diff here.

What I'm getting from your post, is that you want to add a cross-reference to inputmode. So, maybe the patch should just do that? I.e. instead of the other changes to sentence structure, just change "possibly with a pattern attribute" to "possibly with pattern or inputmode attributes".

@hannalaakso
Copy link
Contributor Author

@domenic Thanks for your response - sorry if the explanation wasn’t clear.

Yes, you’re right, we’re essentially adding a cross-reference to inputmode. But we’ve also tweaked the sentence structure to deliberately avoid using ‘possibly’ or ‘probably’ - this is because inputmode has good cross browser support and is semantically correct so authors should be encouraged to use it.

pattern is a workaround, at best, and the original wording reflects that by being ambiguous and not making a direct recommendation. But as inputmode is now the correct thing to use the wording should make that clearer.

@domenic
Copy link
Member

domenic commented Feb 13, 2020

I don't really agrees with your interpretation of how the word "possibly" is being used, or your characterization of pattern as a workaround. Pattern is a useful way to constrain the contents in cases like this. And both pattern and inputmode are not always appropriate, so "possibly" makes sense; it has nothing to do with cross-browser support.

I think it would be best to retain the original sentence structure and just insert the inputmode reference.

@hannalaakso
Copy link
Contributor Author

hannalaakso commented Feb 18, 2020

Our thinking on this is possibly too focused on bringing up the correct keypad. We can see how pattern could be useful for constraining content in some scenarios (even if we generally prefer to handle this on the server).

However, it seems that inputmode should always be used in the scenario that the guidance describes? Can you think of a use case where you wouldn't want to use inputmode with type="text" if the content is only numbers?

Perhaps we could go with your suggestion to retain the original sentence structure but insert inputmode earlier in the sentence?

type="text" with an inputmode attribute is probably the right choice (possibly with a pattern attribute).

@hannalaakso
Copy link
Contributor Author

@domenic Do you have any thoughts on the above?

@domenic
Copy link
Member

domenic commented Mar 9, 2020

I think my earlier thoughts still stand. I haven't had time to work through the cases you asked about in your second paragraph, but I think the easiest route to resolution remains to retain the original sentence structure and just insert the inputmode reference. We could open a follow-up issue to discuss further tweaks if you really feel strongly.

@hannalaakso hannalaakso force-pushed the add-inputmode-to-type-number-guidance branch from c7913fc to 7634740 Compare May 26, 2020 09:16
@hannalaakso hannalaakso force-pushed the add-inputmode-to-type-number-guidance branch from 7634740 to 64609ea Compare June 3, 2020 16:18
@hannalaakso
Copy link
Contributor Author

@domenic In order to move this forward I've changed the wording to the one you suggested. I will raise a separate issue to improve the guidance further.

Please let me know if there's anything else that needs to be done before this PR can be accepted.

source Show resolved Hide resolved
Improve the guidance by mentioning `inputmode` (alongside `pattern`) as
it now has good cross browser support for showing the numeric keypad on
mobile.

A follow up issue will be raised to improve the wording to make a clearer
recommendation to use `inputmode`.

Include names of contributors under Acknowledgements.

Co-authored-by: Hanna Laakso <hanna.laakso@digital.cabinet-office.gov.uk>
Co-authored-by: Mark Green <mark.green@digital.cabinet-office.gov.uk>
@hannalaakso hannalaakso force-pushed the add-inputmode-to-type-number-guidance branch from 64609ea to 57dff34 Compare June 10, 2020 09:20
Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@domenic domenic merged commit e915da4 into whatwg:master Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants