Vivid API

Number Field

Allows users to enter a number in a text field or use buttons to increment or decrement the value.

Usage

import { registerNumberField } from '@vonage/vivid-api';
registerNumberField('your-prefix');

About Number Field

The number-field component allows users to enter a number in a text field. It follows the native number field specification.

The component is not appropriate for values that only happen to consist of numbers but aren’t strictly speaking a number, e.g. phone numbers or ZIP codes. Use the text-field component instead.

Known issues

  • Constraint validation with minlength and maxlength is not supported.

Step

  • Type: number
  • Default: 1

Set the step attribute to change the step value for the number field.

Min

  • Type: number | undefined
  • Default: undefined

Set the min attribute to set the minimum value for the number field.

Max

  • Type: number | undefined
  • Default: undefined

Set the max attribute to set the maximum value for the number field.

Slots

Helper-Text

The helper-text slot allows you to use rich content as the number field’s helper text.

Example showing a link in the helper text:

Contextual-Help

The contextual-help slot allows you to add the Contextual Help component next to the label.

API Reference

Properties

PropertyTypeDefaultDescription
appearance'fieldset' | 'ghost'
autoCompletestring
autofocusbooleanIndicates that this element should get focus after the page finishes loading. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautofocus | autofocus HTML attribute for more information.
decrementButtonAriaLabelstring
disabledbooleanSets the element's disabled state. A disabled element will not be included during form submission.
errorTextstringProvides a custom error message. Any current error state will be overridden.
helperTextstringProvides additional information to help the user enter the correct information. To add HTML to the helper text, use the helper-text slot instead.
incrementButtonAriaLabelstring
initialValuestringThe default value of the element. This value sets the `value` property only when the `value` property has not been explicitly set.
labelstringThe label for the form element.
liststringAllows associating a https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist | datalist to the element by https://developer.mozilla.org/en-US/docs/Web/API/Element/id.
maxnumberThe maximum the value can be
maxlengthnumberThe maximum number of characters a user can enter.
minnumberThe minimum the value can be
minlengthnumberThe minimum number of characters a user can enter.
namestringThe name of the element. This element's value will be surfaced during form submission under the provided name.
placeholderstringSets the placeholder value of the element, generally used to provide a hint to the user.
readOnlybooleanWhen true, the control will be immutable by user interaction. See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly | readonly HTML attribute for more information.
requiredbooleanRequire the field to be completed prior to form submission.
scale'condensed' | 'normal'The size the number-field should have.
shape'rounded' | 'pill'
sizenumberSets the width of the element to a specified number of characters.
stepnumberAmount to increment or decrement the value by
successTextstringProvides a custom success message. Any current error state will be overridden.
value
(modelValue)
stringThe current value of the element.
valueAsNumber
(valueAsNumber)
numberThe value property, typed as a number.
PropertyTypeDefaultDescription
appearance'fieldset' | 'ghost'
autocompletestring
autofocusbooleanIndicates that this element should get focus after the page finishes loading. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautofocus | autofocus HTML attribute for more information.
decrement-button-aria-labelstring
disabledbooleanSets the element's disabled state. A disabled element will not be included during form submission.
error-textstringProvides a custom error message. Any current error state will be overridden.
helper-textstringProvides additional information to help the user enter the correct information. To add HTML to the helper text, use the helper-text slot instead.
increment-button-aria-labelstring
valuestringThe default value of the element. This value sets the `value` property only when the `value` property has not been explicitly set.
labelstringThe label for the form element.
liststringAllows associating a https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist | datalist to the element by https://developer.mozilla.org/en-US/docs/Web/API/Element/id.
maxnumberThe maximum the value can be
maxlengthnumberThe maximum number of characters a user can enter.
minnumberThe minimum the value can be
minlengthnumberThe minimum number of characters a user can enter.
namestringThe name of the element. This element's value will be surfaced during form submission under the provided name.
placeholderstringSets the placeholder value of the element, generally used to provide a hint to the user.
readonlybooleanWhen true, the control will be immutable by user interaction. See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly | readonly HTML attribute for more information.
requiredbooleanRequire the field to be completed prior to form submission.
scale'condensed' | 'normal'The size the number-field should have.
shape'rounded' | 'pill'
sizenumberSets the width of the element to a specified number of characters.
stepnumberAmount to increment or decrement the value by
success-textstringProvides a custom success message. Any current error state will be overridden.
current-valuestringThe current value of the element.
valueAsNumber
(property only)
numberThe value property, typed as a number.

Slots

NameDescription
contextual-helpSlot for the contextual-help component, displayed next to the label.
helper-textDescribes how to use the number-field. Alternative to the `helper-text` attribute.
NameDescription
contextual-helpSlot for the contextual-help component, displayed next to the label.
helper-textDescribes how to use the number-field. Alternative to the `helper-text` attribute.

Events

NameTypeDescription
changeCustomEvent<undefined>Fires a custom 'change' event when the value has changed
inputCustomEvent<undefined>Fires a custom 'input' event when the value has changed
NameTypeDescription
changeCustomEvent<undefined>Fires a custom 'change' event when the value has changed
inputCustomEvent<undefined>Fires a custom 'input' event when the value has changed

Methods

NameParamsReturnsDescription
checkValiditybooleanReturn the current validity of the element.
reportValiditybooleanReturn the current validity of the element. If false, fires an invalid event at the element.
selectvoidSelects all the text in the number field
stepChanged
_: number
next: number
void
stepDownvoidDecrements the value using the step value
stepUpvoidIncrements the value using the step value
validatevoid{@inheritDoc (FormAssociated:interface).validate}