alphagov / govuk-frontend

GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.
https://frontend.design-system.service.gov.uk/
MIT License
1.18k stars 323 forks source link

Voice Control inserts spaces in input fields #2085

Closed philsherry closed 2 years ago

philsherry commented 3 years ago

Issue: Voice Control inserts spaces in input fields. Platform: macOS 11.0.1 (20B29) Browser: Safari 14.0.1 (16610.2.11.51.8). (Only tested in the native browser, as other vendors will likely refuse to fix anyway.) Example page: Design System » Date input » Example Why: When the user inputs a value, Voice Control automatically inserts a leading space, leading to validation errors and a confused user. Suggest: Client-side trim of leading whitespace on blur() Example 1: Input of a date on the example page:

Insert the day with the keyboard as a baseline test: 11. Then switch to using Voice Control to enter the month and year.

“01” “Next field” “2021”

This actually tries to submit the following three values:

  1. "11"
  2. " 01"
  3. " 2021"

☝️ Note the leading spaces in the inputs where Voice Control was used. Visually, they’re barely noticeable, but these will cause validation issues and force the error state. Here’s a screenshot from Safari’s web inspector, showing those values.

Note the leading spaces in the inputs where Voice Control was used.

Example 2: Picking a country from the autocomplete:

France (No results) sigh “Select word. Delete previous character.” France (1 Result)

Note: This issue doesn’t occur on mobile devices, but only because Voice Control completely refuses to see the inputs on the example page.

iOS Voice Control not seeing the date inputs, example 1 iOS Voice Control not seeing the date inputs, example 2 iOS Voice Control not seeing the date inputs, example 3

abbott567 commented 3 years ago

I've also seen this happen with Dragon if a user pauses between numbers or letters. I've seen it come up a few times, and using blur() as @philsherry suggested could be a nice solution for this particular instance.

However, I think there is a guidance or education piece which needs addressing around sanitising input data before validation as it will affect more than just the date component. I've seen it happen on bank account fields and National Insurance number fields, so it then becomes a bit of a can of worms trying to fix it for people rather than getting them to understand their own validation requirements. It also means you'd still have the issue if JS didn't load.

It almost feels like we should have patterns for this kind of thing. We have visual patterns and coded components, but we don't have common sanitisation, regex's, wording etc.

36degrees commented 3 years ago

Having talked about this as a team, we think this is best addressed on the server-side by trimming or otherwise ignoring leading and trailing spaces as part of the validation process where appropriate. We think there'd be scope to add something about this to the 'Help users to recover from validation errors' pattern.

I've created an issue to represent this work – https://github.com/alphagov/govuk-design-system/issues/1450.

@philsherry it seems like this issue should be reported to Apple – have you raised a bug in Webkit / Radar?

philsherry commented 3 years ago

@36degrees Just done.

AX: Voice Control inserts leading spaces in input fields

edwardhorsford commented 3 years ago

To add - after testing, it's not just leading and trailing whitespace, but whitespace between the digits. Dictating with Voice Control I get 2 0 2 1. I think this is probably rather unexpected and teams already stripping leading and trialing whitespace by default are unlikely to catch this.

It would be good to explicitly mention this on the date input component.

36degrees commented 2 years ago

This is reported as having been fixed 'in shipping software' on the original Webkit bug as of February this year.

Testing it myself, following the steps outlined above, I am no longer seeing leading spaces nor spaces between characters when using Voice Control in Safari 15.5 (17613.2.7.1.8) on macOS 12.4 (21F79).

I think we can therefore close this issue as resolved. Thanks to @philsherry for taking the time to report it to us and to the Webkit team.

36degrees commented 2 years ago

(I've also tested dictating 'two zero two one' and I get 2021 in the text input rather than 2 0 2 1, so I believe that's been fixed too)