Skip to content

Commit ad6763b

Browse files
committed
refactor: 增加客户端设置值逻辑
1 parent fa4df4b commit ad6763b

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
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-
@bind="@CurrentValueAsString"
1615
placeholder="@PlaceHolder" disabled="@Disabled" @ref="FocusElement"/>
1716
<span class="form-select-append"><i class="@Icon"></i></span>
1817
<span class="form-select-append ac-loading"><i class="@LoadingIcon"></i></span>

src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ protected override void OnParametersSet()
119119
LoadingIcon ??= IconTheme.GetIconByKey(ComponentIcons.LoadingIcon);
120120
}
121121

122+
/// <summary>
123+
/// <inheritdoc/>
124+
/// </summary>
125+
/// <returns></returns>
126+
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, Value);
127+
122128
/// <summary>
123129
/// Callback method when a candidate item is clicked
124130
/// </summary>
@@ -137,6 +143,9 @@ private async Task OnClickItem(string val)
137143
}
138144

139145
await TriggerFilter(val);
146+
147+
// 使用脚本更新 input 值
148+
await InvokeVoidAsync("setValue", Id, val);
140149
}
141150

142151
private List<string> Rows => _filterItems ?? [.. Items];

src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ const handlerKeyup = (ac, e) => {
175175
}
176176
}
177177

178+
export function setValue(id, value) {
179+
const ac = Data.get(id)
180+
const { input } = ac;
181+
if (input) {
182+
input.value = value;
183+
}
184+
}
185+
178186
export function dispose(id) {
179187
const ac = Data.get(id)
180188
Data.remove(id)

src/BootstrapBlazor/Components/AutoComplete/PopoverCompleteBase.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,6 @@ protected override void OnParametersSet()
158158
Offset ??= "[0, 6]";
159159
}
160160

161-
/// <summary>
162-
/// <inheritdoc/>
163-
/// </summary>
164-
/// <returns></returns>
165-
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop);
166-
167161
/// <summary>
168162
/// 触发 OnBlur 回调方法 由 Javascript 触发
169163
/// </summary>

0 commit comments

Comments
 (0)