Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
data-bb-auto-dropdown-focus="@ShowDropdownListOnFocusString" data-bb-debounce="@DurationString"
data-bb-skip-esc="@SkipEscString" data-bb-skip-enter="@SkipEnterString" data-bb-blur="@TriggerBlurString"
data-bb-scroll-behavior="@ScrollIntoViewBehaviorString" data-bb-trigger-delete="true"
@bind="@CurrentValueAsString" @onblur="@OnBlur"
@bind="@CurrentValueAsString"
placeholder="@PlaceHolder" disabled="@Disabled" @ref="FocusElement"/>
<span class="form-select-append"><i class="@Icon"></i></span>
<span class="form-select-append ac-loading"><i class="@LoadingIcon"></i></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ private async Task OnClickItem(string val)
{
await OnSelectedItemChanged(val);
}

if (OnBlurAsync != null)
{
await OnBlurAsync(Value);
}
}

private List<string> Rows => _filterItems ?? [.. Items];
Expand Down
20 changes: 16 additions & 4 deletions src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function init(id, invoke) {
const el = document.getElementById(id)
const menu = el.querySelector('.dropdown-menu')
const input = document.getElementById(`${id}_input`)
const ac = { el, invoke, menu }
const ac = { el, invoke, menu, input }
Data.set(id, ac)

const isPopover = input.getAttribute('data-bs-toggle') === 'bb.dropdown';
Expand Down Expand Up @@ -102,24 +102,36 @@ export function init(id, invoke) {
const d = Data.get(id);
if (d) {
d.close();
d.blur();
}
}
});
}
ac.blur = e => {

ac.keyup = e => {
if (e.key === 'Tab') {
[...document.querySelectorAll('.auto-complete.show')].forEach(a => {
const id = a.getAttribute('id');
const d = Data.get(id);
if (d) {
d.close();
d.blur();
}
});
}
}

ac.blur = function () {
const { input, invoke } = this;
const triggerBlur = input.getAttribute('data-bb-blur') === 'true';
if (triggerBlur) {
invoke.invokeMethodAsync('TriggerBlur');
}
}

registerBootstrapBlazorModule('AutoComplete', id, () => {
EventHandler.on(document, 'click', ac.closePopover);
EventHandler.on(document, 'keyup', ac.blur);
EventHandler.on(document, 'keyup', ac.keyup);
});
}

Expand Down Expand Up @@ -183,7 +195,7 @@ export function dispose(id) {
const { AutoComplete } = window.BootstrapBlazor;
AutoComplete.dispose(id, () => {
EventHandler.off(document, 'click', ac.closePopover);
EventHandler.off(document, 'keyup', ac.blur);
EventHandler.off(document, 'keyup', ac.keyup);
});
}

Expand Down
12 changes: 12 additions & 0 deletions src/BootstrapBlazor/Components/AutoComplete/PopoverCompleteBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,16 @@ protected override void OnParametersSet()
/// </summary>
/// <returns></returns>
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop);

/// <summary>
/// 触发 OnBlur 回调方法 由 Javascript 触发
/// </summary>
[JSInvokable]
public async Task TriggerBlur()
{
if (OnBlurAsync != null)
{
await OnBlurAsync(Value);
}
}
}
Loading