Setting both a View and DateRangeChanged Parameter affects the view switch control
Closed this issue · 4 comments
To reproduce:
<MudCalendar View="CalendarView.Week" DateRangeChanged="DateRangeChanged" />
@code {
private void DateRangeChanged(DateRange dateRange}
{
// Code here
}
}
The page will load with the calendar showing the week view
Change the view by clicking on month or day
Expected: The view changes to the appropriate month/day view
Actual: The view doesn't change until you click a second time
Not a fix but a workaround:
<MudCalendar @ref="calendar"/>
@code {
private MudCalendar calendar;
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
calendar.View = CalendarView.Week;
}
}
A tried that workaround but it still isn't a complete fix. The buttons in the upper right corner don't update. Click on "Month", the calendar updates, but the Week button is still Variant.Filled, while the others are Variant.Outlined.
Using View="CalendarView.Week"
is not the correct way to set a default value in Blazor. The problem is that you are always trying to set the view to Week.
When you click the Month or Day button the component is changing to that view but then your code is immediately changing it back to Week.
You can set a default value like this:
<MudCalendar @bind-View="_view" />
@code {
private CalendarView _view = CalendarView.Week;
}
Removing the 'bug' label because I don't think it's a bug.
Thank you. That fixed it for me.