Skip to content

Commit 12e71d6

Browse files
authored
fix(Input): prevent focus exception (#6920)
* refactor: 移除 FocusElement 定义 * feat: 改用 focus 自定义方法 * chore: bump version 9.11.3-beta02
1 parent 26cc74a commit 12e71d6

File tree

10 files changed

+16
-14
lines changed

10 files changed

+16
-14
lines changed

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.11.3-beta01</Version>
4+
<Version>9.11.3-beta02</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
data-bb-auto-dropdown-focus="@ShowDropdownListOnFocusString" data-bb-debounce="@DurationString"
1313
data-bb-skip-esc="@SkipEscString" data-bb-skip-enter="@SkipEnterString" data-bb-blur="@TriggerBlurString"
1414
data-bb-scroll-behavior="@ScrollIntoViewBehaviorString" data-bb-trigger-delete="true"
15-
placeholder="@PlaceHolder" disabled="@Disabled" @ref="FocusElement"/>
15+
placeholder="@PlaceHolder" disabled="@Disabled" />
1616
<span class="form-select-append"><i class="@Icon"></i></span>
1717
<span class="form-select-append ac-loading"><i class="@LoadingIcon"></i></span>
1818
@if (GetClearable())

src/BootstrapBlazor/Components/AutoFill/AutoFill.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
data-bb-auto-dropdown-focus="@ShowDropdownListOnFocusString" data-bb-debounce="@DurationString"
1515
data-bb-skip-esc="@SkipEscString" data-bb-skip-enter="@SkipEnterString"
1616
data-bb-scroll-behavior="@ScrollIntoViewBehaviorString"
17-
placeholder="@PlaceHolder" disabled="@Disabled" @ref="FocusElement" />
17+
placeholder="@PlaceHolder" disabled="@Disabled" />
1818
<span class="form-select-append"><i class="@Icon"></i></span>
1919
<span class="form-select-append ac-loading"><i class="@LoadingIcon"></i></span>
2020
@if (GetClearable())

src/BootstrapBlazor/Components/Input/BootstrapInput.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ else
2727
@<input @attributes="@AdditionalAttributes" type="@Type" id="@Id" class="@ClassName"
2828
readonly="@ReadonlyString" disabled="@Disabled"
2929
placeholder="@PlaceHolder"
30-
@bind-value="CurrentValueAsString" @bind-value:event="@EventString" @onblur="@OnBlur" @ref="FocusElement" />;
30+
@bind-value="CurrentValueAsString" @bind-value:event="@EventString" @onblur="@OnBlur" />;
3131
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import EventHandler from "../../modules/event-handler.js"
22

3+
export function focus(id) {
4+
const el = document.getElementById(id)
5+
if (el) {
6+
el.focus();
7+
}
8+
}
9+
310
export function clear(id) {
411
const el = document.getElementById(id)
512
if (el) {

src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ public abstract class BootstrapInputBase<TValue> : ValidateBase<TValue>
1919
.AddClass(CssClass).AddClass(ValidCss)
2020
.Build();
2121

22-
/// <summary>
23-
/// Gets or sets Element reference instance
24-
/// </summary>
25-
protected ElementReference FocusElement { get; set; }
26-
2722
/// <summary>
2823
/// Gets or sets the placeholder attribute value
2924
/// </summary>
@@ -102,7 +97,7 @@ public abstract class BootstrapInputBase<TValue> : ValidateBase<TValue>
10297
/// Method to focus the element
10398
/// </summary>
10499
/// <returns></returns>
105-
public async Task FocusAsync() => await FocusElement.FocusAsync();
100+
public async Task FocusAsync() => await InvokeVoidAsync("focus", GetInputId());
106101

107102
/// <summary>
108103
/// Method to select all text

src/BootstrapBlazor/Components/Input/FloatingLabel.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
@inherits BootstrapInputBase<TValue>
44

55
<div class="@ClassString">
6-
<input @attributes="@AdditionalAttributes" type="@Type" id="@Id" placeholder="@PlaceHolder" class="@ClassName" disabled="@Disabled" @bind-value="@CurrentValueAsString" @onblur="@OnBlur" @ref="FocusElement" />
6+
<input @attributes="@AdditionalAttributes" type="@Type" id="@Id" placeholder="@PlaceHolder" class="@ClassName" disabled="@Disabled" @bind-value="@CurrentValueAsString" @onblur="@OnBlur" />
77
<label for="@Id">@DisplayText</label>
88
</div>

src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ else
2525

2626
@code {
2727
RenderFragment RenderInput =>
28-
@<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" />;
28+
@<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" />;
2929
}

src/BootstrapBlazor/Components/Search/Search.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
data-bb-skip-esc="@SkipEscString" data-bb-skip-enter="@SkipEnterString" data-bb-blur="@TriggerBlurString"
3030
data-bb-scroll-behavior="@ScrollIntoViewBehaviorString"
3131
data-bb-input="@UseInputString"
32-
placeholder="@PlaceHolder" disabled="@Disabled" @ref="FocusElement" />
32+
placeholder="@PlaceHolder" disabled="@Disabled" />
3333
@if (IsClearable)
3434
{
3535
<div class="search-clear-icon">

src/BootstrapBlazor/Components/Textarea/Textarea.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
}
99
<textarea @attributes="AdditionalAttributes" placeholder="@PlaceHolder" id="@Id" class="@ClassName" disabled="@Disabled"
1010
@bind-value="CurrentValueAsString" @bind-value:event="@EventString" @onblur="@OnBlur"
11-
data-bb-shift-enter="@ShiftEnterString" data-bb-scroll="@AutoScrollString" @ref="FocusElement"></textarea>
11+
data-bb-shift-enter="@ShiftEnterString" data-bb-scroll="@AutoScrollString"></textarea>

0 commit comments

Comments
 (0)