Skip to content

Commit

Permalink
PasswordInput component updates (#983)
Browse files Browse the repository at this point in the history
  • Loading branch information
gvreddy04 authored Dec 18, 2024
1 parent e167097 commit d7fc0a8
Show file tree
Hide file tree
Showing 12 changed files with 316 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal override IEnumerable<NavItem> GetNavItems()
new (){ Id = "401", Text = "Currency Input", Href = RouteConstants.Demos_CurrencyInput_Documentation, IconName = IconName.CurrencyDollar, ParentId = "4" },
new (){ Id = "402", Text = "Date Input", Href = RouteConstants.Demos_DateInput_Documentation, IconName = IconName.CalendarDate, ParentId = "4" },
new (){ Id = "403", Text = "Number Input", Href = RouteConstants.Demos_NumberInput_Documentation, IconName = IconName.InputCursor, ParentId = "4" },
new (){ Id = "403", Text = "Password Input", Href = RouteConstants.Demos_PasswordInput_Documentation, IconName = IconName.EyeSlashFill, ParentId = "4" },
new (){ Id = "403", Text = "Radio Input", Href = RouteConstants.Demos_RadioInput_Documentation, IconName = IconName.RecordCircle, ParentId = "4" },
new (){ Id = "404", Text = "Range Input", Href = RouteConstants.Demos_RangeInput_Documentation, IconName = IconName.Sliders, ParentId = "4" },
//new (){ Id = "404", Text = "Select Input", Href = RouteConstants.Demos_SelectInput_Documentation, IconName = IconName.MenuButtonWideFill, ParentId = "4" },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@page "/password-input"

@attribute [Route(pageUrl)]

<PageMetaTags PageUrl="@pageUrl"
Title="@metaTitle"
Description="@metaDescription"
ImageUrl="@imageUrl" />

<PageHero Heading="@pageTitle">
<LeadSection>@pageDescription</LeadSection>
</PageHero>

<CarbonAds />

<Section Size="HeadingSize.H2" Name="Basic usage" PageUrl="@pageUrl" Link="basic-usage">
<Demo Type="typeof(PasswordInput_Demo_01_Basic_Usage)" Tabs="true" />
</Section>

<Section Size="HeadingSize.H2" Name="Disable" PageUrl="@pageUrl" Link="disable">
<div class="mb-3">Use the <code>Disabled</code> parameter to disable the <code>TextInput</code>.</div>
<Demo Type="typeof(PasswordInput_Demo_02_Disable_A)" Tabs="false" />
<div class="my-3">Also, use <b>Enable()</b> and <b>Disable()</b> methods to enable and disable the <code>TextInput</code>.</div>
<Callout Color="CalloutColor.Warning" Heading="NOTE">
Do not use both the <b>Disabled</b> parameter and <b>Enable()</b> &amp; <b>Disable()</b> methods.
</Callout>
<Demo Type="typeof(PasswordInput_Demo_02_Disable_B)" Tabs="false" />
</Section>

<Section Size="HeadingSize.H2" Name="Valdations" PageUrl="@pageUrl" Link="validations">
<div class="mb-3">
Like any other blazor input component, <code>PasswordInput</code> supports validations.
Add the DataAnnotations on the <code>PasswordInput</code> component to validate the user input before submitting the form.
In the below example, we used <b>Required</b> attribute.
</div>
<Demo Type="typeof(PasswordInput_Demo_03_Validations)" Tabs="true" />
</Section>

<Section Size="HeadingSize.H2" Name="Events: ValueChanged" PageUrl="@pageUrl" Link="events-value-changed">
<div class="mb-3">This event fires when the <code>PasswordInput</code> value changes, but not on every keystroke.</div>
<Demo Type="typeof(PasswordInput_Demo_04_Events_ValueChanged)" Tabs="true" />
</Section>

@code {
private const string pageUrl = RouteConstants.Demos_PasswordInput_Documentation;
private const string pageTitle = "Blazor PasswordInput";
private const string pageDescription = "The Blazor Bootstrap PasswordInput component is constructed using an HTML input of type 'password'.";
private const string metaTitle = "Blazor PasswordInput Component";
private const string metaDescription = "The Blazor Bootstrap PasswordInput component is constructed using an HTML input of type 'password'.";
private const string imageUrl = "https://i.imgur.com/1mVjqQv.png"; // TODO: Update image URL
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="mb-3">
<PasswordInput @bind-Value="@enteredPassword" />
</div>
<div class="mb-3">Entered password: @enteredPassword</div>

@code {
private string? enteredPassword = null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="mb-3">
<PasswordInput @bind-Value="@enteredPassword" Disabled="@disabled" />
</div>
<div class="mb-3">Entered password: @enteredPassword</div>

<Button Color="ButtonColor.Primary" @onclick="Enable"> Enable </Button>
<Button Color="ButtonColor.Secondary" @onclick="Disable"> Disable </Button>
<Button Color="ButtonColor.Warning" @onclick="Toggle"> Toggle </Button>

@code {
private string? enteredPassword = null;

private bool disabled = true;

private void Enable() => disabled = false;

private void Disable() => disabled = true;

private void Toggle() => disabled = !disabled;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="mb-3">
<PasswordInput @ref="passwordInputRef" @bind-Value="@enteredPassword" />
</div>
<div class="mb-3">Entered text: @enteredPassword</div>

<Button Color="ButtonColor.Secondary" @onclick="Disable"> Disable </Button>
<Button Color="ButtonColor.Primary" @onclick="Enable"> Enable </Button>

@code {
private PasswordInput? passwordInputRef;

private string? enteredPassword = null;

private void Disable() => passwordInputRef.Disable();

private void Enable() => passwordInputRef.Enable();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@using System.ComponentModel.DataAnnotations

<style>
.valid.modified:not([type=checkbox]) {
outline: 1px solid #26b050;
}
.invalid {
outline: 1px solid red;
}
.validation-message {
color: red;
}
</style>

<EditForm EditContext="@editContext" OnValidSubmit="HandleOnValidSubmit">
<DataAnnotationsValidator />

<div class="form-group row mb-3">
<label class="col-md-2 col-form-label">User name: <span class="text-danger">*</span></label>
<div class="col-md-10">
<TextInput @bind-Value="@userLogin.UserName" Placeholder="Enter user name" />
<ValidationMessage For="@(() => userLogin.UserName)" />
</div>
</div>

<div class="form-group row mb-3">
<label class="col-md-2 col-form-label">Password: <span class="text-danger">*</span></label>
<div class="col-md-10">
<PasswordInput @bind-Value="@userLogin.Password" />
<ValidationMessage For="@(() => userLogin.Password)" />
</div>
</div>

<div class="row">
<div class="col-md-12 text-right">
<Button Type="ButtonType.Button" Color="ButtonColor.Secondary" Class="float-end" @onclick="ResetForm">Reset</Button>
<Button Type="ButtonType.Submit" Color="ButtonColor.Success" Class="float-end me-2">Login</Button>
</div>
</div>

</EditForm>

@code {
private UserLogin userLogin = new();
private EditContext? editContext;

protected override void OnInitialized()
{
editContext = new EditContext(userLogin);
base.OnInitialized();
}

public void HandleOnValidSubmit()
{
// additional check
if (editContext.Validate())
{
// do something
// submit the form
Console.WriteLine("Login successful");
}
}

private void ResetForm()
{
userLogin = new();
editContext = new EditContext(userLogin);
}

public class UserLogin
{
[Required(ErrorMessage = "User name required.")]
public string? UserName { get; set; }

[Required(ErrorMessage = "Password required.")]
public string? Password { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="mb-3">
<PasswordInput Value="@enteredPassword" ValueExpression="() => enteredPassword" ValueChanged="(value) => PasswordChanged(value)" />
</div>
<div class="mb-3">Entered password: @enteredPassword</div>

@code {
private string? enteredPassword = null;

private void PasswordChanged(string? value)
{
enteredPassword = value;

// do something
}
}
10 changes: 10 additions & 0 deletions BlazorBootstrap.Demo.RCL/Components/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
<h4 class="mb-0 fs-5 fw-semibold"><Icon Name="IconName.InputCursor" class="me-2" /> Number Input</h4>
</a>
</div>
<div class="col-sm-4 mb-2">
<a class="d-block pe-lg-4 text-decoration-none lh-sm" href="/form/password-input">
<h4 class="mb-0 fs-5 fw-semibold"><Icon Name="IconName.EyeSlashFill" class="me-2" /> Password Input <Badge Color="BadgeColor.Danger">New</Badge></h4>
</a>
</div>
<div class="col-sm-4 mb-2">
<a class="d-block pe-lg-4 text-decoration-none lh-sm" href="/offcanvas">
<h4 class="mb-0 fs-5 fw-semibold"><Icon Name="IconName.LayoutSidebarReverse" class="me-2" /> Offcanvas</h4>
Expand Down Expand Up @@ -299,6 +304,11 @@
<h4 class="mb-0 fs-5 fw-semibold"><Icon Name="IconName.InputCursor" class="me-2" /> Number Input</h4>
</a>
</div>
<div class="col-sm-4 mb-2">
<a class="d-block pe-lg-4 text-decoration-none lh-sm" href="/form/password-input">
<h4 class="mb-0 fs-5 fw-semibold"><Icon Name="IconName.EyeSlashFill" class="me-2" /> Password Input <Badge Color="BadgeColor.Danger">New</Badge></h4>
</a>
</div>
<div class="col-sm-4 mb-2">
<a class="d-block pe-lg-4 text-decoration-none lh-sm" href="@RouteConstants.Demos_RadioInput_Documentation">
<h4 class="mb-0 fs-5 fw-semibold"><Icon Name="IconName.RecordCircle" class="me-2" /> Radio Input <Badge Color="BadgeColor.Danger">New</Badge></h4>
Expand Down
1 change: 1 addition & 0 deletions BlazorBootstrap.Demo.RCL/Constants/RouteConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static class RouteConstants
public const string Demos_CurrencyInput_Documentation = Demos_Forms_Prefix + "/currency-input";
public const string Demos_DateInput_Documentation = Demos_Forms_Prefix + "/date-input";
public const string Demos_NumberInput_Documentation = Demos_Forms_Prefix + "/number-input";
public const string Demos_PasswordInput_Documentation = Demos_Forms_Prefix + "/password-input";
public const string Demos_RadioInput_Documentation = Demos_Forms_Prefix + "/radio-input";
public const string Demos_RangeInput_Documentation = Demos_Forms_Prefix + "/range-input";
public const string Demos_SelectInput_Documentation = Demos_Forms_Prefix + "/select-input";
Expand Down
23 changes: 13 additions & 10 deletions blazorbootstrap/Components/Form/PasswordInput/PasswordInput.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
@preservewhitespace true

<div class="input-group mb-3">
<input
@ref="@Element"
type="@InputTextType"
id="@Id"
class="@BootstrapClass.FormControl"
disabled="@Disabled"
value="@Value"
@attributes="@AdditionalAttributes"
@onchange="OnChange">
<button type="button" class="btn btn-primary btn-sm" @onclick="OnShowHidePasswordButtonClick"><i class="bi bi-eye-fill" /></button>
<input @ref="@Element"
type="@InputTextType"
id="@Id"
class="@ClassNames"
style="@StyleNames"
value="@Value"
disabled="@Disabled"
@attributes="@AdditionalAttributes"
@onchange="OnChange">

<button type="button" class="@ShowHidePasswordButtonCssClass" @onclick="ShowHidePassword">
<i class="@ShowHidePasswordButtonIcon"></i>
</button>
</div>
Loading

0 comments on commit d7fc0a8

Please sign in to comment.