MudTextField: Fix Focus by ElementReference#11733
Merged
danielchalmers merged 3 commits intoMudBlazor:devfrom Jul 30, 2025
Merged
MudTextField: Fix Focus by ElementReference#11733danielchalmers merged 3 commits intoMudBlazor:devfrom
danielchalmers merged 3 commits intoMudBlazor:devfrom
Conversation
- Removed JavaScript focus invocation from `MudBaseInput.cs`. - Updated `@onclick` syntax in `MudTextField.razor`. - Added `HandleContainerClick` method in `MudTextField.razor.cs` to manage focus using C#. - Deleted `focusInput` function from `mudInput.js` to streamline focus handling.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves focus handling in MudTextField by replacing JavaScript-based focus implementation with native Blazor ElementReference.FocusAsync(). The change removes the need for external JavaScript while maintaining the same focus functionality when clicking on text field containers.
- Removed JavaScript
focusInputfunction and relatedHandleContainerClickmethod from base class - Added new
HandleContainerClickmethod in MudTextField that uses ElementReference.FocusAsync() - Updated razor template to use the new component-specific click handler
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/MudBlazor/TScripts/mudInput.js | Removes the focusInput JavaScript function that was handling focus via DOM manipulation |
| src/MudBlazor/Components/TextField/MudTextField.razor.cs | Adds new HandleContainerClick method using ElementReference.FocusAsync() instead of JavaScript |
| src/MudBlazor/Components/TextField/MudTextField.razor | Updates click handler reference to use the component-specific method |
| src/MudBlazor/Base/MudBaseInput.cs | Removes the base HandleContainerClick method that relied on JavaScript |
Co-authored-by: Copilot <[email protected]>
danielchalmers
approved these changes
Jul 30, 2025
Co-authored-by: Daniel Chalmers <[email protected]>
|
This was referenced Aug 5, 2025
Closed
Closed
This was referenced Aug 14, 2025
This was referenced Nov 12, 2025
This was referenced Dec 12, 2025
Closed
Closed
This was referenced Dec 29, 2025
This was referenced Jan 9, 2026
Closed
This was referenced Feb 10, 2026
Closed
This was referenced Feb 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Resolves #11690 and #11698
Removed
HandleContainerClickmethod calling JavaScript focusInput with InputElementId fromMudBaseInput.cs.Deleted
focusInputfunction from javascript to streamline focus handling.Replaced
HandleContainerClickmethod inMudTextField.razor.csto manage focus using the built in textarea/input override of ElementReference.FocusAsync() requiring no external javascript.Checklist:
dev).