Skip to content

Comments

MudDatePicker: Fix keyboard navigation with fixed year/month#12180

Merged
danielchalmers merged 18 commits intoMudBlazor:devfrom
spingee:feature/datepicker_key_nav
Jan 11, 2026
Merged

MudDatePicker: Fix keyboard navigation with fixed year/month#12180
danielchalmers merged 18 commits intoMudBlazor:devfrom
spingee:feature/datepicker_key_nav

Conversation

@spingee
Copy link
Contributor

@spingee spingee commented Nov 30, 2025

Hello,
This is followup for this PR #12028 , it was merged too fast :).
I fixed issue when it was able to move weird state with fixed year/month with keyboard nav.
Also updated docs with info about keyboard shortcuts

@mudbot mudbot bot changed the title Datepicker keyboard navigation followup MudDatePicker: Fix keyboard navigation with fixed year/month Nov 30, 2025
@mudbot mudbot bot added accessibility Accessibility concerns (ARIA, keyboard, focus, screen readers, contrast) bug Unexpected behavior or functionality not working as intended docs Updates/improvements to project documentation that do not affect core library logic tests Updates tests or test infrastructure and there are no changes the main library labels Nov 30, 2025
@danielchalmers danielchalmers removed docs Updates/improvements to project documentation that do not affect core library logic tests Updates tests or test infrastructure and there are no changes the main library labels Nov 30, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes keyboard navigation issues in MudDatePicker when FixYear or FixMonth parameters are set, ensuring these constraints are respected during keyboard interactions. It also adds comprehensive accessibility documentation for keyboard shortcuts.

Key changes:

  • Added guard checks in navigation methods (MoveToNextYear, MoveToPreviousYear, MoveToNextMonth, MoveToPreviousMonth) to prevent changes when year/month are fixed
  • Refactored duplicate month navigation logic by adding parameters to existing methods
  • Added test coverage for FixYear and FixMonth keyboard navigation scenarios
  • Documented all keyboard shortcuts in an accessibility section

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
MudDatePicker.cs Added FixYear/FixMonth guards to navigation methods and refactored month navigation to accept step parameter
DatePickerTests.cs Added tests verifying keyboard navigation respects FixYear and FixMonth constraints
DatePickerPage.razor Added accessibility section documenting keyboard shortcuts (with some documentation errors)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 206 to 212
<td>Increment month/date in respective view</td>
</tr>
<tr>
<td>
<CodeInline>ArrowRight</CodeInline>
</td>
<td>Decrement month/date in respective view</td>
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The descriptions for ArrowLeft and ArrowRight are swapped. Based on the code:

  • ArrowLeft decrements (moves to previous day/month)
  • ArrowRight increments (moves to next day/month)

The descriptions should be:

  • ArrowLeft: "Decrement month/date in respective view"
  • ArrowRight: "Increment month/date in respective view"
Suggested change
<td>Increment month/date in respective view</td>
</tr>
<tr>
<td>
<CodeInline>ArrowRight</CodeInline>
</td>
<td>Decrement month/date in respective view</td>
<td>Decrement month/date in respective view</td>
</tr>
<tr>
<td>
<CodeInline>ArrowRight</CodeInline>
</td>
<td>Increment month/date in respective view</td>

Copilot uses AI. Check for mistakes.
Comment on lines 230 to 236
<td>Increment month in date view</td>
</tr>
<tr>
<td>
<CodeInline>Shift+ArrowRight</CodeInline>
</td>
<td>Decrement month in date view</td>
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The descriptions for Shift+ArrowLeft and Shift+ArrowRight are swapped. Based on the code:

  • Shift+ArrowLeft moves to previous month
  • Shift+ArrowRight moves to next month

The descriptions should be:

  • Shift+ArrowLeft: "Decrement month in date view"
  • Shift+ArrowRight: "Increment month in date view"
Suggested change
<td>Increment month in date view</td>
</tr>
<tr>
<td>
<CodeInline>Shift+ArrowRight</CodeInline>
</td>
<td>Decrement month in date view</td>
<td>Decrement month in date view</td>
</tr>
<tr>
<td>
<CodeInline>Shift+ArrowRight</CodeInline>
</td>
<td>Increment month in date view</td>

Copilot uses AI. Check for mistakes.

private void MoveToPreviousMonth()
private void MoveToPreviousMonth(int numberOfMonths = 1)

Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the extra blank line between the method signature and the opening brace for consistency with the rest of the codebase.

Suggested change

