Skip to content

Commit 5a52adc

Browse files
Tsvetomir-Hrradkostanev
authored andcommitted
docs(DateRangePicker): add kb for daterangepicker customization
1 parent 94f99d7 commit 5a52adc

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: How to Customize the DateRangePicker
3+
description: Learn how to enhance the Blazor DateRangePicker by customizing its styling, disabling weekends, reducing the width of DateInputs, preventing horizontal expansion, hiding Start and End labels, and making the component more compact for better user experience and design consistency in your application.
4+
type: how-to
5+
page_title: How to Customize the DateRangePicker
6+
slug: daterangepicker-kb-css-customization
7+
tags: daterangepicker, styling
8+
ticketid: 1633582
9+
res_type: kb
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>DateRangePicker for Blazor</td>
19+
</tr>
20+
</tbody>
21+
</table>
22+
23+
## Description
24+
25+
This KB article answers the following questions:
26+
27+
* How to customize the Blazor DateRangePicker styling?
28+
* How to make weekends disabled in the DateRangePicker component?
29+
* How to reduce the width of the two DateInputs?
30+
* How to prevent horizontal expansion of the DateRangePicker?
31+
* How to hide the Start and End labels of the DateRangePicker?
32+
* How to make the DateRangePicker more compact?
33+
34+
## Solution
35+
36+
1. Use a `Class` parameter and custom CSS to override our theme and hide the labels (**.k-floating-label**). Note that If it is used **display:none**, it violates the accessibility compliance. Instead, use **font-size:0** for example.
37+
2. Override the default width of **10em** of the two `DateInputs` (**.k-dateinput**).
38+
3. Change the display of the element to inline with **display:inline-flex** to prevent the horizontal expansion of the component.
39+
4. Set the **padding-top: 0** of the **.k-floating-label-container** to remove reserved space and make the `DateRangePicker` more compact.
40+
41+
>caption Customized Blazor DateRangePicker
42+
43+
````CSHTML
44+
<span style="display:inline-block;border: 1px solid red;">
45+
<TelerikDateRangePicker @bind-StartValue="@StartValue"
46+
@bind-EndValue="@EndValue"
47+
Format="yyyy-MM-dd"
48+
Min="@Min" Max="@Max"
49+
Class="no-labels smaller-width"
50+
PopupClass="no-weekends">
51+
</TelerikDateRangePicker>
52+
</span>
53+
54+
<style>
55+
/* remove reserved space for labels */
56+
.no-labels .k-floating-label-container {
57+
padding-top: 0;
58+
}
59+
60+
/* hide labels */
61+
.no-labels .k-floating-label {
62+
font-size: 0;
63+
color: transparent;
64+
}
65+
66+
/* prevent horizontal expansion */
67+
span.smaller-width {
68+
display: inline-flex;
69+
width: min-content;
70+
}
71+
72+
/* reduce textbox width */
73+
span.smaller-width .k-dateinput {
74+
width: 7em;
75+
}
76+
77+
/* make weekends disabled */
78+
.no-weekends .k-calendar-td[title*="Saturday"],
79+
.no-weekends .k-calendar-td[title*="Sunday"] {
80+
color: #424242;
81+
opacity: .6;
82+
pointer-events: none;
83+
}
84+
85+
</style>
86+
87+
@code {
88+
private DateTime? StartValue { get; set; }
89+
private DateTime? EndValue { get; set; }
90+
91+
private DateTime Min = DateTime.Today.AddYears(-200);
92+
private DateTime Max = DateTime.Today.AddYears(100);
93+
}
94+
````
95+
96+
## See Also
97+
* [DateRangePicker Overview]({%slug daterangepicker-overview%})

0 commit comments

Comments
 (0)