@using System.Linq.Expressions @inject IJSRuntime JSRuntime
@code { private bool _showPassword = false; private InputText? inputComponent; /// /// Gets or sets the ID of the input field. /// [Parameter] public required string Id { get; set; } /// /// Gets or sets the value of the input field. /// [Parameter] public required string Value { get; set; } /// /// Gets or sets the event callback that is triggered when the value changes. /// [Parameter] public required EventCallback ValueChanged { get; set; } /// /// Gets or sets the expression that identifies the value property. /// [Parameter] public required Expression> ValueExpression { get; set; } /// /// Gets or sets the placeholder text for the input field. /// [Parameter] public required string Placeholder { get; set; } /// /// Gets or sets additional attributes for the input field. /// [Parameter(CaptureUnmatchedValues = true)] public Dictionary? AdditionalAttributes { get; set; } = new(); /// /// Toggles the password visibility. /// private void TogglePasswordVisibility() { _showPassword = !_showPassword; } /// /// Focuses the input field. /// /// A task that represents the asynchronous focus operation. public async Task FocusAsync() { try { if (inputComponent?.Element != null) { await inputComponent.Element.Value.FocusAsync(); } else { // Fallback to JS focus if component element is not available await JSRuntime.InvokeVoidAsync("eval", $"document.getElementById('{Id}')?.focus()"); } } catch (Exception) { // Final fallback to JS focus if ElementReference focus fails await JSRuntime.InvokeVoidAsync("eval", $"document.getElementById('{Id}')?.focus()"); } } }