|
| 1 | +--- |
| 2 | +title: Disabling 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 | +When using the NumericTextBox with arrows enabled, 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 the increase/decrease arrows of the NumericTextBox from being used when the numeric value reaches its minimum or maximum, 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 | +````CSHTML |
| 39 | +<style> |
| 40 | + .disable-increase .k-spinner-increase, |
| 41 | + .disable-decrease .k-spinner-decrease { |
| 42 | + pointer-events: none; |
| 43 | + opacity: 0.5; |
| 44 | + } |
| 45 | +</style> |
| 46 | +
|
| 47 | +<TelerikNumericTextBox @bind-Value="@theValue" |
| 48 | + Min="@minValue" |
| 49 | + Max="@maxValue" |
| 50 | + Class="@numericClass" |
| 51 | + Width="300px"> |
| 52 | +</TelerikNumericTextBox> |
| 53 | +
|
| 54 | +@code { |
| 55 | + private int theValue { get; set; } = 3; |
| 56 | + private int minValue { get; set; } = 1; |
| 57 | + private int maxValue { get; set; } = 10; |
| 58 | +
|
| 59 | + private string numericClass => $"disable-arrows {(theValue == maxValue ? "disable-increase" : "")} {(theValue == minValue ? "disable-decrease" : "")}"; |
| 60 | +} |
| 61 | +```` |
| 62 | + |
| 63 | +## See Also |
| 64 | + |
| 65 | +* [NumericTextBox Overview](https://docs.telerik.com/blazor-ui/components/numerictextbox/overview) |
| 66 | +* [Override the Theme or Apply Custom CSS Styles]({%slug themes-override%}) |
0 commit comments