Example of Floating Label in ASP.NET MVC TextArea Control
This example demonstrates the floating label functionalities of the textarea control. Choose the corresponding floatLabel option from the property panel to update the floating label behaviour in textarea.
Float label type
@Html.UiTextArea("floatlabel", null, new UiTextAreaOptions { Label = "Enter your comments", FloatLabelType = UiFloatLabelType.Auto, Rows = 5 })
@Html.UiDropDownList("select", new UiDropDownListOptions { Width = "120px", Value = "Auto", OnChange = "floatLabelHandler", Items = ((IEnumerable<InputsDemoController.floatLabelValues>)ViewData["data"]).Select(f => new UiListItem(f.floatLabelValue, f.text)).ToList() })
<style>
.content-wrapper { width: 90%; margin: 0 auto; min-width: 185px; }
.content-wrapper .ta-row { padding: 12px 0; }
.content-wrapper .ta-cols { display: flex; gap: 24px; }
.content-wrapper .ta-cols > * { flex: 1 1 0; min-width: 0; }
.content-wrapper .ta-title { padding: 15px 0 0; font-weight: 700; }
.property-section .property-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.property-section .prop-input { width: 130px; padding: 4px 6px; border: 1px solid var(--ui-input-border); border-radius: var(--ui-radius); background: var(--ui-surface); color: var(--ui-text); font: inherit; }
.floatinglabel .ta-row { padding: 40px 0 0; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<div class="control-section floatinglabel">
<div class="content-wrapper">
<div class="ta-row">
@Html.UiTextArea("floatlabel", null, new UiTextAreaOptions { Label = "Enter your comments", FloatLabelType = UiFloatLabelType.Auto, Rows = 5 })
</div>
</div>
</div>
<div class="demo-property-panel property-section" title="Properties">
<div class="property-row"><span>Float label type</span> @Html.UiDropDownList("select", new UiDropDownListOptions { Width = "120px", Value = "Auto", OnChange = "floatLabelHandler", Items = ((IEnumerable<InputsDemoController.floatLabelValues>)ViewData["data"]).Select(f => new UiListItem(f.floatLabelValue, f.text)).ToList() })</div>
</div>
<script>
// Syncfusion: the list sets the float label type of the textarea
function floatLabelHandler(value) { if (value) { window.Lumen.get('floatlabel').setFloatLabelType(value); } }
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class TextAreaController : Controller
{
// The page is Views/TextArea/FloatingLabel.cshtml; it draws what ViewData holds.
public ActionResult FloatingLabel()
{
ViewData["data"] = new floatLabelValues().TextAreaModel();
return View();
}
public class floatLabelValues
{
public string text { get; set; }
public string floatLabelValue { get; set; }
public List<floatLabelValues> TextAreaModel()
{
List<floatLabelValues> list = new List<floatLabelValues>();
list.Add(new floatLabelValues { text = "Auto", floatLabelValue = "Auto" });
list.Add(new floatLabelValues { text = "Always", floatLabelValue = "Always" });
list.Add(new floatLabelValues { text = "Never", floatLabelValue = "Never" });
return list;
}
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
The floating label is used to float the placeholder text while the user enters text or focuses on the textarea element with a value. In this sample, the floating label behavior can be changed using the following options:
- Choose float label types either 'Never', 'Always', or 'Auto' to control the floating behavior of the placeholder text.