Number input¶
The number input allows users to enter and modify a numeric value with an optional unit.
Usage¶
The component includes +
/ -
controls to increment or decrement the value in predefined steps. It acts as a high-level alternative to the native number input control.
When to use¶
- To enter a numeric value in a form or inline in a component.
- When a user needs precise control over a numeric value.
Best practices¶
- Define the width of the number input field according to the maximum value and the grid system.
- Offer a smart default value whenever possible.
- When precision is not important, use a slider instead.
Design¶
Elements¶
- Label (optional), 2. Container, 3. Content, 4. Unit (optional), 5. Controls (optional)
Label (optional)¶
Effective form labeling helps users understand what information to enter.
- Provide a short and concise label that is shorter than the input field itself.
- A mandatory field is marked with an
*
-asterisk. - Labels can be placed above or left to the input.
Controls (optional)¶
The number input can contain controls to increment or decrement the value.
It is possible to set the step size. E.g. in a range of 0..10'000
, a step size of 10
is more appropriate.
Interaction states¶
Validation¶
Real-time validation ensures that the data being entered is within a specific range or follows certain rules, preventing errors and ensuring the integrity of the data.
Code¶
A drop-in replacement for the HTML <input type="number">
. It has more accessible increment decrement buttons and can show a unit.
Usage¶
import { SiNumberInputComponent } from '@siemens/element-ng/number-input';
@Component({
imports: [SiNumberInputComponent, ...]
})
SiNumberInputComponent API Documentation¶
si-number-input
Common interface for form item controls. Controls that should be connected to SiFormItemComponent must implement this interface and must be provided using the SI_FORM_ITEM_CONTROL token.
Input Properties¶
Name | Type | Default | Description |
---|---|---|---|
aria-label ¶ | TranslatableString | undefined | The aria-label passed to the input |
disabled ¶ | boolean | false | |
inputId ¶ | string | __si-number-input-${SiNumberInputComponent.idCounter++} | ID that is set on the input, e.g. for <label for="..."> |
max ¶ | number | undefined | The max. value for HTML input |
min ¶ | number | undefined | The min. value for HTML input |
placeholder ¶ | TranslatableString | The placeholder for input field. | |
readonly ¶ | boolean | false | |
showButtons ¶ | boolean | true | Show increment/decrement buttons? |
step ¶ | (number | "any" ) | 1 | The step size for HTML input |
unit ¶ | string | Optional unit label | |
value ¶ | number | The value |
Output Properties¶
Name | Type | Description |
---|---|---|
valueChange ¶ | (undefined | number ) |
Attributes and Methods¶
Name | Type | Default | Description |
---|---|---|---|
(readonly) id ¶ | Signal <string > | ... | The actual id of the control that should be used in the for attribute of a label. |
(readonly) inputElement ¶ | Signal <ElementRef <HTMLInputElement >> | ... |
Types Documentation¶
Variable |
---|
Represents a translatable string. This can either be a translation key, e.g. ACTIONS.EDIT that will be automatically translated when displayed on the UI or a pre-translated string, e.g. Edit . Equivalent to a normal string in usage and functionality. |
---|
Common interface for form item controls. Controls that should be connected to SiFormItemComponent must implement this interface and must be provided using the SI_FORM_ITEM_CONTROL token. | |||||
---|---|---|---|---|---|
|
Translatable import imported from @siemens/element-translate-ng |
---|
|
Interface for form error mapper. It resolves a key to either a translatable string or function which is called with the validation error for its key and should return a translatable string. | |
---|---|
| |
|
|
| |||||||||||||||||||||||||||
| |||||||||||||||||||||||||||
| |||||||||||||||||||||||||||
|
| ||||||||||||||||||||||
| ||||||||||||||||||||||
| ||||||||||||||||||||||
|
| ||||||||||||
| ||||||||||||
|
Except where otherwise noted, content on this site is licensed under MIT License.