Skip to content

Commit 8519e4c

Browse files
committed
refactor: 增加 triggerBlur 方法
1 parent 6ff8822 commit 8519e4c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function init(id, invoke) {
3333
})
3434
}
3535

36-
EventHandler.on(input, 'blur', e => {
36+
ac.triggerBlur = () => {
3737
el.classList.remove('show');
3838
const triggerBlur = input.getAttribute('data-bb-blur') === 'true';
3939
if (triggerBlur) {
@@ -81,7 +81,11 @@ export function init(id, invoke) {
8181

8282
const el = a.querySelector('[data-bs-toggle="bb.dropdown"]');
8383
if (el === null) {
84-
a.classList.remove('show');
84+
const id = a.getAttribute('id');
85+
const d = Data.get(id);
86+
if (d) {
87+
d.triggerBlur();
88+
}
8589
}
8690
});
8791
}
@@ -99,7 +103,7 @@ const handlerKeyup = (ac, e) => {
99103
const current = menu.querySelector('.active');
100104
if (current !== null) {
101105
current.click();
102-
input.blur();
106+
ac.triggerBlur();
103107
}
104108
invoke.invokeMethodAsync('EnterCallback', input.value);
105109
}
@@ -108,7 +112,7 @@ const handlerKeyup = (ac, e) => {
108112
const skipEsc = el.getAttribute('data-bb-skip-esc') === 'true';
109113
if (skipEsc === false) {
110114
invoke.invokeMethodAsync('EscCallback');
111-
input.blur();
115+
ac.triggerBlur();
112116
}
113117
}
114118
else if (key === 'ArrowUp' || key === 'ArrowDown') {
@@ -158,7 +162,6 @@ export function dispose(id) {
158162
}
159163
EventHandler.off(input, 'change');
160164
EventHandler.off(input, 'keyup');
161-
EventHandler.off(input, 'blur');
162165
Input.dispose(input);
163166

164167
const { AutoComplete } = window.BootstrapBlazor;

0 commit comments

Comments
 (0)