Logo

NumberBox

NumberBox provides a specialized input field for numeric values with built-in validation, spinner buttons, and flexible formatting options. It supports both integer and floating-point numbers, handles empty states as null values, and integrates seamlessly with form validation.
Key features:
  • Flexible numeric input: Accepts integers, floating-point numbers, or empty values (stored as null)
  • Input constraints: Configure minimum/maximum values, integer-only mode, and positive-only restrictions
  • Spinner buttons: Built-in increment/decrement buttons with customizable step values and icons
  • Visual adornments: Add icons or text to the start and end of the input field
  • Validation: Built-in validation status indicators and form compatibility
  • Smart paste handling: Only accepts pasted content that results in valid numeric values
The NumberBox is often used in forms. See the this guide for details.

Properties

autoFocus (default: false)

If this property is set to true, the component gets the focus automatically when displayed.
If this boolean prop is set to true, the NumberBox input will be focused when appearing on the UI.

enabled (default: true)

This boolean property value indicates whether the component responds to user events (true) or not (false).
Controls whether the input field is enabled (true) or disabled (false).
<App>
  <NumberBox enabled="false" />
</App>
Example: enabled
<App>
  <NumberBox enabled="false" />
</App>

endIcon

This property sets an optional icon to appear on the end (right side when the left-to-right direction is set) of the input.
This string prop enables the display of an icon on the right side (left-to-right display) of the input field by providing a valid
icon name
.
<App>
  <NumberBox endIcon="email" />
</App>
Example: endIcon
<App>
  <NumberBox endIcon="email" />
</App>
It is possible to set the other adornments as well: endText, startIcon and startText.
<App>
  <NumberBox startIcon="hyperlink" startText="www." endIcon="email" endText=".com" />
</App>
Example: all adornments
<App>
  <NumberBox startIcon="hyperlink" startText="www." endIcon="email" endText=".com" />
</App>

endText

This property sets an optional text to appear on the end (right side when the left-to-right direction is set) of the input.
This string prop enables the display of a custom string on the right side (left-to-right display) of the input field.
<App>
  <NumberBox endText=".com" />
</App>
Example: endText
<App>
  <NumberBox endText=".com" />
</App>
It is possible to set the other adornments as well: endIcon, startIcon and startText.
<App>
  <NumberBox startIcon="hyperlink" startText="www." endIcon="email" endText=".com" />
</App>
Example: all adornments
<App>
  <NumberBox startIcon="hyperlink" startText="www." endIcon="email" endText=".com" />
</App>

gap

This property defines the gap between the adornments and the input area.

hasSpinBox (default: true)

This boolean prop shows (true) or hides (false) the spinner buttons for the input field.
<App>
  <NumberBox hasSpinBox="true" initialValue="3" />
  <NumberBox hasSpinBox="false" initialValue="34" />
</App>
Example: hasSpinBox
<App>
  <NumberBox hasSpinBox="true" initialValue="3" />
  <NumberBox hasSpinBox="false" initialValue="34" />
</App>

initialValue

This property sets the component's initial value.
The initial value displayed in the input field.
<App>
  <NumberBox initialValue="123" />
</App>
Example: initialValue
<App>
  <NumberBox initialValue="123" />
</App>

integersOnly (default: false)

This boolean property signs whether the input field accepts integers only (true) or not (false).
<App>
  <NumberBox integersOnly="true" initialValue="42" />
  <NumberBox integersOnly="false" initialValue="{Math.PI}" />
</App>
Example: integersOnly
<App>
  <NumberBox integersOnly="true" initialValue="42" />
  <NumberBox integersOnly="false" initialValue="{Math.PI}" />
</App>

label

This property sets the label of the component. If not set, the component will not display a label.

labelBreak (default: true)

This boolean value indicates whether the NumberBox label can be split into multiple lines if it would overflow the available label width.

labelPosition (default: "top")

Places the label at the given position of the component.
Available values:
ValueDescription
startThe left side of the input (left-to-right) or the right side of the input (right-to-left)
endThe right side of the input (left-to-right) or the left side of the input (right-to-left)
topThe top of the input (default)
bottomThe bottom of the input

labelWidth

This property sets the width of the NumberBox component's label. If not defined, the label's width will be determined by its content and the available space.

maxLength

This property sets the maximum length of the input it accepts.

