You probably don’t need input type=“number”
bradfrost.com
bradfrost.com
I like the article, and have enjoyed everything I've read that Brad Frost has written, but I will probably keep using <input type="number">. I hope somehow this gets back to browser and desktop environment makers and they fix this usability and accessibility issue.
https://html.spec.whatwg.org/multipage/interaction.html#inpu...
It'll work in Chrome (and other Blink-based browsers), but nothing else.
What's interesting is it used to be partially supported in Firefox, and has now been put behind about:config [0]. I'm curious as to why, since the MDN docs seems to endorse its use. [1]
[0] https://caniuse.com/#search=inputmode
[1] https://developer.mozilla.org/en-US/docs/Web/HTML/Global_att...
Then it isn't the right choice.
1: https://caniuse.com/#search=inputmode
2: https://en.wikipedia.org/wiki/IOS (Latest preview in the infobox)
https://www.w3.org/TR/html5/forms.html#number-state-(type=nu...
>The type=number state is not appropriate for input that happens to only consist of numbers but isn’t strictly speaking a number. For example, it would be inappropriate for credit card numbers or US postal codes. A simple way of determining whether to use type=number is to consider whether it would make sense for the input control to have a spinbox interface (e.g., with "up" and "down" arrows). Getting a credit card number wrong by 1 in the last digit isn’t a minor mistake, it’s as wrong as getting every digit incorrect. So it would not make sense for the user to select a credit card number using "up" and "down" buttons. When a spinbox interface is not appropriate, type=text is probably the right choice (possibly with a pattern attribute).
I agree with another commenter that it would be better if it were called magnitude. Still, even when it's the correct thing to do I still think it's a bad feature because it can be accidentally triggered.
There's a gotcha in Safari when using pattern for zipcodes or anything that can have a leading 0: https://www.filamentgroup.com/lab/type-number.html#support-l...
Edit: kibibu below says it's the "inputmode" attribute, but it only works in Chrome currently. :(
https://html.spec.whatwg.org/multipage/interaction.html#inpu...
A spinbox only makes sense if you don't care what the value is, such that any two nearby values are exactly equivalent. And that is what the W3 guidance you quote says:
> Getting a credit card number wrong by 1 in the last digit isn’t a minor mistake, it’s as wrong as getting every digit incorrect. [And that's why a card number field should not use a spinbox.]
This suggests to me that the real problem is the idea that "type=numeric" means you want a spinbox. You don't ever want a spinbox; there's no reason for any attribute to give you one. But you frequently do want to restrict the input to numeric characters.
Mouse-adjustable low-resolution analog values have their own widget, the scrollbar. If you somehow find yourself wishing for a spinbox, use one of those.
Basically, if "close-ish" is acceptable, then a numeric input makes a ton of sense. And that's the case for lots of things, and most of those things wouldn't be entered with a keyboard (unless you want to get the figure in the ballpark).
If the number is <10 or so most of the time, then a menu makes a ton of sense (number of socks), and include a "custom" option so users can enter their own numbers. I do this with all kinds of things that only need a ballpark number but don't benefit from tweaking (e.g. seconds in an internal; basically, if 10 options or so makes sense, just make it a menu).
I happen to work with graphical things that don't need to be precise much of the time but need more precision that a set of presets. But most retail and whatnot apps are not that.
I agree with that, but this is an attribute of a text entry field. Like I said, we already have a different widget that accommodates the "I don't care what the value is, but I want to be able to easily fudge it upwards or downwards" use case.
Also, input does not necessarily mean text entry. We have <input type=“checkbox”/> and <input type=“button”/> among others.
Some people do like spin boxes, and they allow you to adjust numeric values without reaching for the digit row on your keyboard. By all means, don’t use them if you don’t like them, but they do exist for a reason.
Whether spinboxes are good UI is a separate debate.
If I'm not mistaken, using type="pattern" also means I can't use min or max.
Yes, you can work around all of these issues by overriding default number behaviour. But some things that look like numbers are really just strings of digits.
The fact that databases use auto-incrementing integers to ensure uniqueness is an implementation detail, and not a strictly necessary one (think UUIDs).
So just because something looks like a number doesn't mean that you can do 'safe' things like add leading zeros.
That looks like a framework-specific issue and if that’s how you process incoming numbers from the Internet, you are clearly doing something wrong.
Anyone on the Internet will reasonably expect that a decimal number provided to a Internet input-field will be interpreted as a decimal number.
Anything else, unless explicitly stated, is by definition an error on the part of the application developer.
An iPad allows spaces and dashes to be typed in, but input.value returns a value of "". Silent failure...
If they were numbers, then adding 2 SSNs would have some valid meaning. In reality, adding 2 SSNs is an entirely useless operation.
What they are is basically identifiers who happen to restrict the set of allowable characters to digits.
One consequence of using input type number on a 2 factor verification code box that I have seen is that the browser would eliminate the leading 0. Which is absolutely the correct behavior if the code was indeed a number, but leads to incorrect behavior since it’s not.
I learnt this the hard way while trying to get my text input fields to show the correct numeric keyboard on this site: https://percentagecalculatortools.com -- I eventually had to switch back to number inputs. I couldn't find any other solution that worked.
Above all, Google Maps repurposing it for zoom. Like, I'm scrolling down a webpage, there's an embedded Google Map, and suddenly it stops scrolling and starts zooming in by orders of magnitude and it's just a WTF moment... you're breaking the web. Nobody wants to zoom by orders of magnitude like that. Nobody asked you to stop scrolling the page. It's beyond useless.
Likewise, this is doing the same for numbers, at least in Safari. Again, nobody wants that. I can't think of any good reason ever to have that as a "feature". I can't even imagine what goes through the minds of people who think that's a good idea. Worst. Design. Decision. Ever.
However, it still doesn't change the fact that, on my Mac, on Google Maps proper I want to use scroll wheel or two-finger swipe equivalent to pan/scroll up-down or side-to-side like virtually every other app does, instead of zooming like virtually no other app does.
Having the scroll wheel move in y with no scroll to move in x just seems...weird.
Before that, you had to buy a book every year to keep in a glove compartment and look up street names in an alphabetical index, then go to a page number, look for a row and column and then plot a route by flipping between many pages or having traveled there before (aka getting lost) https://images.app.goo.gl/SdS9Z1rfs3HPJJwA9
Also a Google Maps innovation—trying to accurately put street numbers on a map. You’d often know, in some books, where street numbers began and ended at intersections, but it was extra detail and was often left out or entirely wrong. Of course it’s still wrong today, but street view really changed all that.
This alone convinced my father that it was worth having Internet access at home.
http://streetmap.co.uk/map.srf?x=531500&y=181500&z=120&sv=Lo...
Shift+scroll works as horizontal scroll in just about every place I've had reason to try it. (Outside of browsers, at least, though there I'm uncertain because everyone puts so much effort into eliminating any horizontal scroll)
Scroll wheels are still a thing in 2019 ? I can scroll in any direction using either the trackpad or a Magic Mouse in pretty much every app and website except Google Maps.
If they do choose to go with a modifier, I hope it's not control, because I hate accidentally zooming the page with the browser's zoom since it breaks nearly every page out there.
A static map may be underwhelming for the tech people but it is better. No need to load the Google plugin so +3s page load, so better search. Plus, if someone wants the map the link around the image can take them to Google Maps and they can then type in directions, see your reviews and bring actual business your way.
Cutting down the bloat helps, sometimes simpler is better.
At the moment I have a project where I am trimming the maps out of the footer of the home page.
The static maps I am putting in place have been saved with srcset images so the pin is in the middle with mobile and off to one side with desktop. mod_pagespeed does the image resizing so that the images a customer sees are always bandwidth friendly. Why have 3s of download (or more) when you can have a 12k image come down the same http2 connection?
- a static image
- a table of addresses with an external map link
It's not just the idea of wheeling around in some 256x256 box added at the last minute to a Contact Us page, the entire concept of an embeddable map is shit
Their main purpose seems to be to add 1 second to page loads across the web, and feed more clickstream back to the mothership
The main exception to this I can think of right now is Flightaware, but even that does not require such detailed rendering
At work we have a lot of embedded Google Maps and any content below the map was rarely viewed. Once we disabled auto focus, we saw more and people scrolling to content below the embedded map. Suggesting that people got confused by it and simply left the page. For us, it was the right thing to do.
I reported this at https://bugs.kde.org/show_bug.cgi?id=399324, and several Reddit posts have complained about the same thing.
This issue may also apply to GTK.
I'll admit, I prefer something like CTRL+<scroll> or something to trigger it as an alternative behavior, but that's a minor qualm, really.
Maybe you have a small imagination? :)
I use the scroll-to-change-number-input feature quite a lot, for one. Since you have your mouse already in hand, it's faster and more comfortable than switching to keyboard/numpad for quick adjustments or inputting small values; and definitely better than clicking the tiny arrow (does anybody use these anymore?) 32 times or clicking and holding.
> input type="number" is fine. Please don't stop using it.
Agreed
> The problem here is a bad input device
Part of the problem is the input device, but, as is stated around here, a "Social Security Number" is NOT a number. A number is an object that we can reasonably expect +-*/ operations on, within the context of mathematical feasibility (i.e., yes, there are some issues with division under the integer set).
I saw stated elsewhere something like, a Social Security Number is an identifier which happens to be limited to [0-9]. It should be treated as such -- an input field with a limitation on valid characters. Same with a phone number or a membership ID. No matter how sensitive the input wheel, you should not use input type="number" for a non-number, no matter how much it really, really looks like a number.
Those are not numbers. Those are opaque identifiers which just happen to take a form of a number. My DBA teacher always said: If you don't need to calculate it, then don't process and store it as a number. This applies to phone numbers as well.
Sounds like your problem is your "magic" mouse.
<input type="number">
element in it.[for the pedants/purists: yes, there is a chance that your mistake will just happen to hit the same checksum]
https://en.wikipedia.org/wiki/International_Bank_Account_Num...
inputmode is supposed to work in Mobile Safari on iOS 12.2
type=number acts differently between iPhone and iPad. And on an IPad if you type in anything that isn't a number, it silently fails (value=="").
type=tel works ok, but at some point will have a popup to select from contacts or autofill.
Data input is essentially broken on browsers from anything more complex than a text field.
Sorry, it's silly to propose features which work only on iOS. Standards-wise, I am not even sure if browsers should be parsing regex to accomplish this goal.
Input type=number can just be about what keypad to show, and shed the up-down arrows for increment/decrement. That's a valid complaint.
The pattern trick article basically explains the exact opposite of what the "you don't need input type number" article says but is cited for something it does not say at all.
This seems surprisingly insightful for a non-programmer! Either OP is a good explainer, or the support person is one the bank should hold on to.
Now that I'm using React, I try to use the best type for the UX since I have to do it manually anyway, but with Angular it was sometimes easier to use the slightly worse UX.
By the way I found typing hero on android just for this. It's a fantastic app for entering numbers and expanding short cuts on android!
type=tel [1] seems a lot more suited for this.
[1] https://developer.mozilla.org/en-US/docs/Web/HTML/Element/in...