danheron / Heron.MudCalendar

Calendar component for MudBlazor
MIT License
174 stars 33 forks source link

Setting both a View and DateRangeChanged Parameter affects the view switch control #64

Closed traseedarkwatch closed 1 year ago

traseedarkwatch commented 1 year ago

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

MinZe25 commented 1 year ago

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;
    }
}
traseedarkwatch commented 1 year ago

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.

danheron commented 1 year ago

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.

traseedarkwatch commented 1 year ago

Thank you. That fixed it for me.