Telerik Textbox Password Input

1 Answer 400 Views
TextBox
Anthony
Top achievements
Rank 1
Iron
Anthony asked on 12 Feb 2024, 09:46 PM
Is there a way to keep the show password icon on the textbox whether the textbox is focused or not or when its initialized?

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 15 Feb 2024, 11:43 AM

Hi Anthony,

I assume that you are using the input adornments that we released in 5.1.0. You can implement something like the approach below.

When we implement a built-in focus event, you may be able to use it as well.

<span @onfocusin="@OnTextBoxFocus" @onfocusout="@OnTextBoxBlur">
    <TelerikTextBox @bind-Value="@Password"
                    Width="200px"
                    Password="@MaskPassword">
        <TextBoxSuffixTemplate>
            @if (ShowEyeIcon)
            {
                <TelerikButton Icon="@( MaskPassword ? SvgIcon.Eye : SvgIcon.EyeSlash )"
                               FillMode="@ThemeConstants.Button.FillMode.Flat"
                               OnClick="@( () => MaskPassword = !MaskPassword )" />
            }
        </TextBoxSuffixTemplate>
    </TelerikTextBox>
</span>

@code {
    string Password { get; set; } = "foo";

    bool ShowEyeIcon { get; set; }

    bool MaskPassword { get; set; } = true;

    void OnTextBoxFocus()
    {
        ShowEyeIcon = true;
    }

    void OnTextBoxBlur()
    {
        ShowEyeIcon = false;
    }
}

Regards,
Dimo
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
Tags
TextBox
Asked by
Anthony
Top achievements
Rank 1
Iron
Answers by
Dimo
Telerik team
Share this question
or