carbon: Slider error validation

Slider validation

In Slider component, if I enter a number greater than the max number, I get a red border around the text field but the number remained in the field. image

I think the component shouldn’t allow users to keep the numbers greater than the max number. It should change the number to the max number (100) if user’s data is higher than the max number, or add a validation text below the slider describing the issue with the users data.

### Tasks
- [ ] https://github.com/carbon-design-system/carbon/issues/13473
- [ ] https://github.com/carbon-design-system/carbon/issues/13474
- [ ] https://github.com/carbon-design-system/carbon/issues/13477
- [ ] https://github.com/carbon-design-system/carbon/issues/13476
- [ ] https://github.com/carbon-design-system/carbon-website/issues/3511
- [ ] https://github.com/carbon-design-system/carbon-design-kit/issues/676

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

@thefirstartist I said “11” not “111”. Trying to point out that the assumption the number entered was intentional and not a mistype may not be valid.

@thefirstartist Auto-correction on blur would constitute an assumption made by the Carbon team of how a general purpose component is used in certain applications, but not all applications. That is not a decision the Carbon team themselves should make.

It’s also very hard for a visually impaired user using a screen reader to become aware that a previously entered value has now been altered (and potentially persisted on a server someplace) as a result of them browsing away from the field in question without modifying it.

The error suggestion laid out by @tay1orjones (and @aagonzales) is transparent, informative, and assumption-less. It assumes you know your data better than anyone else, and it will not self-modify unless you tell it to do so.

I worked on a team where they have a similar settings page with auto-saving like you described, but they rely on the fact that the form components will not be auto-updated in the absence of user action. A change to that effect would “break” their use case.

Probably shouldn’t reinvent the wheel here. Pop a validation message and let the user decide the best course of action. By doing that, the field stays invalid and should prevent forms from submitting.

I agree. I don’t believe auto-correction is something to include within the component. This can already be achieved by using the onBlur handler to implement your own custom error handling validation. Additionally there is now a onInputKeyUp prop that can also be used for custom validation if you prefer, https://github.com/carbon-design-system/carbon/pull/11230

I think a reasonable improvement here would be to add an error icon to the input and provide optional helpText. Something akin to this suggestion from @aagonzales - I’m not sure if we’d need the actual slider track and handle to be red though.

image