Skip to content

Commit 90802cf

Browse files
GioviQmckaragoz
andauthored
MudDateWheelPicker fix (#64)
* fix #63 * MudDateWheelPicker example update * Select Last Day If Needed Co-authored-by: mckaragoz <[email protected]>
1 parent c30a612 commit 90802cf

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

CodeBeam.MudExtensions/Components/DateWheelPicker/MudDateWheelPicker.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@
4343
@if (yearIndex < dayIndex)
4444
{
4545
<MudWheel Class="mud-width-full" @bind-Value="_year" ItemCollection="Years" Sensitivity="@Sensitivity" Label="@(ShowHeader ? LocalizedStrings.Year : null)" Dense="@Dense" Color="@Color" Disabled="FixYear" />
46-
<MudWheel Class="mud-width-full" @bind-Value="_month" ItemCollection="Months" Sensitivity="@Sensitivity" Label="@(ShowHeader ? LocalizedStrings.Month : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@Color" Disabled="FixMonth" />
46+
<MudWheel Class="mud-width-full" Value="_month" ValueChanged=@((int m) => OnMonthChanged(m)) ItemCollection="Months" Sensitivity="@Sensitivity" Label="@(ShowHeader ? LocalizedStrings.Month : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@Color" Disabled="FixMonth" />
4747
<MudWheel Class="mud-width-full" @bind-Value="_day" ItemCollection="Days" Sensitivity="@Sensitivity" Label="@(ShowHeader ? LocalizedStrings.Day : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@Color" Disabled="FixDay" />
4848
}
4949
else if (monthIndex < dayIndex && dayIndex < yearIndex )
5050
{
51-
<MudWheel Class="mud-width-full" @bind-Value="_month" ItemCollection="Months" Sensitivity="@Sensitivity" Label="@(ShowHeader ? LocalizedStrings.Month : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@Color" Disabled="FixMonth" />
51+
<MudWheel Class="mud-width-full" Value="_month" ValueChanged=@((int m) => OnMonthChanged(m)) ItemCollection="Months" Sensitivity="@Sensitivity" Label="@(ShowHeader ? LocalizedStrings.Month : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@Color" Disabled="FixMonth" />
5252
<MudWheel Class="mud-width-full" @bind-Value="_day" ItemCollection="Days" Sensitivity="@Sensitivity" Label="@(ShowHeader ? LocalizedStrings.Day : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@Color" Disabled="FixDay" />
5353
<MudWheel Class="mud-width-full" @bind-Value="_year" ItemCollection="Years" Sensitivity="@Sensitivity" Label="@(ShowHeader ? LocalizedStrings.Year : null)" Dense="@Dense" Color="@Color" Disabled="FixYear" />
5454
}
5555
else
5656
{
5757
<MudWheel Class="mud-width-full" @bind-Value="_day" ItemCollection="Days" Sensitivity="@Sensitivity" Label="@(ShowHeader ? LocalizedStrings.Day : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@Color" Disabled="FixDay" />
58-
<MudWheel Class="mud-width-full" @bind-Value="_month" ItemCollection="Months" Sensitivity="@Sensitivity" Label="@(ShowHeader ? LocalizedStrings.Month : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@Color" Disabled="FixMonth" />
58+
<MudWheel Class="mud-width-full" Value="_month" ValueChanged=@((int m) => OnMonthChanged(m)) ItemCollection="Months" Sensitivity="@Sensitivity" Label="@(ShowHeader ? LocalizedStrings.Month : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@Color" Disabled="FixMonth" />
5959
<MudWheel Class="mud-width-full" @bind-Value="_year" ItemCollection="Years" Sensitivity="@Sensitivity" Label="@(ShowHeader ? LocalizedStrings.Year : null)" Dense="@Dense" Color="@Color" Disabled="FixYear" />
6060
}
6161
}

CodeBeam.MudExtensions/Components/DateWheelPicker/MudDateWheelPicker.razor.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
using System;
2-
using System.Data;
3-
using System.Threading.Tasks;
4-
using MudExtensions.Utilities;
5-
using Microsoft.AspNetCore.Components;
1+
using Microsoft.AspNetCore.Components;
62
using Microsoft.AspNetCore.Components.Web;
7-
using Microsoft.Extensions.DependencyInjection;
83
using MudBlazor;
94
using MudBlazor.Utilities;
105
using MudExtensions.Enums;
11-
using static MudBlazor.CategoryTypes;
6+
using MudExtensions.Utilities;
127

138
namespace MudExtensions
149
{
@@ -300,6 +295,34 @@ protected void ToggleDateView()
300295
}
301296
}
302297

298+
private void RefreshDays()
299+
{
300+
var month = _month;
301+
var year = _year;
302+
var day = _day;
303+
304+
++month;
305+
306+
if (month == 13)
307+
{
308+
month = 1;
309+
++year;
310+
}
311+
312+
Days = Enumerable.Range(1, new DateTime(year, month, 1).AddDays(-1).Day).ToList();
313+
if (Days.Last() < _day)
314+
{
315+
_day = Days.Last();
316+
}
317+
}
318+
319+
private void OnMonthChanged(int month)
320+
{
321+
_month = month;
322+
323+
RefreshDays();
324+
}
325+
303326
protected void SetWheelValues()
304327
{
305328
if (Value == null)
@@ -312,6 +335,8 @@ protected void SetWheelValues()
312335
_hour = Value.Value.Hour;
313336
_minute = Value.Value.Minute;
314337
_second = Value.Value.Second;
338+
339+
RefreshDays();
315340
}
316341

317342
public override ValueTask FocusAsync()

ComponentViewer.Docs/Pages/Examples/DateWheelPickerExample1.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@
4545
</MudGrid>
4646

4747
@code {
48-
DateTime? _date = new DateTime(2000, 1, 1);
48+
DateTime? _date = DateTime.Now;
4949
DateView _dateView = DateView.Date;
5050
bool _editable = false;
5151
bool _showToolbar = false;
5252
bool _showHeader = false;
5353
bool _submitOnClose = true;
5454
Color _color;
5555
Color _colorTime = Color.Inherit;
56-
string _dateFormat = "dd.MM.yyyy";
56+
string _dateFormat = System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern;
5757
bool _fixYear;
5858
bool _fixMonth;
5959
bool _fixDay;

0 commit comments

Comments
 (0)