How to Limit TextArea AutoSize and Show Scrollbar
Environment
Product | TextArea for Blazor |
Description
This KB article answers the following questions:
- How to limit the TextArea auto size area and have a scrollbar when the component needs to expand more.
- How to use the TextArea's
AutoSize
up to a point, and have a vertical scrollbar if the text grows beyond that. - How to make the
TelerikTextArea
show a scrollbar if a max height is hit.
Solution
- Set a
Class
to the TextArea. - Apply a
max-height
style andoverflow-y: auto !important;
to thetextarea
children of the CSS class from the previous step.
<TelerikTextArea @bind-Value="@TextValue"
Width="500px"
ResizeMode="TextAreaResizeMode.Auto"
Class="max-height-200" />
<style>
.max-height-200 > textarea {
max-height: 200px;
overflow-y: auto !important;
}
</style>
@code {
private string TextValue { get; set; } = string.Empty;
}
Use
AutoSize="true"
instead ofResizeMode="TextAreaResizeMode.Auto"
with Telerik UI for Blazor versions6.x
and earlier.