From 36a00758bd37c2db6f728e19ccf4570bcddfdc10 Mon Sep 17 00:00:00 2001 From: KB Bot Date: Fri, 12 Dec 2025 09:24:46 +0000 Subject: [PATCH] Added new kb article datepicker-select-all-content-on-focus --- .../datepicker-select-all-content-on-focus.md | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 knowledge-base/datepicker-select-all-content-on-focus.md diff --git a/knowledge-base/datepicker-select-all-content-on-focus.md b/knowledge-base/datepicker-select-all-content-on-focus.md new file mode 100644 index 000000000..cf143eb74 --- /dev/null +++ b/knowledge-base/datepicker-select-all-content-on-focus.md @@ -0,0 +1,88 @@ +--- +title: How to Select All Content in DatePicker on Focus +description: Learn how to ensure the entire content of the DatePicker input is selected on focus. +type: how-to +page_title: Automatically Select All Text in DatePicker Input on Focus +meta_title: Automatically Select All Text in DatePicker Input on Focus +slug: datepicker-kb-select-all-content-on-focus +tags: datepicker, focus, input, selection +res_type: kb +ticketid: 1704388 +--- + +## Environment + + + + + + + + +
ProductDatePicker for Blazor
+ +## Description + +I want the entire content of the [Telerik DatePicker](slug:components/datepicker/overview) input to be automatically selected when focused, allowing users to copy-paste dates directly. + +## Solution + +To ensure the entire input content is selected on focus and the popup calendar remains functional, follow these steps: + +1. Hide the default calendar button using CSS. +2. Add a custom button for opening the popup calendar. +3. Utilize the [`FocusAsync`](slug:components/datepicker/overview#datepicker-reference-and-methods) and a JavaScript function to select all text in the input. + +Here is the complete implementation: + +````Razor +@inject IJSRuntime JS + + + + + + + + + + +@code { + private TelerikDatePicker DatePickerRef { get; set; } + private DateTime DatePickerValue { get; set; } = DateTime.Now; + + private void OpenPicker() + { + DatePickerRef?.Open(); + } + + private async Task FocusAndSelect() + { + await DatePickerRef.FocusAsync(); + + // wait a moment so the input renders focus + await Task.Delay(20); + + await JS.InvokeVoidAsync("selectDatePickerInput"); + } +} +```` + +## See Also + +* [DatePicker Documentation](slug:components/datepicker/overview) +* [FocusAsync Method](slug:components/datepicker/overview#datepicker-reference-and-methods)