Skip to content

Commit 4794c9f

Browse files
committed
Fix CodeInput
1 parent 082e8fb commit 4794c9f

22 files changed

Lines changed: 161 additions & 5997 deletions

File tree

CodeBeam.MudBlazor.Extensions.Docs.Wasm/wwwroot/CodeBeam.MudBlazor.Extensions.xml

Lines changed: 33 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@namespace MudExtensions.Docs.Examples
22

33
<MudGrid>
4-
<MudAlert Class="mud-width-full" Severity="Severity.Warning"><b>Known Issue:</b>MudChipField doesn't work on chromium based android browsers due to their keydown limitation.</MudAlert>
4+
<MudAlert Class="mud-width-full" Severity="Severity.Info">MudChipField works on mobile with MudExtensions 9 and after.</MudAlert>
55
</MudGrid>

CodeBeam.MudBlazor.Extensions/Base/MudBaseInputExtended.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ protected MudBaseInputExtended()
5555
/// </summary>
5656
[Parameter] public EventCallback OnChange { get; set; }
5757

58+
/// <summary>
59+
/// Gets or sets a callback that is invoked before input is processed.
60+
/// </summary>
61+
/// <remarks>Use this callback to perform custom logic or validation before the input event is
62+
/// handled. This can be useful for intercepting or modifying input behavior in advanced scenarios
63+
/// </remarks>
5864
[Parameter]
5965
public EventCallback<MudBeforeInputEventArgs> OnBeforeInput { get; set; }
6066

@@ -64,6 +70,12 @@ protected MudBaseInputExtended()
6470
[Parameter]
6571
public bool HasAdornmentStart { get; set; }
6672

73+
/// <summary>
74+
/// Gets or sets a value indicating whether the component has an adornment at the end.
75+
/// </summary>
76+
[Parameter]
77+
public bool HasAdornmentEnd { get; set; }
78+
6779
/// <summary>
6880
/// The Adornment if used. By default, it is set to None.
6981
/// </summary>
@@ -91,6 +103,12 @@ protected MudBaseInputExtended()
91103
[Category(CategoryTypes.FormComponent.Behavior)]
92104
public bool DisablePaste { get; set; }
93105

