MudAutocomplete: OpenChanged called twice after selection#11985
MudAutocomplete: OpenChanged called twice after selection#11985danielchalmers merged 2 commits intoMudBlazor:devfrom
Conversation
There was a problem hiding this comment.
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.
|
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. |
|
@digitaldirk Look at his unit test, it's a good way to test the selection after you verify focus |
|
@versile2 I've added to the description what this PR fixes. |
There was a problem hiding this comment.
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
SelectOptionAsyncto use_openfield directly instead ofOpenproperty for internal state changes - Added comprehensive unit tests to verify
OpenChangedevent is raised exactly once per open/close operation - Created test component to track
OpenChangedevent 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.
versile2
left a comment
There was a problem hiding this comment.
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.
|
Thank you! |
After item selection
MudAutocompletecurrently calls theOpenChangedevent twicewhich 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:
dev).