Counter
Overview
Counter
is a field that lets you increase or decrease its value incrementally, as well as directly input a value.
When to use:
- Use
Counters
to input values that have a small range of likely values (e.g. 1-10). - Use
Counters
for values that are usually a number with some exceptions - e.g. number of copies.
Implementation
Counters
are stylized numerical form controls with the ability to control validation.
Edit the code below to see your changes live!
function Example() { const [counterValue, setCounterValue] = useState(5); const handleChange = (value: number) => { setCounterValue(value); }; return ( <Form> <FormGroup> <Counter description="Description for the counter." label="Label" max={10} min={0} onCountChange={handleChange} value={counterValue} /> </FormGroup> </Form> ); }
Props
Supports most native <input />
element attributes.
Prop name | Type | Default | Description |
---|---|---|---|
label | string | FormControlLabel |
| Label element for |
labelId | string |
| Appends an |
description | string | FormControlDescription |
| Append a description to the input field. |
error | string | string[] | FormControlError | FormControlError[] |
| Displays an error message for the field. Error message will be passed to the |
value * | number |
| Value for the |
min | number | 0 | The minimum |
max | number | 100 | The maximum |
step | number | 1 | The amount beetween one |
onCountChange * | (count: number) => void |
| Function to be called that changes counter value. Receives the new count from the component. |
localization | { decreaseCount: string, increaseCount: string, optional: string } |
| Overrides the labels with localized text. |
Props ending with * are required
Do's and Don'ts
Do |
---|
Counters should have a default value that represents the most likley choice the user will take. |
Counters should always have a clear label as to what the number represents. |
Include relevant signs (e.g. %, $) in the Counter to give context for the value’s type. |
Don't |
---|
Avoid Counters if the value will likley change by large/unpredictable increments (e.g. price). |