NumberInputV2
Use the NumberInput component to enter integers and floating-point numbers.
Import
import { NumberInputV2 } from '@dynatrace/strato-components/forms';
Use cases
This is the simplest version of the NumberInputV2, which is uncontrolled and
therefore handles its state internally. You can also set a specific initial
value using the defaultValue prop.
Control the state
The NumberInput can also be controlled, meaning that you can handle the state.
To do so, you need to use the onChange prop to provide a handler that is
called when a valid number can be received. Which is when the input gets
blurred or a step button is clicked - it does not happen on typing. You also
need to assign the value from the state to the NumberInput by setting the
value prop.
Validate with min and max
The NumberInput has built-in support for the min and max props. When the
entered value falls outside the allowed range, the component automatically
displays a validation error. Add FormFieldMessages inside FormField to
render those messages.
Validate with step
The step prop constrains the accepted values to specific increments. If the
entered value does not align with the step (relative to min if provided), a
validation error is shown automatically.
The value can be incremented or decremented in the following ways:
| Interaction | Behaviour |
|---|---|
↑ / ↓ arrow keys | Increment / decrement by one step |
| Scroll wheel (when focused) | Same as arrow keys |
Home key | Jumps to min — only when min is set |
End key | Jumps to max — only when max is set |
Snap-to-step alignment: if the current value is not aligned with the step when an arrow key or scroll event fires, the first interaction snaps the value to the nearest step boundary instead of moving a full step — subsequent interactions then move by exactly one step as expected.
Clamping: stepping always respects min and max. The value will not go
below min or above max. When max and step are both set, the highest
reachable step-aligned value may be less than max if max is not itself
step-aligned.
Read-only inputs: all step interactions are suppressed when the input is in
readOnly mode.