|
| 1 | +--- |
| 2 | +title: Readonly RadioGroup |
| 3 | +description: Learn how to make the Telerik RadioGroup for Blazor readonly without graying out the text. |
| 4 | +type: how-to |
| 5 | +page_title: How to Customize Telerik RadioGroup for Blazor to Be Readonly Without Graying Out |
| 6 | +meta_title: How to Customize Telerik RadioGroup for Blazor to Be Readonly Without Graying Out |
| 7 | +slug: radiogroup-kb-readonly |
| 8 | +tags: radiogroup, blazor, readonly |
| 9 | +res_type: kb |
| 10 | +ticketid: 1690650 |
| 11 | +--- |
| 12 | + |
| 13 | +## Environment |
| 14 | + |
| 15 | +<table> |
| 16 | + <tbody> |
| 17 | + <tr> |
| 18 | + <td>Product</td> |
| 19 | + <td>RadioGroup for Blazor</td> |
| 20 | + </tr> |
| 21 | + </tbody> |
| 22 | +</table> |
| 23 | + |
| 24 | +## Description |
| 25 | + |
| 26 | +I want to make the [RadioGroup](slug:radiogroup-overview) readonly but keep the text visually clear (not grayed out). Using the `Enabled` property disables the input entirely but also makes the text and radio buttons gray, which reduces readability. |
| 27 | + |
| 28 | +## Solution |
| 29 | + |
| 30 | +To make the TelerikRadioGroup readonly without graying out the text, use the following CSS approach: |
| 31 | + |
| 32 | +````Razor |
| 33 | +<style> |
| 34 | + .k-radio-list li .k-radio-wrap { |
| 35 | + pointer-events: none; /* Prevents mouse interactions */ |
| 36 | + opacity: 0.5; /* Makes it look visually disabled */ |
| 37 | + cursor: not-allowed; |
| 38 | + } |
| 39 | +
|
| 40 | + .k-radio-list li label { |
| 41 | + pointer-events: none; /* Prevents mouse interactions */ |
| 42 | + cursor: not-allowed; |
| 43 | + } |
| 44 | +</style> |
| 45 | +
|
| 46 | +Chosen delivery method: @(ChosenDeliveryMethod == 0 ? "no selection yet" : ChosenDeliveryMethod.ToString()) |
| 47 | +<br /> |
| 48 | +
|
| 49 | +<TelerikRadioGroup Data="@DeliveryOptions" |
| 50 | + @bind-Value="@ChosenDeliveryMethod" |
| 51 | + ValueField="@nameof(DeliveryMethodModel.MethodId)" |
| 52 | + TextField="@nameof(DeliveryMethodModel.MethodText)"> |
| 53 | +</TelerikRadioGroup> |
| 54 | +
|
| 55 | +@code { |
| 56 | + private int ChosenDeliveryMethod { get; set; } |
| 57 | +
|
| 58 | + private List<DeliveryMethodModel> DeliveryOptions { get; set; } = new List<DeliveryMethodModel> |
| 59 | + { |
| 60 | + new DeliveryMethodModel { MethodId = 1, MethodText = "Standard Shipping" }, |
| 61 | + new DeliveryMethodModel { MethodId = 2, MethodText = "Express Shipping" }, |
| 62 | + new DeliveryMethodModel { MethodId = 3, MethodText = "In-Store Pickup" }, |
| 63 | + new DeliveryMethodModel { MethodId = 4, MethodText = "Curbside Pickup" }, |
| 64 | + }; |
| 65 | +
|
| 66 | + public class DeliveryMethodModel |
| 67 | + { |
| 68 | + public int MethodId { get; set; } |
| 69 | + public string MethodText { get; set; } |
| 70 | + } |
| 71 | +} |
| 72 | +```` |
| 73 | + |
| 74 | +## See Also |
| 75 | + |
| 76 | +* [RadioGroup Documentation](slug:radiogroup-overview) |
| 77 | +* [CSS pointer-events Property](https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events) |
| 78 | +* [RadioGroup Binding](slug:radiogroup-databind) |
0 commit comments