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.


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

查看所有标签

猜你喜欢:

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

高效团队开发

高效团队开发

[日] 池田尚史、[日] 藤仓和明、[日] 井上史彰 / 严圣逸 / 人民邮电出版社 / 2015-7 / 49.00

本书以团队开发中所必需的工具的导入方法和使用方法为核心,对团队开发的整体结构进行概括性的说明。内容涉及团队开发中发生的问题、版本管理系统、缺陷管理系统、持续集成、持续交付以及回归测试,并且对“为什么用那个工具”“为什么要这样使用”等开发现场常有的问题进行举例说明。 本书适合初次接手开发团队的项目经理,计划开始新项目的项目经理、Scrum Master,以及现有项目中返工、延期问题频发的开发人......一起来看看 《高效团队开发》 这本书的介绍吧!

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

在线压缩/解压 HTML 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换