Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(InputNumber): support oninput event #2767

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>8.1.5</Version>
<Version>8.1.6-beta01</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/Input/BootstrapInput.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@namespace BootstrapBlazor.Components
@typeparam TValue
@inherits BootstrapInputBase<TValue>
@inherits BootstrapInputEventBase<TValue>

@if (IsShowLabel)
{
Expand Down
8 changes: 0 additions & 8 deletions src/BootstrapBlazor/Components/Input/BootstrapInput.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,4 @@ public partial class BootstrapInput<TValue>
public bool Readonly { get; set; }

private string? ReadonlyString => Readonly ? "true" : null;

/// <summary>
/// 获得/设置 是否在文本框输入值时触发 bind-value:event="oninput" 默认 false
/// </summary>
[Parameter]
public bool UseInputEvent { get; set; } = false;

private string EventString => UseInputEvent ? "oninput" : "onchange";
}
22 changes: 22 additions & 0 deletions src/BootstrapBlazor/Components/Input/BootstrapInputEventBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/

namespace BootstrapBlazor.Components;

/// <summary>
/// 输入框基类
/// </summary>
public abstract class BootstrapInputEventBase<TValue> : BootstrapInputBase<TValue>
{
/// <summary>
/// 获得/设置 是否在文本框输入值时触发 bind-value:event="oninput" 默认 false
/// </summary>
[Parameter]
public bool UseInputEvent { get; set; }

/// <summary>
/// event 字符串
/// </summary>
protected string EventString => UseInputEvent ? "oninput" : "onchange";
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
<button class="@ButtonClassString" type="button" @onclick="OnClickDec" disabled="@Disabled">
<i class="@MinusIcon"></i>
</button>
<input @attributes="AdditionalAttributes" step="@StepString" min="@Min" max="@Max" id="@Id" type="number" placeholder="@PlaceHolder" class="@InputClassString" disabled="@Disabled" @bind-value="@CurrentValueAsString" @bind-value:event="onchange" @onblur="@OnBlur" @ref="FocusElement" />
<input @attributes="AdditionalAttributes" step="@StepString" min="@Min" max="@Max" id="@Id" type="number" placeholder="@PlaceHolder" class="@InputClassString" disabled="@Disabled" @bind-value="@CurrentValueAsString" @bind-value:event="@EventString" @onblur="@OnBlur" @ref="FocusElement" />
<button class="@ButtonClassString" type="button" @onclick="OnClickInc" disabled="@Disabled">
<i class="@PlusIcon"></i>
</button>
</div>
}
else
{
<input @attributes="AdditionalAttributes" step="@StepString" min="@Min" max="@Max" id="@Id" type="number" placeholder="@PlaceHolder" class="@InputClassString" disabled="@Disabled" @bind-value="@CurrentValueAsString" @bind-value:event="onchange" @onblur="@OnBlur" @ref="FocusElement" />
<input @attributes="AdditionalAttributes" step="@StepString" min="@Min" max="@Max" id="@Id" type="number" placeholder="@PlaceHolder" class="@InputClassString" disabled="@Disabled" @bind-value="@CurrentValueAsString" @bind-value:event="@EventString" @onblur="@OnBlur" @ref="FocusElement" />
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace BootstrapBlazor.Components;
/// <summary>
/// BootstrapInputNumber 基类
/// </summary>
public class BootstrapInputNumberBase<TValue> : BootstrapInputBase<TValue>
public class BootstrapInputNumberBase<TValue> : BootstrapInputEventBase<TValue>
{
/// <summary>
/// SetParametersAsync 方法
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/Slider/Slider.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ else

@code {
RenderFragment RenderRange =>
@<input type="range" id="@Id" @attributes="@AdditionalAttributes" class="@ClassString" disabled="@IsDisabled" @bind-value="CurrentValueAsString" @bind-value:event="@eventName" step="@StepString" min="@MinString" max="@MaxString">;
@<input type="range" id="@Id" @attributes="@AdditionalAttributes" class="@ClassString" disabled="@IsDisabled" @bind-value="CurrentValueAsString" @bind-value:event="@EventString" step="@StepString" min="@MinString" max="@MaxString">;
}
8 changes: 0 additions & 8 deletions src/BootstrapBlazor/Components/Slider/Slider.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ public partial class Slider<TValue>
.AddClassFromAttributes(AdditionalAttributes)
.Build();

/// <summary>
/// 获得/设置 是否使用 input 事件 默认为 false
/// </summary>
[Parameter]
public bool UseInputEvent { get; set; }

/// <summary>
/// 获得/设置 最小值 默认为 null 未设置
/// </summary>
Expand All @@ -43,8 +37,6 @@ public partial class Slider<TValue>
[NotNull]
public TValue? Step { get; set; }

private string eventName => UseInputEvent ? "oninput" : "onchange";

private string? MinString => Min.ToString() == "0" ? GetRangeMinString : Min.ToString();

private string? GetRangeMinString => _range?.Minimum.ToString();
Expand Down