Skip to content

MudBaseDatePicker: Ensure GetMonthStart always returns the first day of the month#12386

Merged
ScarletKuro merged 1 commit intoMudBlazor:devfrom
pwasilewski:fix/GetMonthStart-always-return-first-of
Jan 6, 2026
Merged

MudBaseDatePicker: Ensure GetMonthStart always returns the first day of the month#12386
ScarletKuro merged 1 commit intoMudBlazor:devfrom
pwasilewski:fix/GetMonthStart-always-return-first-of

Conversation

@pwasilewski
Copy link
Contributor

@pwasilewski pwasilewski commented Jan 4, 2026

Description
When PickerMonth was set to a date that was not the first day of the month (for example 2026-02-15), the calendar grid could render incorrectly, because the component treated that mid-month date as the “start” used to compute the month view. The result was a broken layout where only the trailing part of the month could appear (as shown in the screenshot).

image

Root cause
GetMonthStart did not normalize the provided PickerMonth to the first day of the month. It preserved the day-of-month from the PickerMonth, which meant downstream calendar calculations were anchored to the wrong day.

Fix
GetMonthStart now always returns a DateTime on day 1 for the computed year and month (still respecting the active culture/calendar and using DateTimeKind.Utc). This ensures the month view is always computed from a proper month boundary, regardless of what day PickerMonth is set to.

Resolves: #11777

Checklist:

  • I've read the contribution guidelines
  • My code follows the style of this project
  • I've added or updated relevant unit tests

Ensure GetMonthStart always returns the first day of the month.
Add unit test to verify PickerMonth normalization to day 1.
@mudbot mudbot bot added the bug Unexpected behavior or functionality not working as intended label Jan 4, 2026
@danielchalmers danielchalmers added the localization Translations, locale formats, RTL layout, calendars label Jan 4, 2026
@ScarletKuro ScarletKuro merged commit 63c0396 into MudBlazor:dev Jan 6, 2026
7 checks passed
@ScarletKuro
Copy link
Member

Hmmm on my machine this test keeps failing.

@ScarletKuro
Copy link
Member

Yeah, because on my machine it's:
Screenshot 2026-01-06 181603
The "--day-id: 1;" will be "26" in my case

@pwasilewski
Copy link
Contributor Author

Arf! Indeed, I should have force a "fr-BE" or "en" culture on this test.
Do you want me to create a fix in +/-30min?

@ScarletKuro
Copy link
Member

I guess i will just add FirstDayOfWeek="@FirstDayOfWeek" to SimpleMudDatePickerTest and set it

var comp = OpenPicker(parameters => parameters
                .Add(x => x.PickerMonth, new DateTime(2026, 2, 15))
                .Add(x => x.FirstDayOfWeek, DayOfWeek.Sunday));

instead of the culture approach

@pwasilewski
Copy link
Contributor Author

Oh yeah that's even cleaner! Sorry for introducing an issue.

@pwasilewski
Copy link
Contributor Author

pwasilewski commented Jan 6, 2026

I’m still looking into this. SimpleMudDatePickerTest forces the culture, which makes it hard for me to reason about this issue.

One idea would be to change the test to assert the rendered result instead of relying on culture. Rather than forcing a culture or FirstDayOfWeek, we could check that the picker renders the expected number of visible days for the month.

For example:

[Test]
public void GetMonthStart_Should_NormalizeToFirstDayOfMonth()
{
    var testDateTime = new DateTime(2026, 2, 15);

    var comp = OpenPicker(parameters => parameters
        .Add(x => x.PickerMonth, testDateTime));

    var visibleDaysCount = comp
        .FindAll(".mud-button-root.mud-icon-button.mud-ripple.mud-ripple-icon.mud-picker-calendar-day.mud-day:not(.mud-hidden)")
        .Count;

    visibleDaysCount.Should().Be(DateTime.DaysInMonth(testDateTime.Year, testDateTime.Month));
}

This way the test just checks that all days of the month are rendered, regardless of culture.

@ScarletKuro
Copy link
Member

ScarletKuro commented Jan 6, 2026

Yeah, that's also a good idea, but I already implemented the fix in other PR with the DayOfWeek.Sunday .
There is another bug related with the FirstDayOfWeek.
If you open the editable picker at 01/01/0001 when FirstDayOfWeek=DayOfWeek.Monday you will see "6" twice on Sunday and Saturday, but if you open DayOfWeek.Sunday then its ok. Apparently this is some ancient bug. If you want, you can look at it.

This was referenced Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unexpected behavior or functionality not working as intended localization Translations, locale formats, RTL layout, calendars

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MudDatePicker: Incomplete month view when PickerMonth property is set

3 participants