IntegerField and NumberField with overridable PARSER and FORMATTER

I want to edit integers and doubles but apply advanced formatting such as significant-digits, maximum-digits, commas, switching to scientific-notation for large/small numbers, etc. Unfortunately, both IntegerField and NumberField hide the constructor that would allow the developer to provide a different parser and formatter.

I’ve written my own implementation that uses a TextField. It is more work and ugly code.

Is there a strong reason why this needed to be private?

Probably no direct reason for making that API private other than the regular framework designer instinct to avoid leaking implementation details that might be a liability for backwards compatibility in the future. We basically want to have a specific use case for anything that isn’t private so that we can have tests for that case to see that we don’t accidentally break it.

IntegerField and NumberField use internally input element with type number, which means that you can’t that freely add custom formatter.

So your approach to use TextField is a correct one. You can compare your solution to my example here and check whether it is uglier or prettier.

https://v-herd.eu/tatulund-addons/decimal-field

There is an enhancement request in our backlog to refactor these fields internal implementation to be based on text input: [number-field] Consider using `input type="text"` for number and integer fields · Issue #3102 · vaadin/web-components · GitHub