Skip to content

Commit

Permalink
PasswordField DisablePaste (CodeBeamOrg#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
mckaragoz authored Nov 17, 2023
1 parent 9e625f4 commit 82e9e86
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CodeBeam.MudBlazor.Extensions/Base/MudBaseInputExtended.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ protected virtual async Task InvokeKeyDown(KeyboardEventArgs obj)
[Category(CategoryTypes.FormComponent.Behavior)]
public bool KeyDownPreventDefault { get; set; }

[Parameter]
[Category(CategoryTypes.FormComponent.Behavior)]
public bool DisablePaste { get; set; }


/// <summary>
/// Fired on the KeyPress event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,62 @@
}

<div class="mud-input" style="flex-basis: 20px; flex-grow: 1">
<input class="@InputClassname"
@ref="ElementReference"
@attributes="UserAttributes"
type="@InputTypeString"
value="@_internalText"
@oninput="OnInputHandler"
@onchange="OnChangeHandler"
placeholder="@Placeholder"
disabled=@Disabled
readonly="@ReadOnly"
@onblur="@OnBlurredAsync"
inputmode="@InputMode.ToString()"
pattern="@Pattern"
@onkeydown="@InvokeKeyDown"
@onkeypress="@InvokeKeyPress"
@onkeyup="@InvokeKeyUp"
maxlength="@MaxLength"
@onkeydown:preventDefault="KeyDownPreventDefault"
@onkeypress:preventDefault="@KeyPressPreventDefault"
@onkeyup:preventDefault="@KeyUpPreventDefault"
@onmousewheel="@OnMouseWheel"
@onwheel="@OnMouseWheel"
aria-invalid="@Error.ToString().ToLower()"
aria-describedby="@ErrorId" />
@if (DisablePaste)
{
<input class="@InputClassname"
@ref="ElementReference"
@attributes="UserAttributes"
type="@InputTypeString"
value="@_internalText"
@oninput="OnInputHandler"
@onchange="OnChangeHandler"
placeholder="@Placeholder"
disabled=@Disabled
readonly="@ReadOnly"
@onblur="@OnBlurredAsync"
inputmode="@InputMode.ToString()"
pattern="@Pattern"
@onkeydown="@InvokeKeyDown"
@onkeypress="@InvokeKeyPress"
@onkeyup="@InvokeKeyUp"
maxlength="@MaxLength"
@onkeydown:preventDefault="KeyDownPreventDefault"
@onkeypress:preventDefault="@KeyPressPreventDefault"
@onkeyup:preventDefault="@KeyUpPreventDefault"
onpaste="return false"
@onmousewheel="@OnMouseWheel"
@onwheel="@OnMouseWheel"
aria-invalid="@Error.ToString().ToLower()"
aria-describedby="@ErrorId" />
}
else
{
<input class="@InputClassname"
@ref="ElementReference"
@attributes="UserAttributes"
type="@InputTypeString"
value="@_internalText"
@oninput="OnInputHandler"
@onchange="OnChangeHandler"
placeholder="@Placeholder"
disabled=@Disabled
readonly="@ReadOnly"
@onblur="@OnBlurredAsync"
inputmode="@InputMode.ToString()"
pattern="@Pattern"
@onkeydown="@InvokeKeyDown"
@onkeypress="@InvokeKeyPress"
@onkeyup="@InvokeKeyUp"
maxlength="@MaxLength"
@onkeydown:preventDefault="KeyDownPreventDefault"
@onkeypress:preventDefault="@KeyPressPreventDefault"
@onkeyup:preventDefault="@KeyUpPreventDefault"
@onmousewheel="@OnMouseWheel"
@onwheel="@OnMouseWheel"
aria-invalid="@Error.ToString().ToLower()"
aria-describedby="@ErrorId" />
}

</div>

@*Note: double mouse wheel handlers needed for Firefox because it doesn't know onmousewheel*@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
HideSpinButtons="true"
Clearable="@Clearable"
OnClearButtonClick="@OnClearButtonClick"
Pattern="@Pattern">
Pattern="@Pattern"
DisablePaste="@DisablePaste">
<AdornmentStart>
@AdornmentStart
</AdornmentStart>
Expand Down Expand Up @@ -103,7 +104,8 @@
HideSpinButtons="true"
Clearable="@Clearable"
OnClearButtonClick="@OnClearButtonClick"
Pattern="@Pattern">
Pattern="@Pattern"
DisablePaste="@DisablePaste">
<AdornmentEnd>
@if (CustomAdornment != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public partial class MudPasswordField<T> : MudDebouncedInput<T>
[Category(CategoryTypes.FormComponent.Behavior)]
public bool Clearable { get; set; } = false;

[Parameter]
[Category(CategoryTypes.FormComponent.Behavior)]
public bool DisablePaste { get; set; }

/// <summary>
/// If true, adornment button accepts tab stop. Default is false.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@
<MudItem xs="12" sm="8" Class="d-flex align-center">
@if (_adornmentStart)
{
<MudPasswordField @bind-Value="@_password" @bind-PasswordMode="@_passwordMode" Variant="Variant.Outlined" IconSize="_size">
<MudPasswordField @bind-Value="@_password" @bind-PasswordMode="@_passwordMode" Variant="Variant.Outlined" IconSize="_size" DisablePaste="_disablePaste">
<AdornmentStart>
<MudIcon Icon="@Icons.Material.Filled.Key"/>
</AdornmentStart>
</MudPasswordField>
}
else
{
<MudPasswordField @bind-Value="@_password" @bind-PasswordMode="@_passwordMode" Variant="Variant.Outlined" IconSize="_size" />
<MudPasswordField @bind-Value="@_password" @bind-PasswordMode="@_passwordMode" Variant="Variant.Outlined" IconSize="_size" DisablePaste="_disablePaste" />
}
</MudItem>

<MudItem xs="12" sm="4">
<MudStack>
<MudSwitchM3 @bind-Checked="_passwordMode" Color="Color.Secondary">Password Mode</MudSwitchM3>
<MudSwitchM3 @bind-Checked="_adornmentStart" Color="Color.Secondary">Adornment Start</MudSwitchM3>
<MudSwitchM3 @bind-Checked="_disablePaste" Color="Color.Secondary">Disable Paste</MudSwitchM3>
<MudSelectExtended @bind-Value="_size" ItemCollection="Enum.GetValues<Size>()" Label="Icon Size" Variant="Variant.Outlined"/>
</MudStack>
</MudItem>
Expand All @@ -27,5 +28,6 @@
string _password = "asdf";
bool _passwordMode;
bool _adornmentStart;
bool _disablePaste;
Size _size = Size.Medium;
}

0 comments on commit 82e9e86

Please sign in to comment.