maxValue (default: 999999999999999)

The maximum value the input field allows. Can be a float or an integer if integersOnly is set to false, otherwise it can only be an integer.If not set, no maximum value check is done.
The maximum value the input field allows. Can be a float or an integer if integersOnly is set to false, otherwise it can only be an integer.
Try to enter a bigger value into the input field below than the maximum allowed.
<App>
  <NumberBox maxValue="100" initialValue="99" />
</App>
Example: maxValue
<App>
  <NumberBox maxValue="100" initialValue="99" />
</App>

minValue (default: -999999999999999)

The minimum value the input field allows. Can be a float or an integer if integersOnly is set to false, otherwise it can only be an integer.If not set, no minimum value check is done.
Try to enter a bigger value into the input field below than the minimum allowed.
<App>
  <NumberBox minValue="-100" initialValue="-99" />
</App>
Example: minValue
<App>
  <NumberBox minValue="-100" initialValue="-99" />
</App>

placeholder

An optional placeholder text that is visible in the input field when its empty.
A placeholder text that is visible in the input field when its empty.
<App>
  <NumberBox placeholder="This is a placeholder" />
</App>
Example: placeholder
<App>
  <NumberBox placeholder="This is a placeholder" />
</App>

readOnly (default: false)

Set this property to true to disallow changing the component value.
If true, the component's value cannot be modified with user interactions.
<App>
  <NumberBox initialValue="123" readOnly="true" />
</App>
Example: readOnly
<App>
  <NumberBox initialValue="123" readOnly="true" />
</App>

required (default: false)

Set this property to true to indicate it must have a value before submitting the containing form.

spinnerDownIcon

Allows setting an alternate icon displayed in the NumberBox spinner for decrementing values. You can change the default icon for all NumberBox instances with the "icon.spinnerDown:NumberBox" declaration in the app configuration file.

spinnerUpIcon

Allows setting an alternate icon displayed in the NumberBox spinner for incrementing values. You can change the default icon for all NumberBox instances with the "icon.spinnerUp:NumberBox" declaration in the app configuration file.

startIcon

This property sets an optional icon to appear at the start (left side when the left-to-right direction is set) of the input.
This string prop enables the display of an icon on the left side (left-to-right display) of the input field by providing a valid
icon name
.
<App>
  <NumberBox startIcon="hyperlink" />
</App>
Example: startIcon
<App>
  <NumberBox startIcon="hyperlink" />
</App>
It is possible to set the other adornments as well: endText, startIcon and startText.
<App>
  <NumberBox startIcon="hyperlink" startText="www." endIcon="email" endText=".com" />
</App>
Example: all adornments
<App>
  <NumberBox startIcon="hyperlink" startText="www." endIcon="email" endText=".com" />
</App>

startText

This property sets an optional text to appear at the start (left side when the left-to-right direction is set) of the input.
This string prop enables the display of a custom string on the left side (left-to-right display) of the input field.
<App>
  <NumberBox startText="www." />
</App>
Example: startText
<App>
  <NumberBox startText="www." />
</App>
It is possible to set the other adornments as well: endIcon, startIcon and endText.
<App>
  <NumberBox startIcon="hyperlink" startText="www." endIcon="email" endText=".com" />
</App>
Example: all adornments
<App>
  <NumberBox startIcon="hyperlink" startText="www." endIcon="email" endText=".com" />
</App>

step (default: 1)

This prop governs how big the step when clicking on the spinner of the field.
The default stepping value is 1.
Note that only integers are allowed to be entered.
<App>
  <NumberBox initialValue="10" step="10" />
</App>
Example: step
<App>
  <NumberBox initialValue="10" step="10" />
</App>

validationStatus (default: "none")

This property allows you to set the validation status of the input component.
Available values:
ValueDescription
validVisual indicator for an input that is accepted
warningVisual indicator for an input that produced a warning
errorVisual indicator for an input that produced an error
This prop is used to visually indicate status changes reacting to form field validation.
ValueDescription
validVisual indicator for an input that is accepted
warningVisual indicator for an input that produced a warning
errorVisual indicator for an input that produced an error
<App>
  <NumberBox />
  <NumberBox validationStatus="valid" />
  <NumberBox validationStatus="warning" />
  <NumberBox validationStatus="error" />
