Skip to content

Commit 12bc57f

Browse files
committed
Merge branch 'main' into refat-complete
2 parents ead68ff + 3d6591e commit 12bc57f

File tree

14 files changed

+204
-8
lines changed

14 files changed

+204
-8
lines changed

src/BootstrapBlazor.Server/Components/Samples/Inputs.razor

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,33 @@
222222
</div>
223223
</DemoBlock>
224224

225+
<DemoBlock Title="@Localizer["ClearableTitle"]"
226+
Introduction="@Localizer["ClearableIntro"]"
227+
Name="OnInput">
228+
<div class="row g-3">
229+
<div class="col-12 col-sm-6">
230+
<BootstrapInput Value="Model.Name" Clearable="true" ShowLabel="true" DisplayText="Clearable" />
231+
</div>
232+
</div>
233+
<div class="row form-inline g-3 mt-0">
234+
<div class="col-12 col-sm-6">
235+
<BootstrapInput Value="Model.Name" Clearable="true" ShowLabel="true" DisplayText="Clearable" />
236+
</div>
237+
</div>
238+
<div class="row g-3 mt-0">
239+
<div class="col-12 col-sm-6">
240+
<BootstrapInputGroup>
241+
<BootstrapInputGroupLabel ShowRequiredMark DisplayText="Clearable"></BootstrapInputGroupLabel>
242+
<BootstrapInput Value="@Model.Name" Clearable="true" />
243+
</BootstrapInputGroup>
244+
</div>
245+
<div class="col-12 col-sm-6">
246+
<BootstrapInputGroup>
247+
<BootstrapInput Value="@Model.Name" Clearable="true" />
248+
<BootstrapInputGroupLabel ShowRequiredMark DisplayText="Clearable"></BootstrapInputGroupLabel>
249+
</BootstrapInputGroup>
250+
</div>
251+
</div>
252+
</DemoBlock>
253+
225254
<AttributeTable Items="@GetAttributes()" />

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2780,7 +2780,9 @@
27802780
"InputsFormatStringSetting": "Set up",
27812781
"InputsFormatStringTips": "The <code>BootstrapInput</code> component binds <code>byte[]</code> array and formats it as an example of <code>base64</code> encoded string",
27822782
"UseInputEvent": "Whether use oninput event when bind-value",
2783-
"IsTrim": "automatically trim white space when entering content"
2783+
"IsTrim": "automatically trim white space when entering content",
2784+
"ClearableTitle": "Clearable",
2785+
"ClearableIntro": "By setting the <code>Clearable=\"true\"</code> parameter, a small <b>Clear</b> button will be displayed when the component gains focus or when the mouse hovers over it."
27842786
},
27852787
"BootstrapBlazor.Server.Components.Samples.InputNumbers": {
27862788
"InputNumbersTitle": "InputNumber",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2780,7 +2780,9 @@
27802780
"InputsFormatStringSetting": "设置",
27812781
"InputsFormatStringTips": "<code>BootstrapInput</code> 组件绑定 <code>byte[]</code> 数组,格式化成 <code>base64</code> 编码字符串示例",
27822782
"UseInputEvent": "是否在文本框输入值时触发",
2783-
"IsTrim": "是否自动去除空格"
2783+
"IsTrim": "是否自动去除空格",
2784+
"ClearableTitle": "清除",
2785+
"ClearableIntro": "通过设置 <code>Clearable=\"true\"</code> 参数,使组件获得焦点或者鼠标悬浮时显示一个 <b>清除</b> 小按钮"
27842786
},
27852787
"BootstrapBlazor.Server.Components.Samples.InputNumbers": {
27862788
"InputNumbersTitle": "InputNumber 组件",

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.2.0-beta03</Version>
4+
<Version>9.2.0-beta01</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Input/BootstrapInput.razor

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,25 @@
77
<BootstrapLabel required="@Required" for="@Id" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
88
}
99

10-
<input @attributes="@AdditionalAttributes" type="@Type" placeholder="@PlaceHolder" id="@Id" readonly="@ReadonlyString" class="@ClassName" disabled="@Disabled" @bind-value="CurrentValueAsString" @bind-value:event="@EventString" @onblur="@OnBlur" @ref="FocusElement" />
10+
@if (Clearable)
11+
{
12+
<div class="bb-clearable-input">
13+
@RenderInput
14+
@if (!IsDisabled && !Readonly)
15+
{
16+
<i class="@ClearableIconString" @onclick="OnClickClear"></i>
17+
}
18+
</div>
19+
}
20+
else
21+
{
22+
@RenderInput
23+
}
24+
25+
@code {
26+
RenderFragment RenderInput =>
27+
@<input @attributes="@AdditionalAttributes" type="@Type" id="@Id" class="@ClassName"
28+
readonly="@ReadonlyString" disabled="@Disabled"
29+
placeholder="@PlaceHolder"
30+
@bind-value="CurrentValueAsString" @bind-value:event="@EventString" @onblur="@OnBlur" @ref="FocusElement" />;
31+
}

