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

栏目: IT技术 · 发布时间: 5年前

内容简介:To provide users with a good service, government organisations usually need to collect data. Lots of data. The GOV.UK Design System team creates patterns and components that let users enter their data in an easy and accessible way. The last thing we want t

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

To provide users with a good service, government organisations usually need to collect data. Lots of data. The GOV.UK Design System team creates patterns and components that let users enter their data in an easy and accessible way. The last thing we want to do is create barriers to users completing a task and force them to find an alternative method of using the service, such as phoning a helpline. 

Numbers are one of the most commonly asked for pieces of data, typically used in dates. We know from user research that some users prefer the large buttoned number keyboard (resembling a telephone keypad) for entering numbers on mobile. Until now, the GOV.UK Design System date input component used the HTML element <input type=”number”> to provide this number keypad when a user enters dates.

Why the Gov.uk Design System team changed the input type for numbers
Large buttoned, easy to use number keypad on Android

However, we recently moved away from <input type=”number”> to <input type=”text” inputmode=”numeric” pattern="[0-9]*"> and published new guidance on how to ask users for numbers .

Why type=number is problematic

Although we have user research from 2017 that didn’t flag any major issues with <input type=”number”> , we identified many usability problems with this input type.

1. Accessibility

We found that <input type=”number”> :

2. Incrementable numbers

It's reasonable to assume that <input type=”number”> can be used for collecting any numeric data: it contains the word “number”, after all. A note in the HTML specification states that <input type=”number”> is “not appropriate for input that happens to only consist of numbers but isn't strictly speaking a number”.

This means that <input type=”number”> can only be used for incrementable numbers, such as dates or the number of people in a household. Using <input type=”number”> for collecting numbers that are not incrementable can cause problems with browsers validating them in that way.

For example, browsers attempt to round large numbers when incrementing or decrementing (pressing up or down key), and in the case of very large numbers they are converted to exponential notation.

Why the Gov.uk Design System team changed the input type for numbers
Chrome 79.0: type=number displays large numbers in exponential format if user presses the up or down arrows on their keyboard.

Once the number is parsed by the browser as an exponent, as shown above, and possibly by mistake, t he action cannot be reversed by the user. This could confuse users. 

If users access your site using older versions of Safari, <input type=”number”> can also be problematic when collecting values of 16 or more digits. In Safari 6, the browser rounds the number when a user leaves the field, so no mistake with up or down keys is required.

Why the Gov.uk Design System team changed the input type for numbers
Safari 6 rounds the last digit on blur

Safari 5.1 attempts to make values with at least 16 digits more readable by inserting commas.

Why the Gov.uk Design System team changed the input type for numbers
Safari 5.1 attempting a more human readable number on blur

3. Letters 

The HTML spec states that when using <input type=”number”> , “user agents must not allow the user to set the value to a non-empty string that is not a valid floating-point number”. The web and Android versions of Chrome implement this by silently discarding all letter input except the letter ‘e’.

This means users are not given feedback on what type of characters <input type=”number”> accepts, and assistive technologies don’t alert the user that their input has been silently discarded.

4. Scrolling 

Users can accidentally increase or decrease the number using the scroll wheel on the mouse or the scroll gesture on their trackpad. This feature can be useful when collecting countable data but bad if entering data such as passport numbers.

The solution

Using <input type=”text” inputmode=”numeric” pattern="[0-9]*"> 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. 

Prior to 2019 there wasn’t enough browser support, especially on mobile devices, for us to feel confident in rolling this out instead of using <input type=”number”> . However the inputmode attribute is now supported by all the mobile browsers we test in .

We still include the pattern attribute for backwards compatibility with older iOS devices .

We’ve now updated the date input component and the rest of the relevant patterns .

We’ve also published some guidance to help users to understand how to collect numbers in HTML forms.

Finally, we’ve proposed a change to the HTML spec guidance to cross reference inputmode when using <input type=”text”> with content that is only numbers

You can take a look at the GOV.UK Design System backlog to see what else we’re working on.


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

移动风暴

移动风暴

[美]弗雷德·沃格尔斯坦 / 朱邦芊 / 中信出版社 / 2014-1-1 / 39

也许,除了伟大的乔布斯,每一位奋力改变世界的硅谷英雄,都值得我们肃然起敬。苹果与谷歌十年博弈,关于这场移动平台战争的报道早已铺天盖地,而这是第一次,我们能听到幕后工程师的真实声音。两大科技巨人用智能手机和平板电脑颠覆了电脑产业。它们位处变革的中心,凭借各自的经营哲学、魅力领袖和商业敏感度,把竞争变成了残酷对决。商业记者沃格尔斯坦报道这场对抗已逾十载,在《移动风暴》中,他带领我们来到一间间办公室和会......一起来看看 《移动风暴》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具