Number Field
Use cases:
- Numeric entry
- Not for cases where a field only contains numbers but should be a string e.g. credit card numbers or a phone number.
Example
Step automatically adjusts: 1 for integers, 0.1 for 1 decimal, 0.01 for 2 decimals, etc.
Values exceeding 12 significant digits will be truncated
- Genesis
- React
- Angular
Declaration
<rapid-number-field></rapid-number-field>
Usage
@customElement({
name: 'my-element',
template: html`
<rapid-text-field value=${sync((x) => x.fieldValue, 'number')}>
</rapid-text-field>
`,
})
export class MyElement extends GenesisElement {
@observable fieldValue = '';
fieldValueChanged() {
console.log(this.fieldValue);
}
}
Declaration
<rapid-number-field></rapid-number-field>
Usage
export function MyComponent() {
const [outputValue, setOutputValue] = useState('');
const onChange = (event) => {
setOutputValue(event.target.value);
console.log(outputValue);
}
return (
<rapid-number-field onChange={onChange}></rapid-number-field>
);
}
Declaration
<rapid-number-field></rapid-number-field>
Usage
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { FormsModule } from '@angular/forms';
@Component({
selector: 'my-root',
template: `
<rapid-number-field
(change)="onChange($event)"
></rapid-number-field>
`,
styleUrls: ['./my.component.css'],
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [FormsModule],
})
export class AppComponent {
onChange(event: Event) {
const target = event.target as HTMLInputElement;
console.log(target.value);
}
}
API
Property and attribute binding examples for Genesis Component syntax.
Attributes
| Name | Type | Description | Example |
|---|---|---|---|
| autofocus | boolean | When true, the component will be focused when the page has finished loading | |
| appearance | string | Can be outline or filled | |
| autoStepPrecision | boolean | When true, automatically calculates the step value based on the decimal precision of the current value. For example, a value of 100.5 will use a step of 0.1, while 100.25 will use 0.01. This ensures that step operations maintain the same decimal precision as the input value. | |
| disabled | boolean | Similar to readonly, but with a blur on the component | |
| locale | string | Defines a number format based on language and location. Default: "en-US". Must be used with withFormatting | |
| form | string | Associates this component with a form. Form id needs to be passed. If no Id is provided, then it will be associated with the ancestor form | |
| hideStep | boolean | Hides the step control (up and down arrows) for the element | |
| maxlength | number | The maximum number of characters allowed | |
| minlength | number | The minimum number of characters allowed | |
| max | number | Defines the maximum value allowed | |
| maximumInputPrecision | number | Defines the maximum number of significant digits allowed in the input. Default: 12. This helps prevent precision loss when working with very large or very precise numbers. | |
| min | number | Defines the minimum value allowed | |
| withFormatting | boolean | Enables you to format the number | |
| name | string | Defines the name of the element | |
| placeholder | string | Sets placeholder text for the element (which disappears when the user starts typing) | |
| readonly | boolean | If true, the user cannot change the value of this field | |
| size | number | Sets the width of the component | |
| step | number | Defines the amount the field value changes each time the user clicks to increase or decrease the field value. If autoStepPrecision is enabled, this value is ignored and the step is automatically calculated based on the decimal precision of the current value. | |
| value | string | Sets the value for this component. Use the sync utility to bind the data the template back to the model. | |
Properties
| Name | Type | Description | Example |
|---|---|---|---|
| options | json | The options to be used when withFormatting is true, e.g. , use maximumFractionDigits to set the number of decimal places. | |
Slots
| Slot | Use |
|---|---|
| start | Start slot. |
| end | End slot. |
| step-up-glyph | The glyph for the step up control. |
| step-down-glyph | The glyph for the step down control. |
Parts
| Part | Use |
|---|---|
| label | The label. |
| start | Before the input. |
| controls | The step up and step down controls. |
| end | After the input. |
| root | The element wrapping the control, including start and end slots. |
| control | The element representing the input. |
| step-up | The step up control. |
| step-down | The step down control. |
Events fired
| Name | Type | Description | Example |
|---|---|---|---|
| @input | void | Fires a custom 'input' event when the value is changed via step-up and step-down functionality, and also on blur. | |
| @change | void | Fires a custom 'change' event when the value has changed. | |
Events listened to
This component doesn't listen to any events.
Further details
This component is an implementation of an HTML text-field element.