Skip to main content

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

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);
}
}

API

Property and attribute binding examples for Genesis Component syntax.

Attributes

NameTypeDescriptionExample
autofocusbooleanWhen true, the component will be focused when the page has finished loading
<rapid-number-field ?autofocus="${(x) => x.autoFocus}">
appearancestringCan be outline or filled
<rapid-number-field appearance="outline">
disabledbooleanSimilar to readonly, but with a blur on the component
<rapid-number-field ?disabled="${(x) => x.isDisabled}">
localestringDefines a number format based on language and location. Default: "en-US". Must be used with withFormatting
<rapid-number-field withFormatting locale="en-GB">
formstringAssociates 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
<rapid-number-field form="myForm">
hideStepbooleanHides the step control (up and down arrows) for the element
<rapid-number-field hideStep>
maxlengthnumberThe maximum number of characters allowed
<rapid-number-field maxlength="${(x) => x.maxLength}">
minlengthnumberThe minimum number of characters allowed
<rapid-number-field minlength="${(x) => x.minLength}">
maxnumberDefines the maximum value allowed
<rapid-number-field max="${(x) => x.max}">
minnumberDefines the minimum value allowed
<rapid-number-field min="${(x) => x.min}">
withFormattingbooleanEnables you to format the number
<rapid-number-field withFormatting>
namestringDefines the name of the element
<rapid-number-field name="username">
placeholderstringSets placeholder text for the element (which disappears when the user starts typing)
<rapid-number-field placeholder="Enter your name">
readonlybooleanIf true, the user cannot change the value of this field
<rapid-number-field ?readonly="${(x) => x.isReadonly}">
sizenumberSets the width of the component
<rapid-number-field size="${(x) => x.fieldSize}">
stepnumberDefines the amount the field value changes each time the user clicks to increase or decrease the field value
<rapid-number-field type="number" step="${(x) => x.stepValue}">
valuestringSets the value for this component. Use the sync utility to bind the data the template back to the model.
<rapid-number-field value="${sync((x) => x.fieldValue, 'number')}">

Properties

NameTypeDescriptionExample
optionsjsonThe options to be used when withFormatting is true, e.g. , use maximumFractionDigits to set the number of decimal places.
<rapid-number-field withFormatting :options=${() => ({maximumFractionDigits: 2})}>

Slots

SlotUse
startStart slot.
endEnd slot.
step-up-glyphThe glyph for the step up control.
step-down-glyphThe glyph for the step down control.

Parts

PartUse
labelThe label.
startBefore the input.
controlsThe step up and step down controls.
endAfter the input.
rootThe element wrapping the control, including start and end slots.
controlThe element representing the input.
step-upThe step up control.
step-downThe step down control.

Events fired

NameTypeDescriptionExample
@inputvoidFires a custom 'input' event when the value is changed via step-up and step-down functionality, and also on blur.
<rapid-number-field @input="${(x) => x.inputHandler()}">
@changevoidFires a custom 'change' event when the value has changed.
<rapid-number-field @change="${(x) => x.changeHandler()}">

Events listened to

This component doesn't listen to any events.

Further details

This component is an implementation of an HTML text-field element.