Skip to content

MudAutocomplete: OpenChanged called twice after selection#11985

Merged
danielchalmers merged 2 commits intoMudBlazor:devfrom
Yomodo:Fix_MudAutocomplete_Multiple_OpenChanged
Nov 1, 2025
Merged

MudAutocomplete: OpenChanged called twice after selection#11985
danielchalmers merged 2 commits intoMudBlazor:devfrom
Yomodo:Fix_MudAutocomplete_Multiple_OpenChanged

Conversation

@Yomodo
Copy link
Contributor

@Yomodo Yomodo commented Oct 21, 2025

After item selection MudAutocomplete currently calls the OpenChanged event twice
which might affect the workings of user-code unexpectedly.
Additionally:
-It sometimes causes UI flicker as the list is quickly opened and closed.
-UI flickering can occur when Autocomplete's Clear adornment is clicked.

Fixes #11974

Checklist:

  • The PR is submitted to the correct branch (dev).
  • My code follows the style of this project.
  • I've added relevant tests or confirmed existing ones.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively resolves the issue of the autocomplete list being briefly visible after a selection. The change in MudAutocomplete.razor.cs to directly manipulate the _open backing field within SelectOptionAsync is a precise and correct way to prevent multiple OpenChanged events from firing, which was the root cause of the UI flicker. The addition of the AutocompleteOpenChangedTest component and the associated unit tests in AutocompleteTests.cs is excellent, as it provides solid verification for the fix and covers various scenarios, ensuring the component's behavior is now correct and stable. The code is clean, the change is minimal and targeted, and the test coverage is appreciated.

@versile2
Copy link
Contributor

I have questions, not sure who is right to answer them.

This PR needs more information in the open description, just Resolves isn't good enough to glance for reason etc.

It is purposeful and intentional for the current behavior as indicated by the comment. Do we know who put that in and why? I wish they had put in a test or an issue to link.

@versile2
Copy link
Contributor

@digitaldirk Look at his unit test, it's a good way to test the selection after you verify focus

@mudbot mudbot bot added the bug Unexpected behavior or functionality not working as intended label Oct 23, 2025
@Yomodo Yomodo changed the title MudAutocomplete: Fix list briefly visible after selection MudAutocomplete: OpenChanged called twice after selection Oct 25, 2025
@mudbot mudbot bot added the needs: info This issue/PR lacks key context (goal, setup, environment) label Oct 25, 2025
@Yomodo
Copy link
Contributor Author

Yomodo commented Oct 28, 2025

@versile2 I've added to the description what this PR fixes.
I'm unable to answer your questions but I do hope this PR will get approved and merged.

@mudbot mudbot bot removed the needs: info This issue/PR lacks key context (goal, setup, environment) label Oct 28, 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 an issue where the OpenChanged event was being triggered multiple times during item selection in the MudAutocomplete component. The fix modifies SelectOptionAsync to directly manipulate the backing _open field instead of using the Open property, which prevents unnecessary OpenChanged event invocations.

Key Changes:

  • Modified SelectOptionAsync to use _open field directly instead of Open property for internal state changes
  • Added comprehensive unit tests to verify OpenChanged event is raised exactly once per open/close operation
  • Created test component to track OpenChanged event counts

Reviewed Changes

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

File Description
MudAutocomplete.razor.cs Changed lines 553 and 558 to use _open field instead of Open property to prevent multiple OpenChanged events
AutocompleteTests.cs Added four new test cases to verify OpenChanged event behavior with various operations
AutocompleteOpenChangedTest.razor New test component that tracks OpenChanged event counts for validation

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

Copy link
Contributor

@versile2 versile2 left a comment

Choose a reason for hiding this comment

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

The code is fine, and the last unit test fails before this code is included so there should be a test protecting it now. I still worry just a hair about why it was put in but it's a simple change.

@danielchalmers danielchalmers removed the request for review from Mr-Technician October 31, 2025 17:11
@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

bug Unexpected behavior or functionality not working as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MudAutocomplete: After selection list is briefly opened and closed

4 participants