|
| 1 | +--- |
| 2 | +title: Disable NumericTextBox Arrows at Min or Max Value in Blazor |
| 3 | +description: Learn how to programmatically disable the increase or decrease arrows of a NumericTextBox in Blazor when the value reaches its minimum or maximum limit. |
| 4 | +type: how-to |
| 5 | +page_title: How to Disable NumericTextBox Arrows on Min or Max Value in Blazor |
| 6 | +slug: numerictextbox-disable-arrows |
| 7 | +tags: numerictextbox, blazor, disable arrows, conditional styling |
| 8 | +res_type: kb |
| 9 | +ticketid: 1665216 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +<table> |
| 15 | + <tbody> |
| 16 | + <tr> |
| 17 | + <td>Product</td> |
| 18 | + <td>NumericTextBox for Blazor</td> |
| 19 | + </tr> |
| 20 | + </tbody> |
| 21 | +</table> |
| 22 | + |
| 23 | +## Description |
| 24 | + |
| 25 | +In a NumericTextBox with enabled arrows, I want to disable the down arrow programmatically at the component's minimum value to prevent looping to the maximum value. |
| 26 | + |
| 27 | +This KB article answers the following questions: |
| 28 | + |
| 29 | +- How can I disable the NumericTextBox increment and decrement buttons based on the value? |
| 30 | +- How can I conditionally disable the NumericTextBox arrows when reaching specified value limits? |
| 31 | + |
| 32 | +## Solution |
| 33 | + |
| 34 | +To prevent your end users from looping through the minimum and maximum values with the icnrease/decrease arrows of the NumericTextBox, apply a conditional CSS class to disable the buttons. |
| 35 | + |
| 36 | +The example below demonstrates how to conditionally render CSS styles to disable the increase or decrease arrows based on the current value of the NumericTextBox. |
| 37 | + |
| 38 | +>caption The Min and Max values should not match the default minimum and maximum values of the Value type. |
| 39 | +
|
| 40 | +````CSHTML |
| 41 | +<style> |
| 42 | + .disable-increase .k-spinner-increase, |
| 43 | + .disable-decrease .k-spinner-decrease { |
| 44 | + pointer-events: none; |
| 45 | + opacity: 0.5; |
| 46 | + } |
| 47 | +</style> |
| 48 | +
|
| 49 | +<TelerikNumericTextBox @bind-Value="@NumericValue" |
| 50 | + Min="@MinValue" |
| 51 | + Max="@MaxValue" |
| 52 | + Class="@NumericClass" |
| 53 | + Width="300px"> |
| 54 | +</TelerikNumericTextBox> |
| 55 | +
|
| 56 | +@code { |
| 57 | + private int NumericValue { get; set; } = 3; |
| 58 | + private int MinValue { get; set; } = 1; |
| 59 | + private int MaxValue { get; set; } = 10; |
| 60 | +
|
| 61 | + private string NumericClass => $"{(NumericValue == MaxValue ? "disable-increase" : "")} {(NumericValue == MinValue ? "disable-decrease" : "")}"; |
| 62 | +} |
| 63 | +```` |
| 64 | + |
| 65 | +## See Also |
| 66 | + |
| 67 | +* [NumericTextBox Overview](https://docs.telerik.com/blazor-ui/components/numerictextbox/overview) |
| 68 | +* [Override the Theme or Apply Custom CSS Styles]({%slug themes-override%}) |
0 commit comments