about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor
blob: 9c325a792ff94d06dba2529a8d603caa8d225783 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@inject IJSRuntime JsRuntime
@if (isVisible)
{
    <input autofocus @bind="Value" @onfocusout="() => { isVisible = false; ValueChanged.InvokeAsync(Value); }" @ref="elementToFocus"/>
}
else
{
    <span tabindex="0" style="border-bottom: #ccc solid 1px; height: 1.4em; display: inline-block; @(string.IsNullOrEmpty(Value) ? "min-width: 50px;" : "")" @onfocusin="() => isVisible = true">@(Formatter?.Invoke(Value) ?? (IsPassword ? string.Join("", Value.Select(x=>'*')) : Value))</span>
}

@code {

    [Parameter]
    public string Value { get; set; }
    
    [Parameter]
    public bool IsPassword { get; set; } = false;
    
    [Parameter]
    public EventCallback<string> ValueChanged { get; set; }
    
    [Parameter]
    public Func<string?, string>? Formatter { get; set; }
    

    private bool isVisible { get; set; } = false;

    private ElementReference elementToFocus;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await JsRuntime.InvokeVoidAsync("BlazorFocusElement", elementToFocus);
    }

}