106+
/// <summary>
107+
/// Invokes logic to be executed before input is processed, including raising the BeforeInput event if a
108+
/// delegate is assigned.
109+
/// </summary>
110+
/// <param name="args">The event data associated with the before input operation.</param>
111+
/// <returns>A task that represents the asynchronous operation.</returns>
94112
protected async Task InvokeBeforeInputAsync(MudBeforeInputEventArgs args)
95113
{
96114
_isFocused = true;
@@ -127,20 +145,33 @@ protected override async Task OnConverterChangedAsync()
127145
/// <returns></returns>
128146
protected string? ResolveAriaDescribedBy() => GetAriaDescribedByString();
129147

148+
/// <summary>
149+
///
150+
/// </summary>
151+
/// <param name="dto"></param>
152+
/// <returns></returns>
130153
[JSInvokable("OnBeforeInput")]
131154
public async Task<bool> OnBeforeInputFromJs(MudBeforeInputJsDto dto)
132155
{
133156
var args = new MudBeforeInputEventArgs
134157
{
135158
Data = dto.Data,
136-
InputType = dto.InputType,
159+
InputType = dto.InputType ?? string.Empty,
137160
IsComposing = dto.IsComposing
138161
};
139162

140163
await InvokeBeforeInputAsync(args);
141164
return args.PreventDefault;
142165
}
143166

167+
/// <summary>
168+
/// Invoked before processing input, allowing for custom logic or validation to be performed asynchronously.
169+
/// </summary>
170+
/// <remarks>Override this method in a derived class to implement custom pre-processing or
171+
/// validation logic before input is handled. This method is called before the main input processing
172+
/// occurs.</remarks>
173+
/// <param name="args">An object containing event data for the input operation.</param>
174+
/// <returns>A task that represents the asynchronous operation. The default implementation returns a completed task.</returns>
144175
protected virtual Task OnBeforeInputAsync(MudBeforeInputEventArgs args) => Task.CompletedTask;
145176

146177

CodeBeam.MudBlazor.Extensions/CodeBeam.MudBlazor.Extensions.csproj

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,11 @@
3535

3636
<ItemGroup>
3737
<PackageReference Include="MudBlazor" Version="9.0.0-preview.1" />
38-
<!--<PackageReference Include="MudBlazor.SassCompiler" Version="2.0.7">
38+
<PackageReference Include="MudBlazor.SassCompiler" Version="2.0.7">
3939
<PrivateAssets>all</PrivateAssets>
40-
</PackageReference>-->
40+
</PackageReference>
4141
</ItemGroup>
4242

43-
<Target Name="CopyMudExtensionsCss" AfterTargets="Build">
44-
<Copy SourceFiles="wwwroot/css/MudExtensions.min.css" DestinationFiles="wwwroot/MudExtensions.min.css" SkipUnchangedFiles="true" Condition="Exists('wwwroot/css/MudExtensions.min.css')" />
45-
</Target>
46-
4743
<Target Name="MinifyMudExtensionsJs" AfterTargets="Build" Condition="'$(CI)' != 'true'
4844
AND '$(TargetFramework)' == 'net10.0'
4945
AND Exists('TScripts/MudExtensions.js')">
@@ -53,7 +49,6 @@
5349

5450
<ItemGroup>
5551
<Content Remove="sasscompiler.json" />
56-
<Content Remove="wwwroot/css/**" />
5752
</ItemGroup>
5853

5954
<ItemGroup>

CodeBeam.MudBlazor.Extensions/Components/CodeInput/MudCodeInput.razor

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,9 @@
1010
int a = i;
1111
<MudTextFieldExtended @ref="_elementReferences[a]" T="T" Class="@InputClassname" Style="@(Margin == Margin.Dense ? "width: 32px" : "width: 42px")" MaxLength="1"
1212
@onkeydown="HandleKeyDown" @onfocus="@(() => CheckFocus(a))" @onblur="SetValue" OnInput="OnInputHandler" Error="@ErrorState.Value"
13-
Variant="@Variant" Margin="@Margin" Disabled="Disabled" ReadOnly="ReadOnly" Immediate="true" InputType="InputType" />
13+
Variant="@Variant" Margin="@Margin" Disabled="Disabled" ReadOnly="ReadOnly" Immediate="true" InputType="InputType"
14+
HasAdornmentStart="false" HasAdornmentEnd="false" />
1415
}
1516
</div>
1617
</InputContent>
1718
</MudInputControl>
18-
19-
<style>
20-
.justify-text-center input {
21-
text-align: center;
22-
}
23-
24-
.mud-code input {
25-
padding: 12px 0px !important;
26-
}
27-
</style>

CodeBeam.MudBlazor.Extensions/Components/CodeInput/MudCodeInput.razor.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.AspNetCore.Components;
22
using Microsoft.AspNetCore.Components.Web;
33
using MudBlazor;
4+
using MudBlazor.Extensions;
45
using MudBlazor.Interfaces;
56
using MudBlazor.State;
67
using MudBlazor.Utilities;
@@ -18,6 +19,12 @@ public partial class MudCodeInput<T> : MudFormComponent<T, string>
1819
/// </summary>
1920
public MudCodeInput()
2021
{
22+
Converter = new DefaultConverter<T>
23+
{
24+
Culture = GetCulture,
25+
Format = GetFormat
26+
};
27+
2128
using var registerScope = CreateRegisterScope();
2229
_theValue = registerScope.RegisterParameter<T?>(nameof(Value))
2330
.WithParameter(() => Value)
@@ -279,7 +286,7 @@ public async Task SetValue()
279286
string result = "";
280287
for (int i = 0; i < _count.Value; i++)
281288
{
282-
var val = _elementReferences[i].Value?.ToString();
289+
var val = _elementReferences[i].GetState(x => x.Value)?.ToString();
283290
if (val == null)
284291
{
285292
continue;

CodeBeam.MudBlazor.Extensions/Components/ComboBox/MudComboBox.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
ShowVisualiser="@((MultiSelection && SelectedValues?.Any() == true) || !Editable)" DataVisualiserStyle="min-height: 1.1876em"
2121
@bind-Value="@_searchString" Typo="@Typo"
2222
Underline="@Underline"
23-
HasAdornmentStart="@((AdornmentStart != null))"
23+
HasAdornmentStart="@(AdornmentStart != null)" HasAdornmentEnd="@(AdornmentEnd != null)"
2424
Disabled="@GetDisabledState()" ReadOnly="@GetReadOnlyState()" Error="@ErrorState.Value" ErrorId="@ErrorIdState.Value"
2525
Clearable="@Clearable" ForceClearable="@(Clearable && HasValue(ReadValue))" OnClearButtonClick="@ClearButtonClickHandlerAsync"
2626
MaxLength="@MaxLength" @attributes="UserAttributes" OnBlur="@HandleOnBlur" ShrinkLabel="@(HasValue(ReadValue) || AdornmentStart != null || _isOpen || ShrinkLabel)">

CodeBeam.MudBlazor.Extensions/Components/InputExtended/MudInputCssHelperExtended.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public static string GetInputClassname<T>(MudBaseInputExtended<T> baseInput) =>
4444

4545
public static string GetAdornmentClassname<T>(MudBaseInputExtended<T> baseInput) =>
4646
new CssBuilder("mud-input-adornment")
47-
.AddClass($"mud-input-adornment-start", baseInput.AdornmentStart != null)
48-
.AddClass($"mud-input-adornment-end", baseInput.AdornmentEnd != null)
47+
.AddClass($"mud-input-adornment-start", baseInput.HasAdornmentStart)
48+
.AddClass($"mud-input-adornment-end", baseInput.HasAdornmentEnd)
4949
.AddClass($"mud-text", !string.IsNullOrEmpty(baseInput.AdornmentText))
5050
.AddClass($"mud-input-root-filled-shrink", baseInput.Variant == Variant.Filled)
5151
.AddClass(baseInput.Class)

CodeBeam.MudBlazor.Extensions/Components/InputExtended/MudInputExtended.razor

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
type="@InputTypeString"
2323
placeholder="@Placeholder"
2424
disabled="@GetDisabledState()"
25-
readonly="@GetReadOnlyState"
26-
inputmode="@InputMode.ToString()"
25+
readonly="@GetReadOnlyState()"
26+
inputmode="@InputMode.ToDescriptionString()"
2727
@bind:event="@(Immediate ? "oninput" : "onchange")"
2828
@bind:get="@_internalText"
2929
@bind:set="@OnInputOrOnChangeAsync"
@@ -37,8 +37,10 @@
3737
@onkeyup:preventDefault="@KeyUpPreventDefault"
3838
@onmousewheel="@OnMouseWheel"
3939
@onwheel="@OnMouseWheel"
40-
aria-invalid="@Error.ToString().ToLower()"
41-
aria-describedby="@ErrorId">
40+
aria-describedby="@GetAriaDescribedByString()"
41+
aria-invalid="@ErrorState.Value.ToString().ToLowerInvariant()"
42+
required="@Required"
43+
aria-required="@Required.ToString().ToLowerInvariant()">
4244
@ReadText
4345
</textarea>
4446
@*Note: double mouse wheel handlers needed for Firefox because it doesn't know onmousewheel*@
@@ -80,8 +82,10 @@
8082
onpaste="return false"
8183
@onmousewheel="@OnMouseWheel"
8284
@onwheel="@OnMouseWheel"
83-
aria-invalid="@Error.ToString().ToLower()"
84-
aria-describedby="@ErrorId" />
85+
aria-describedby="@GetAriaDescribedByString()"
86+
aria-invalid="@ErrorState.Value.ToString().ToLowerInvariant()"
87+
required="@Required"
88+
aria-required="@Required.ToString().ToLowerInvariant()">
8589
}
8690
else
8791
{
@@ -107,8 +111,10 @@
107111
@onkeyup:preventDefault="@KeyUpPreventDefault"
108112
@onmousewheel="@OnMouseWheel"
109113
@onwheel="@OnMouseWheel"
110-
aria-invalid="@Error.ToString().ToLower()"
111-
aria-describedby="@ErrorId" />
114+
aria-describedby="@GetAriaDescribedByString()"
115+
aria-invalid="@ErrorState.Value.ToString().ToLowerInvariant()"
116+
required="@Required"
117+
aria-required="@Required.ToString().ToLowerInvariant()">
112118
}
113119

114120
</div>
@@ -137,7 +143,7 @@
137143
</div>
138144
}
139145

140-
@if (GetClearable() && !GetDisabledState() || ForceClearable)
146+
@if (ShowClearButton() || ForceClearable)
141147
{
142148
<div @onmousedown:stopPropagation>
143149
<MudIconButton Class="@ClearButtonClassname"
@@ -149,7 +155,7 @@
149155
</div>
150156
}
151157

152-
@if (AdornmentEnd != null)
158+
@if (HasAdornmentEnd != true)
153159
{
154160
<div class="@AdornmentEndClassname">
155161
@AdornmentEnd

0 commit comments

Comments
 (0)