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
- 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 |
|
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 |
|
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 |
|
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.