</App>
Example: validationStatus
<App>
  <NumberBox />
  <NumberBox validationStatus="valid" />
  <NumberBox validationStatus="warning" />
  <NumberBox validationStatus="error" />
</App>

zeroOrPositive (default: false)

This boolean property determines whether the input value can only be 0 or positive numbers (true) or also negative (false).
This boolean property determines whether the input value can only be 0 or positive numbers (true) or also negative (false). By default, this property is set to false.
<App>
  <NumberBox initialValue="123" zeroOrPositive="true" />
</App>
Example: zeroOrPositive
<App>
  <NumberBox initialValue="123" zeroOrPositive="true" />
</App>

Events

didChange

This event is triggered when value of NumberBox has changed.
This event is triggered after the user has changed the field value.
Write in the input field and see how the Text underneath it is updated in parallel.
<App var.field="0">
  <NumberBox initialValue="{field}" onDidChange="(val) => field = val" />
  <Text value="{field}" />
</App>
Example: didChange
<App var.field="0">
  <NumberBox initialValue="{field}" onDidChange="(val) => field = val" />
  <Text value="{field}" />
</App>

gotFocus

This event is triggered when the NumberBox has received the focus.
This event is triggered when the NumberBox receives focus. The following sample demonstrates this event.
<App var.focused="{false}">
  <NumberBox
    onGotFocus="focused = true"
    onLostFocus="focused = false" />
  <Text>The NumberBox is {focused ? '' : 'not'} focused</Text>
</App>
Click into the NumberBox (and then click the text below):
<App var.focused="{false}">
  <NumberBox
    onGotFocus="focused = true"
    onLostFocus="focused = false" />
  <Text>The NumberBox is {focused ? '' : 'not'} focused</Text>
</App>
Click into the NumberBox (and then click the text below):

lostFocus

This event is triggered when the NumberBox has lost the focus.
This event is triggered when the NumberBox loses focus.
(See the example above)

Exposed Methods

focus

This API focuses the input field of the NumberBox. You can use it to programmatically focus the field.
Signature: focus(): void

setValue

This API sets the value of the NumberBox. You can use it to programmatically change the value.
Signature: setValue(value: number | undefined): void
You can use this method to set the component's current value programmatically.
<App>
  <NumberBox
    id="numberbox"
    readOnly="true"
  />
  <HStack>
    <Button
      label="Set to 100"
      onClick="numberbox.setValue(100)" />
    <Button
      label="Set to 0"
      onClick="numberbox.setValue(0)" />
  </HStack>
</App>
Example: value and setValue
<App>
  <NumberBox
    id="numberbox"
    readOnly="true"
  />
  <HStack>
    <Button
      label="Set to 100"
      onClick="numberbox.setValue(100)" />
    <Button
      label="Set to 0"
      onClick="numberbox.setValue(0)" />
  </HStack>
</App>

value

This API retrieves the current value of the NumberBox. You can use it to get the value programmatically.
Signature: get value(): number | undefined
You can query this read-only API property to get the input component's current value.
See an example in the setValue API method.

Parts

The component has some parts that can be styled through layout properties and theme variables separately:
  • endAdornment: The adornment displayed at the end of the text box.
  • input: The text box input area.
  • label: The label displayed for the text box.
  • startAdornment: The adornment displayed at the start of the text box.

Styling

Theme Variables

