Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

[Time Input] is allowing NaN in the hidden value field. #1495

Open
xenoworf opened this issue Dec 20, 2021 · 2 comments
Open

[Time Input] is allowing NaN in the hidden value field. #1495

xenoworf opened this issue Dec 20, 2021 · 2 comments

Comments

@xenoworf
Copy link
Contributor

Bug Report

Description

If you start with an empty Time Input and enter a single digit in the 2nd or last field (e.g. minutes in hour/minute or seconds in hour/minute/second) then the component is letting the string "NaN" through.

This is a bug because NaN shouldn't be a part of even a partial iso-8601-like value, which is supposed to be what that hidden field is.

Steps to Reproduce

You can go to the component's doc page and try what I've said above. Inspect the output in your console and you'll see the NaN.

Additional Context / Screenshots

The problem is happening because parseInt(val, 10) results in NaN when val is '' (empty string).

Here is a screenshot w/ the console showing a value containing NaN:
image

Expected Behavior

Certainly not seeing NaN in the value. There are a couple behaviors we could do instead. It all depends on what behavior we want when the user enters a partial value. We DO expect the consumers to take care of end-user-input validation - so we can't try to "fix" the value in the component.

Possible Solution

@benbcai @jmsv6d @neilpfeiffer

@xenoworf
Copy link
Contributor Author

On the face of it, the two easiest options either:

  1. Fill in "00" or some default time value (what?) for the other fields so that they'll parse correctly. This might surprise consumers and users.
  2. Filter out NaN and do nothing else. This would result in values like ::01. Is that better?

@xenoworf
Copy link
Contributor Author

I just chatted with @neilpfeiffer and we both agree the safest and most passive approach is to prevent the value field from being populated (having a value other than empty-string or undefined) unless the other inputs are minimally value, e.g. valid numbers.

I will probably implement this soon as a part of my a11y enhancements.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant