Skip to content

Commit

Permalink
Merge pull request #1604 from pkuehnel/fix/iOSNumericInput
Browse files Browse the repository at this point in the history
feat(GenericInput): use InputMode Text on Numericfield on iOS
  • Loading branch information
pkuehnel authored Nov 8, 2024
2 parents 0d3dc58 + f647aa7 commit 7161c4b
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions TeslaSolarCharger/Client/Components/GenericInput.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

@inject IConstants Constants
@inject IStringHelper StringHelper
@inject IJavaScriptWrapper JavaScriptWrapper

@typeparam T

Expand Down Expand Up @@ -235,11 +236,7 @@
Margin="InputMargin"
Immediate="@ImmediateValueUpdate"
Clearable="@(Clearable && !IsReadOnly && !IsDisabled)"
@attributes="@(ShouldBeInErrorState.HasValue ? new Dictionary<string, object>
{
{ "Error", ShouldBeInErrorState.Value },
{ "ErrorText", ErrorMessage ?? string.Empty },
} :new())" />
@attributes="@(NumericFieldAttributes())" />
}
else if (IsNormalText())
{
Expand Down Expand Up @@ -369,6 +366,25 @@


private bool? _isReadOnlyParameter;
private bool _isIosDevice;

private IDictionary<string, object> NumericFieldAttributes()
{
var attributes = new Dictionary<string, object>();

if (ShouldBeInErrorState.HasValue)
{
attributes["Error"] = ShouldBeInErrorState.Value;
attributes["ErrorText"] = ErrorMessage ?? string.Empty;
}

if (_isIosDevice)
{
attributes["InputMode"] = InputMode.text;
}

return attributes;
}

private Expression<Func<DateTime?>>? ForDateTime
{
Expand Down Expand Up @@ -714,6 +730,18 @@
}
}

protected override async Task OnInitializedAsync()
{
try
{
_isIosDevice = await JavaScriptWrapper.IsIosDevice();
}
catch (Exception)
{
_isIosDevice = false;
}
}

protected override void OnAfterRender(bool firstRender)
{
_componentRenderedCounter++;
Expand Down

0 comments on commit 7161c4b

Please sign in to comment.