VariableDefault Value (Light)Default Value (Dark)
backgroundColor-NumberBox--disablednonenone
backgroundColor-NumberBox-defaultnonenone
backgroundColor-NumberBox-default--focusnonenone
backgroundColor-NumberBox-default--hovernonenone
backgroundColor-NumberBox-errornonenone
backgroundColor-NumberBox-error--focusnonenone
backgroundColor-NumberBox-error--hovernonenone
backgroundColor-NumberBox-successnonenone
backgroundColor-NumberBox-success--focusnonenone
backgroundColor-NumberBox-success--hovernonenone
backgroundColor-NumberBox-warningnonenone
backgroundColor-NumberBox-warning--focusnonenone
backgroundColor-NumberBox-warning--hovernonenone
borderColor-NumberBox--disablednonenone
borderColor-NumberBox-defaultnonenone
borderColor-NumberBox-default--focusnonenone
borderColor-NumberBox-default--hovernonenone
borderColor-NumberBox-errornonenone
borderColor-NumberBox-error--focusnonenone
borderColor-NumberBox-error--hovernonenone
borderColor-NumberBox-successnonenone
borderColor-NumberBox-success--focusnonenone
borderColor-NumberBox-success--hovernonenone
borderColor-NumberBox-warningnonenone
borderColor-NumberBox-warning--focusnonenone
borderColor-NumberBox-warning--hovernonenone
borderRadius-NumberBox-defaultnonenone
borderRadius-NumberBox-errornonenone
borderRadius-NumberBox-successnonenone
borderRadius-NumberBox-warningnonenone
borderStyle-NumberBox-defaultnonenone
borderStyle-NumberBox-errornonenone
borderStyle-NumberBox-successnonenone
borderStyle-NumberBox-warningnonenone
borderWidth-NumberBox-defaultnonenone
borderWidth-NumberBox-errornonenone
borderWidth-NumberBox-successnonenone
borderWidth-NumberBox-warningnonenone
boxShadow-NumberBox-defaultnonenone
boxShadow-NumberBox-default--focusnonenone
boxShadow-NumberBox-default--hovernonenone
boxShadow-NumberBox-errornonenone
boxShadow-NumberBox-error--focusnonenone
boxShadow-NumberBox-error--hovernonenone
boxShadow-NumberBox-successnonenone
boxShadow-NumberBox-success--focusnonenone
boxShadow-NumberBox-success--hovernonenone
boxShadow-NumberBox-warningnonenone
boxShadow-NumberBox-warning--focusnonenone
boxShadow-NumberBox-warning--hovernonenone
color-adornment-NumberBox-defaultnonenone
color-adornment-NumberBox-errornonenone
color-adornment-NumberBox-successnonenone
color-adornment-NumberBox-warningnonenone
fontSize-NumberBox-defaultnonenone
fontSize-NumberBox-errornonenone
fontSize-NumberBox-successnonenone
fontSize-NumberBox-warningnonenone
fontSize-placeholder-NumberBox-defaultnonenone
fontSize-placeholder-NumberBox-errornonenone
fontSize-placeholder-NumberBox-successnonenone
fontSize-placeholder-NumberBox-warningnonenone
gap-adornment-NumberBoxnonenone
outlineColor-NumberBox-default--focusnonenone
outlineColor-NumberBox-error--focusnonenone
outlineColor-NumberBox-success--focusnonenone
outlineColor-NumberBox-warning--focusnonenone
outlineOffset-NumberBox-default--focusnonenone
outlineOffset-NumberBox-error--focusnonenone
outlineOffset-NumberBox-success--focusnonenone
outlineOffset-NumberBox-warning--focusnonenone
outlineStyle-NumberBox-default--focusnonenone
outlineStyle-NumberBox-error--focusnonenone
outlineStyle-NumberBox-success--focusnonenone
outlineStyle-NumberBox-warning--focusnonenone
outlineWidth-NumberBox-default--focusnonenone
outlineWidth-NumberBox-error--focusnonenone
outlineWidth-NumberBox-success--focusnonenone
outlineWidth-NumberBox-warning--focusnonenone
padding-NumberBoxnonenone
paddingBottom-NumberBoxnonenone
paddingHorizontal-NumberBox$space-2$space-2
paddingLeft-NumberBoxnonenone
paddingRight-NumberBoxnonenone
paddingTop-NumberBoxnonenone
paddingVertical-NumberBox$space-2$space-2
textColor-NumberBox--disablednonenone
textColor-NumberBox-defaultnonenone
textColor-NumberBox-default--focusnonenone
textColor-NumberBox-default--hovernonenone
textColor-NumberBox-errornonenone
textColor-NumberBox-error--focusnonenone
textColor-NumberBox-error--hovernonenone
textColor-NumberBox-successnonenone
textColor-NumberBox-success--focusnonenone
textColor-NumberBox-success--hovernonenone
textColor-NumberBox-warningnonenone
textColor-NumberBox-warning--focusnonenone
textColor-NumberBox-warning--hovernonenone
textColor-placeholder-NumberBox-defaultnonenone
textColor-placeholder-NumberBox-errornonenone
textColor-placeholder-NumberBox-successnonenone
textColor-placeholder-NumberBox-warningnonenone
This site is an XMLUI™ app.