src/BootstrapBlazor/Components/Input/BootstrapInput.razor.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,47 @@ public partial class BootstrapInput<TValue>
2222
[Parameter]
2323
public bool AutoSetDefaultWhenNull { get; set; }
2424

25+
/// <summary>
26+
/// 获得/设置 是否显示清空小按钮 默认 false
27+
/// </summary>
28+
[Parameter]
29+
public bool Clearable { get; set; }
30+
31+
/// <summary>
32+
/// 获得/设置 清空文本框时回调方法 默认 null
33+
/// </summary>
34+
[Parameter]
35+
public Func<TValue, Task>? OnClear { get; set; }
36+
37+
/// <summary>
38+
/// 获得/设置 清空小按钮图标 默认 null
39+
/// </summary>
40+
[Parameter]
41+
public string? ClearableIcon { get; set; }
42+
43+
/// <summary>
44+
/// 图标主题服务
45+
/// </summary>
46+
[Inject]
47+
[NotNull]
48+
private IIconTheme? IconTheme { get; set; }
49+
2550
private string? ReadonlyString => Readonly ? "true" : null;
2651

52+
private string? ClearableIconString => CssBuilder.Default("form-control-clear-icon")
53+
.AddClass(ClearableIcon)
54+
.Build();
55+
56+
/// <summary>
57+
/// <inheritdoc/>
58+
/// </summary>
59+
protected override void OnParametersSet()
60+
{
61+
base.OnParametersSet();
62+
63+
ClearableIcon ??= IconTheme.GetIconByKey(ComponentIcons.InputClearIcon);
64+
}
65+
2766
/// <summary>
2867
/// <inheritdoc/>
2968
/// </summary>
@@ -47,4 +86,13 @@ protected override bool TryParseValueFromString(string value, [MaybeNullWhen(fal
4786
}
4887
return ret;
4988
}
89+
90+
private async Task OnClickClear()
91+
{
92+
if (OnClear != null)
93+
{
94+
await OnClear(Value);
95+
}
96+
CurrentValueAsString = "";
97+
}
5098
}

src/BootstrapBlazor/Components/Input/BootstrapInput.razor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function handleKeyUp(id, invoke, enter, enterCallbackMethod, esc, escCall
1111
const el = document.getElementById(id)
1212
if (el) {
1313
EventHandler.on(el, 'keyup', e => {
14-
if (enter && e.key === 'Enter') {
14+
if (enter && (e.key === 'Enter' || e.key === 'NumpadEnter')) {
1515
invoke.invokeMethodAsync(enterCallbackMethod, el.value)
1616
}
1717
else if (esc && e.key === 'Escape') {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.bb-clearable-input {
2+
display: inline-flex;
3+
align-items: center;
4+
flex-grow: 1;
5+
width: 100%;
6+
position: relative;
7+
8+
> input {
9+
width: 100%;
10+
flex-grow: 1;
11+
padding-right: 2rem;
12+
13+
+ .form-control-clear-icon {
14+
color: var(--bb-border-hover-color);
15+
cursor: pointer;
16+
position: absolute;
17+
right: 10px;
18+
display: none;
19+
}
20+
21+
&:focus + .form-control-clear-icon {
22+
display: block;
23+
}
24+
}
25+
26+
&:hover .form-control-clear-icon {
27+
display: block;
28+
}
29+
}

src/BootstrapBlazor/Components/Input/BootstrapInputGroup.razor.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
> .datetime-picker,
33
> .select,
44
> .switch,
5+
> .bb-clearable-input,
56
> .auto-complete {
67
width: 1%;
78
flex: 1 1 auto;
@@ -39,6 +40,20 @@
3940
}
4041
}
4142
}
43+
44+
> .bb-clearable-input:not(:first-child) {
45+
> input {
46+
border-top-left-radius: 0;
47+
border-bottom-left-radius: 0;
48+
}
49+
}
50+
51+
> .bb-clearable-input:not(:last-child) {
52+
> input {
53+
border-top-right-radius: 0;
54+
border-bottom-right-radius: 0;
55+
}
56+
}
4257
}
4358

4459
.input-group-xs {

src/BootstrapBlazor/Components/Modal/ModalDialog.razor.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,17 @@ export function init(id) {
134134
}
135135

136136
const update = el => {
137-
const width = el.offsetWidth / 2;
137+
138138
const height = el.offsetHeight / 2;
139+
const marginTop = parseFloat(getComputedStyle(el).marginTop);
140+
const viewBoxHeight = window.innerHeight / 2;
141+
if (viewBoxHeight - height - marginTop > 0) {
142+
el.style.setProperty("margin-top", `calc(50vh - ${height}px)`);
143+
}
139144

145+
const width = el.offsetWidth / 2;
140146
el.style.setProperty("margin-left", `calc(50vw - ${width}px)`);
141-
el.style.setProperty("margin-top", `calc(50vh - ${height}px)`);
147+
142148
el.classList.remove('is-draggable-center');
143149
}
144150

0 commit comments

Comments
 (0)