From 970d8e4a654e8d1223b5da64cc1ca0f85ac03a2c Mon Sep 17 00:00:00 2001 From: Joana Date: Wed, 19 Jan 2022 00:02:13 +0200 Subject: [PATCH] chore(kb): add kb for floating label --- knowledge-base/inputs-floating-label.md | 82 +++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 knowledge-base/inputs-floating-label.md diff --git a/knowledge-base/inputs-floating-label.md b/knowledge-base/inputs-floating-label.md new file mode 100644 index 0000000000..04e7941f46 --- /dev/null +++ b/knowledge-base/inputs-floating-label.md @@ -0,0 +1,82 @@ +--- +title: Add Floating Label to Telerik Inputs +description: How to add floating label in the Telerik Inputs. +type: how-to +page_title: Floating Label in Telerik Inputs +slug: inputs-kb-floating-label +position: +tags: +res_type: kb +--- + +## Environment + + + + + + + +
ProductTextBox for Blazor, MaskedTextBox for Blazor, NumericTextBox for Blazor, other inputs/form elements
+ + +## Description + +I would like to show a floating label for Telerik Inputs. The label should be displayed like a placeholder when the component is empty, and should animate to top label position of the input when focused. + +## Solution + +>important The 3.0.0 release introduced a breaking change of removing the `Label` parameter from TextBox, MaskedTextBox, TextArea components. In 3.2.0 Floating Label component will be released to fulfill all use cases. However, in the meantime this solution can be used to implement floating label in any component. + +The following code snippet shows how to add a floating label to TextBox, MaskedTextBox, TextArea, DatePicker, and DropDownList components. The example illustrates how with simple html rendering that is shipped with `Telerik UI for Blazor` you could transform the inner html label into a floating label. + +````CSHTML +
+ + + + +

+ + + + +

+ + + + +

+ + + + + +

+ + + + +
+ +@code { + public const string emptyClass = "k-state-empty"; + + public string TextBoxValue { get; set; } + public string TextBoxEmptyClass => string.IsNullOrEmpty(TextBoxValue) ? emptyClass : string.Empty; + + public string MaskedTextBoxValue { get; set; } + public string MaskedTextBoxEmptyClass => string.IsNullOrEmpty(MaskedTextBoxValue) ? emptyClass : string.Empty; + + public string TextAreaValue { get; set; } + public string TextAreaEmptyClass => string.IsNullOrEmpty(TextAreaValue) ? emptyClass : string.Empty; + + public DateTime? DatePickerValue { get; set; } + public string DatePickerEmptyClass => DatePickerValue == null ? emptyClass : string.Empty; + + public string DropDownListValue { get; set; } + public string DropDownListEmptyClass => string.IsNullOrEmpty(DropDownListValue) ? emptyClass : string.Empty; + public List DropDownListData { get; set; } = new List() { "one", "two", "three" }; +} + +```` \ No newline at end of file