TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why the Gov.uk Design System team changed the input type for numbers

556 pointsby joelanmanabout 5 years ago

20 comments

ChrisSDabout 5 years ago
In summary the main issue is that, according to the spec, `&lt;input type=&quot;number&quot;&gt;` is only for numbers that are going to be parsed into a Javascript number. It has to make sense to increment, decrement or do other numerical operations on it. It&#x27;s not to be used for strings or identifiers that just so happen to be numbers, e.g. credit card numbers. I&#x27;ll admit this is slightly surprising to me but it does make a certain amount of sense.<p>The solution is to use `&lt;input type=”text” inputmode=”numeric” pattern=&quot;[0-9]*&quot;&gt;`.
评论 #22435959 未加载
评论 #22436030 未加载
评论 #22438278 未加载
评论 #22435309 未加载
评论 #22436467 未加载
评论 #22441894 未加载
评论 #22437316 未加载
评论 #22435900 未加载
signalsmithabout 5 years ago
This is off-topic, but I <i>really</i> like the current GOV.UK (several years old now). I don&#x27;t really have opinions on the visual stuff, but I find it really pleasant to use.<p>Filing my self-assessment tax return (only required because I run a side-business) is a fantastically straightforward experience. Step-by-step information entry, pre-filled with what they already know (e.g. main employer&#x27;s salary), then they give you a number at the end which you pay by card.<p>Having done the paper version exactly once before moving over to doing them online, I feel grateful every time I see that distinctive custom font.
评论 #22435913 未加载
评论 #22436563 未加载
vitaliyfabout 5 years ago
Similarly, here is your reminder than US Zip Codes aren&#x27;t numbers, because many of us here in the Northeast have them start with a zero (or even two). So don&#x27;t store them as integers, because Boston is 02108, not 2108.<p>See <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;List_of_ZIP_Code_prefixes" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;List_of_ZIP_Code_prefixes</a>
评论 #22436801 未加载
评论 #22436070 未加载
alexrageabout 5 years ago
It&#x27;s good to see UX design problems analyzed from a technical perspective. Designers working on the web should be proficient at understanding the medium on which they work, and look beyond generating static images to toss over the wall for implementation.
shaknaabout 5 years ago
&gt; However the inputmode attribute is now supported by all the mobile browsers we test in.<p>This isn&#x27;t extensive, which might be a tad misleading if you don&#x27;t double check. They test on Chrome &amp; Samsung for Android, and iOS is only the one engine.<p>And those three browsers seem to be the only mobile browsers that have implemented it. (Well, Opera Mobile as well). [0]<p>Desktop support is also extremely spotty.<p>This seems like it might be leaping the gun on expecting this standard to pick up the slack.<p>Whilst they might feel the support is there for their particular audience after 2019, I wouldn&#x27;t, and would suggest that you need to check your particular audience closely before following this advice for your own site. (Which is fairly generic advice, but appropriate.)<p>[0] <a href="https:&#x2F;&#x2F;caniuse.com&#x2F;#feat=input-inputmode" rel="nofollow">https:&#x2F;&#x2F;caniuse.com&#x2F;#feat=input-inputmode</a>
评论 #22435245 未加载
评论 #22435302 未加载
评论 #22435394 未加载
评论 #22435860 未加载
评论 #22442334 未加载
评论 #22436605 未加载
评论 #22436291 未加载
评论 #22435431 未加载
globular-toastabout 5 years ago
Using &quot;numeric&quot; types for strings that look like base 10 numbers is an incredibly common mistake. It&#x27;s one of those mistakes that works 99% of the time, which means it can become deeply embedded in architectures. We&#x27;ve recently seen this problem when a database for the first time for a non-numeric system in its ids and downstream systems that converted that to an integer started to fail.<p>My rule of thumb is that if it doesn&#x27;t make sense to do arithmetic on it then it&#x27;s not a number, it&#x27;s probably a string.
评论 #22436347 未加载
评论 #22437507 未加载
aglionbyabout 5 years ago
The Government Digital Service does all kinds of cool work around accessibility for both users using assistive technology and users who are less technically able. Interesting talk here from 2014 <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=CUkMCQR4TpY" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=CUkMCQR4TpY</a>
maxcbcabout 5 years ago
This is the sort of thing I love about the accessible tech team at gds. They learn something, then they share it in such an accessible way.
gatvolabout 5 years ago
Quite strange that propriety systems like dragon are mentioned as motivation, surely they should fix the product or standardise.
评论 #22436588 未加载
rini17about 5 years ago
This is another reminder that floating point numbers are just a hack that should never be used by default. We have enough CPU, memory and bandwidth that we are able to transmit&#x2F;store exact representation of numeric user input, and convert it to float only when necessary, as designed by programmer.
评论 #22436437 未加载
评论 #22441497 未加载
TazeTSchnitzelabout 5 years ago
&lt;input type=number&gt; for things that are like telephone numbers and not like quantities is such a common mistake. It can be hilarious when, for example, a login form uses such a field for a Swedish personal identity number. I just need to click the up arrow ~1.996×10¹¹ times!
OisinMoranabout 5 years ago
Really interesting article, and as with everyone else I also really admire their commitment to accessible design.<p>One interesting this I noticed in this piece was the text (not quoted for reasons that will soon become clear):<p>Using &lt;input type=”text” inputmode=”numeric” pattern=&quot;[0-9]*&quot;&gt; allows for a degree of separation between how the user enters data (“input mode”), what the browser expects the user input to contain (type equals number), and potentially how it tries to validate it.<p>Which has incorrectly used closing quotes and correctly used straight quotes in the same code section, and then proper opening and closing quotes in the text section. I wonder how that happened.
mirekrusinabout 5 years ago
Gov UK has some great, Jakob Nielsen style UI. It’s fantastic to use, love it.
nimishabout 5 years ago
Javascript not having proper integers strikes again! Kind of surprised they hadn&#x27;t run into more issues parsing string-ids-with-numerals into numbers.
评论 #22437203 未加载
Fejabout 5 years ago
Does anyone know what&#x27;s going on with the Firefox implementation of inputmode, especially for Android? There isn&#x27;t much on Bugzilla about it.
calibasabout 5 years ago
FYI, there&#x27;s a few features available with the number input type that don&#x27;t work with this method. Things like min, max and step attributes.
评论 #22442605 未加载
评论 #22439170 未加载
BurningFrogabout 5 years ago
This number type is fine. It serves a purpose.<p>The real problem is that there is no type for other &quot;numeric&quot; cases.
ArchReaperabout 5 years ago
EDIT: removed my inaccurate comment, misread article
评论 #22437291 未加载
throwaway-q2233about 5 years ago
Better option is graceful degradation, just Target those specific problematic UAs for the other input type.
评论 #22435098 未加载
评论 #22435369 未加载
klingonoperaabout 5 years ago
I&#x27;m no web-dev, but shouldn&#x27;t these things be sanitized server-side? In which case, except for the mobile keypad issue, all these problems would solve themselves?<p>And shouldn&#x27;t they be doing this anyway?
评论 #22435712 未加载
评论 #22435775 未加载
评论 #22435724 未加载
评论 #22435677 未加载