Number input
...
Attention!
The localization format of the input comes from the format settings of the client's operation system.
Browser support
...
Parameters
The CSS component uses the <label>
tag.
The parametrization of the component can be done with the following custom HTML params:
Name | Type | Description |
---|---|---|
z-number-input | string | The main parameter has two components following the pattern:
|
label | string | Label of the input |
readonly | boolean? | Transforms the input into an output |
value | string? | Value of the model |
disabled | boolean? | Blocks the interaction with the input component. |
required | boolean? | Marks the input component as required. |
name | string? | Identification for the field inside the form |
help-text | string? | The forced message to be shown under the input |
min | number | Minimum value of the input. |
max | number | Maximum value of the input. |
step | number | Step value of the input. |
The events emitted from the component are:
Name | Payload | Description |
---|---|---|
onchange | number | Returns the new value of the "value" attribute |
Invalid input
If you require to make the input invalid, use the native API of the input using setCustomValidity
. If no message is provided, the input is set to valid
.
ts
// Make invalid
input.setCustomValidity('Error message');
input.checkValidity();
Or you can use the data-invalid
attribute if you are using the scripts:
html
<label z-number-input>
<span>Number input</span>
<input type="number" data-invalid />
</label>
Playground
Customization
HTML Examples
Imports
html
<script type="module" src="/0.3.6/@zurich/css-components/javascript.js"></script>
<link rel="stylesheet" href="/0.3.6/@zurich/css-components/base.css" />
<link rel="stylesheet" href="/0.3.6/@zurich/css-components/NumberInput.css" />
Code
html
<!-- Default -->
<label z-number-input>
<span>Number input</span>
<input type="number" />
</label>
<label z-number-input="shaped">
<span>Number input</span>
<input type="number" />
</label>
<!-- with value -->
<label z-number-input>
<span>Number input</span>
<input type="number" value="-12.34" />
</label>
<label z-number-input="shaped">
<span>Number input</span>
<input type="number" value="-12.34" />
</label>
<!-- disabled -->
<label z-number-input>
<span>Number input</span>
<input type="number" disabled />
</label>
<label z-number-input="shaped">
<span>Number input</span>
<input type="number" disabled />
</label>
<!-- readonly -->
<label z-number-input>
<span>Number input</span>
<input type="number" readonly value="-12.34" />
</label>
<label z-number-input="shaped">
<span>Number input</span>
<input type="number" readonly value="-12.34" />
</label>
<!-- with help text -->
<label z-number-input>
<span>Number input</span>
<small>Help text</small>
<input type="number" />
</label>
<label z-number-input="shaped">
<span>Number input</span>
<small>Help text</small>
<input type="number" />
</label>
<!-- invalid -->
<label z-number-input>
<span>Number input</span>
<small>Invalid input</small>
<input type="number" data-invalid />
</label>
<label z-number-input="shaped">
<span>Number input</span>
<small>Invalid input</small>
<input type="number" data-invalid />
</label>