Skip to content

Number input - Web Component โ€‹

Attention!

The localization format of the input comes from the format settings of the client's operation system.

Browser support โ€‹

Parameters โ€‹

The Web component uses the <z-number-input> tag:

The parametrization of the component can be done with the following custom HTML params:

NameTypeDescription
configstring

The main parameter has two components following the pattern: <shape><?:size>.

  • shape: Establishes the styling of the input. Default value is line . Possible values are: shaped or line. ,
  • size: (optional) defines de size of the input. The default value is m, being omitted from the param. The possible values are: m or l.
labelstringLabel of the input
readonly
(optional)
booleanTransforms the input into an output
value
(optional)
numberValue of the model
disabled
(optional)
booleanBlocks the interaction with the input component.
required
(optional)
booleanMarks the input component as required.
name
(optional)
stringIdentification for the field inside the form
invalid
(optional)
booleanThe forced state for set the input as invalid
help-text
(optional)
stringThe forced message to be shown under the input
rangenumber[]First value is the minimum value of the input, second value is the maximum value of the input.
stepnumberStep value of the input.

The events emitted from the component are:

NamePayloadDescription
onchangenumberReturns the new value of the "value" attribute

config โ€‹

The config parameter is used to set the shape of the input between lined and shaped. Being omitted will render the default line shape.

label โ€‹

The label parameter is used to set the text label of the component. Make sure you always use it.

readonly โ€‹

The readonly parameter is used to set the input in a read-only state. It's commonly used to display information.

value โ€‹

The value parameter is used to set the number for the input. Make sure you use a valid number format.

disabled โ€‹

The disabled parameter is used to block the interaction with the component. Not to be confused with readonly.

required โ€‹

The required parameter is used to set the component as required.

name โ€‹

The name parameter is used to set the name of the component. This is useful when the component is part of a form.

invalid โ€‹

The invalid parameter is used to force the component to be invalid.

help-text โ€‹

The help-text parameter is used to provide additional assistance to the user.

range โ€‹

The range parameter is used to set the range of the input. It must be an array with two numbers. The first number is the minimum value and the second number is the maximum value.

step โ€‹

The step parameter is used to set the step of the input. It must be a number. The default value is 1.

Playground โ€‹

Customization โ€‹

HTML Examples โ€‹

Imports
html
<link rel="stylesheet" href="/0.4.1/@zurich/web-components/styles.css" />
<script type="module" src="/0.4.1/@zurich/web-components/number-input.js"></script>
Code
html

<!-- Default -->
<z-number-input label="Number input"></z-number-input>
<z-number-input label="Number input" config="shaped"></z-number-input>

<!-- with value -->
<z-number-input label="Number input" value="-12.34"></z-number-input>
<z-number-input label="Number input" value="-12.34" config="shaped"></z-number-input>

<!-- disabled -->
<z-number-input label="Number input" disabled></z-number-input>
<z-number-input label="Number input" disabled config="shaped"></z-number-input>

<!-- readonly -->
<z-number-input label="Number input" readonly value="-12.34"></z-number-input>
<z-number-input label="Number input" readonly value="-12.34" config="shaped"></z-number-input>

<!-- with help text -->
<z-number-input label="Number input" help-text="Help text"></z-number-input>
<z-number-input label="Number input" help-text="Help text" config="shaped"></z-number-input>

<!-- invalid -->
<z-number-input label="Number input" help-text="Invalid input" invalid></z-number-input>
<z-number-input label="Number input" help-text="Invalid input" invalid config="shaped"></z-number-input>