Copilot uses AI. Check for mistakes.
var datePicker = datePickerComponent.Instance;
await comp.InvokeAsync(() => datePicker.OnHandleKeyDownAsync(new KeyboardEventArgs() { Key = "Enter", Type = "keydown", }));
comp.WaitForAssertion(() => comp.FindAll("div.mud-picker-open").Count.Should().Be(1));
//try to select month outside fixed year in date view
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment mentions "fixed year" but the test is for FixMonth. The comment should say "try to select month outside fixed month in date view" to accurately describe what the test is checking.

Suggested change
//try to select month outside fixed year in date view
//try to select month outside fixed month in date view

Copilot uses AI. Check for mistakes.
@ScarletKuro
Copy link
Member

ScarletKuro commented Nov 30, 2025

P.S. not to merge before #12177

@danielchalmers danielchalmers added the on hold Waiting until an external factor or future milestone (e.g., major release) is reached label Nov 30, 2025
@ScarletKuro ScarletKuro removed the on hold Waiting until an external factor or future milestone (e.g., major release) is reached label Dec 3, 2025
@danielchalmers
Copy link
Member

Hi @spingee, could you take another look with Copilot's feedback and merge conflicts?

@spingee
Copy link
Contributor Author

spingee commented Dec 6, 2025

@danielchalmers Hello, done

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…razor

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So looking at these tests they execute (Act) repeatedly but we only check at the end. Also we should align the tests to act on the DOM instead of just executing the method. like the following. You will see I used the Id for easy targetting and since the PopoverProvider is included inside the test razor I don't have to render it as a component as well. You should be able to inputElement.KeyDownAsync just like you was before and verify what it's supposed to do. And what happens when enter is pressed etc. You need to be able to verify via the dom so we protect the logic, not just that one method if fired probably works. Lastly if you want to read a parameter on a comp.Instance it is best to read it from the Dom. If it's parameter state and you must read it then use comp.Instance.GetState(x => x.parameter)

            var startDate = new DateTime(2022, 12, 31, new CultureInfo("en-US").Calendar);
            var comp = Context.Render<SimpleMudDatePickerTest>(parameters => parameters
                .Add(x => x.Date, startDate)
                .Add(x => x.OpenTo, OpenTo.Month)
                .Add(x => x.InputId, "datePickerTest_FixYear_Id")
                .Add(x => x.FixYear, 2022));
            
            var inputElement = comp.WaitForElement("#datePickerTest_FixYear_Id");
            // activate picker popover
            await inputElement.KeyDownAsync(new KeyboardEventArgs() { Key = "Enter", Type = "keydown" });
            var pop = comp.WaitForElement("div.mud-picker-popover");
            comp.WaitForAssertion(() => pop.ClassList.Should().Contain("mud-popover-open"));
            // starts with nothing selected
            comp.FindAll("button.mud-picker-calendar-day.mud-selected").Count.Should().Be(0);            
            //try to select year outside fixed year in month view

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@versile2 Hello this approach doesnt work, sending keydown directly on input, OnKeydownHandler does not get called.
It maybe because event bubbling is perhaps not supported in bunit or involment of keyinterceptor

await KeyInterceptorService.SubscribeAsync(_elementId, options, keyDown: OnHandleKeyDownAsync);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Push your changes and I'll check it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@versile2 pushed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. Yes this binding is pushed by KeyInterceptor and cannot be tested that way, revert your test to the way you had it. Best we can get.

spingee and others added 3 commits December 13, 2025 15:53
…razor

Co-authored-by: Versile Johnson II <148913404+versile2@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@versile2
Copy link
Contributor

@spingee The two comments from copilot about the math, I looked at it very briefly, Thoughts?

@ScarletKuro
Copy link
Member

ScarletKuro commented Dec 19, 2025

Need to address the failing test (versile said to revert the testing) and fix or comment the copilot concerns. Then this can be merged, since overall it looks good.

@spingee
Copy link
Contributor Author

spingee commented Dec 19, 2025

@spingee The two comments from copilot about the math, I looked at it very briefly, Thoughts?

I will look at it tomorrow

@spingee
Copy link
Contributor Author

spingee commented Dec 21, 2025

@versile2 resolved copilot reviews, also reverted commit with temporary dom level keydown failing test, as there was no response from you

@danielchalmers danielchalmers merged commit c3cb822 into MudBlazor:dev Jan 11, 2026
6 checks passed
@danielchalmers
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility Accessibility concerns (ARIA, keyboard, focus, screen readers, contrast) bug Unexpected behavior or functionality not working as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants