Skip to content
Form InputNumber

InputNumber

A numeric field with increment and decrement buttons, formatted for a culture.

On this page

Examples

Quantity and price

The posted value is always invariant, whatever the culture shown.

Quantity: 2, price: 1234.5

Razor
<div class="flex w-full max-w-xs flex-col gap-4">
    <KlyFormField Label="Quantity">
        <KlyInputNumber @bind-Value="_quantity" Min="0" Max="20" />
    </KlyFormField>
    <KlyFormField Label="Price (French format)">
        <KlyInputNumber @bind-Value="_price" Min="0" Step="0.5m" Culture="_french" Orientation="KlyOrientation.Vertical" />
    </KlyFormField>
    <p class="text-sm text-(--klyroo-text-muted)" data-testid="number-state">Quantity: @(_quantity?.ToString() ?? "none"), price: @(_price?.ToString(System.Globalization.CultureInfo.InvariantCulture) ?? "none")</p>
</div>

@code {
    private decimal? _quantity = 2;
    private decimal? _price = 1234.5m;
    private static readonly System.Globalization.CultureInfo _french = new("fr-FR");
}

Bound to int, double and int?

The field binds to the type of the property: any built-in numeric type and its nullable form. Clearing a non-nullable field sets zero; a nullable one can be empty.

Seats: 4, discount: 12.5, ceiling: null

Razor
<div class="flex w-full max-w-xs flex-col gap-4">
    <KlyFormField Label="Seats (int)">
        <KlyInputNumber @bind-Value="_seats" Min="1" Max="50" data-testid="seats" />
    </KlyFormField>
    <KlyFormField Label="Discount in percent (double)">
        <KlyInputNumber @bind-Value="_discount" Min="0" Max="100" Step="2.5m" />
    </KlyFormField>
    <KlyFormField Label="Ceiling (int?, can be empty)">
        <KlyInputNumber @bind-Value="_ceiling" Min="0" />
    </KlyFormField>
    <p class="text-sm text-(--klyroo-text-muted)" data-testid="typed-number-state">Seats: @_seats, discount: @_discount.ToString(System.Globalization.CultureInfo.InvariantCulture), ceiling: @(_ceiling?.ToString() ?? "null")</p>
</div>

@code {
    // The field binds to the type of the property: int, long, double, decimal, byte... and their nullable forms.
    // Clearing the field of a non-nullable property sets zero; only a nullable property can be empty.
    private int _seats = 4;
    private double _discount = 12.5;
    private int? _ceiling;
}

Not bound

Without a binding the browser keeps the number, even when other parameters change.

Razor
<div class="flex w-full max-w-xs flex-col gap-3">
    <KlyFormField Label="Seats">
        <KlyInputNumber Value="2m" Min="0" Max="@_max" Name="seats" />
    </KlyFormField>
    <KlyButton Variant="ButtonVariant.Outline" Label="Raise the maximum" OnClick="Raise" />
</div>

@code {
    private decimal _max = 20;

    private void Raise() => _max += 5;
}

API

KlyInputNumber<TNumber>

Number field with increment and decrement buttons, limits and localized formatting. It binds to any built-in numeric type ( int , long , decimal , double , byte ...) and to its nullable form; only a nullable type can be empty, clearing the field of a non-nullable one sets zero.

Parameters

Name Type Default Description
Class string Classes added to the root element, merged last so they win over the theme.
Color KlyColor "primary" Semantic color of the control: a built-in KlyColor or the name of a color you defined. When not set, Color applies, else primary. Values: primary, secondary, success, info, warning, error, neutral.
Culture CultureInfo Culture used to show and read the number, such as fr-FR . Defaults to the format culture of the locale in effect (the regional current culture when it has the same language). The posted value is always invariant.
Disabled bool false Disables the control: it cannot be focused or changed and is not submitted.
Id string The id of the native control. Defaults to the one of the enclosing KlyFormField , else a generated one.
Max Decimal? Largest value accepted. There is no upper limit when it is null.
Min Decimal? Smallest value accepted. There is no lower limit when it is null. A decimal whatever the bound type, so Min="0" works for an int , a float or a decimal? .
Name string Form field name outside an EditForm . Inside one, the name comes from the bound expression.
Orientation KlyOrientation KlyOrientation.Horizontal Horizontal puts the buttons on both sides of the field, vertical stacks them at its end. Values: Horizontal, Vertical.
Placeholder string Hint shown while the field is empty.
Required bool false Marks the control as required, for the browser and for assistive technology.
Size KlySize? Defaults to the size of the enclosing KlyFormField , or medium. Values: Xs, Sm, Md, Lg, Xl.
Step Decimal Amount added or removed by the buttons and the arrow keys; Page Up and Page Down use ten steps.
Ui InputNumberUi Per-instance class overrides of the slots of the input number, see InputNumberUi . They are merged after the theme and the Class parameter wins on the root slot.
Value (@bind-Value) TNumber The value of the control. Bind it with @bind-Value .
ValueExpression Expression<Func<TNumber>> The expression of the bound field. The compiler sets it with @bind-Value , and validation uses it to find the field.
Variant FieldVariant FieldVariant.Outline Look of the field: Outline , Soft , Subtle , Ghost or None . Values: Outline, Soft, Subtle, Ghost, None.

Ui slots

Ui takes a InputNumberUi with one class string per slot, merged after the theme.

Slot Styles
Root Classes merged into the root slot of KlyInputNumber`1 , after the theme and the app configuration.
Base Classes merged into the base slot of KlyInputNumber`1 , after the theme and the app configuration.
Decrement Classes merged into the decrement slot of KlyInputNumber`1 , after the theme and the app configuration.
Increment Classes merged into the increment slot of KlyInputNumber`1 , after the theme and the app configuration.
Icon Classes merged into the icon slot of KlyInputNumber`1 , after the theme and the app configuration.