Skip to content

Commit 678ee72

Browse files
committed
refactor: 精简代码
1 parent 301c65b commit 678ee72

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,29 +72,22 @@ export function init(id, invoke) {
7272
filterCallback(v);
7373
});
7474

75-
const module = registerBootstrapBlazorModule('AutoComplete', {
76-
hooked: false,
77-
registerCloseDropdownHandler: function () {
78-
if (this.hooked === false) {
79-
this.hooked = true;
80-
81-
EventHandler.on(document, 'click', e => {
82-
[...document.querySelectorAll('.auto-complete.show')].forEach(a => {
83-
const ac = e.target.closest('.auto-complete');
84-
if (ac === a) {
85-
return;
86-
}
87-
88-
const el = a.querySelector('[data-bs-toggle="bb.dropdown"]');
89-
if (el === null) {
90-
a.classList.remove('show');
91-
}
92-
});
93-
});
75+
ac.closePopover = e => {
76+
[...document.querySelectorAll('.auto-complete.show')].forEach(a => {
77+
const ac = e.target.closest('.auto-complete');
78+
if (ac === a) {
79+
return;
9480
}
95-
}
81+
82+
const el = a.querySelector('[data-bs-toggle="bb.dropdown"]');
83+
if (el === null) {
84+
a.classList.remove('show');
85+
}
86+
});
87+
}
88+
registerBootstrapBlazorModule('AutoComplete', id, () => {
89+
EventHandler.on(document, 'click', ac.closePopover);
9690
});
97-
module.registerCloseDropdownHandler();
9891
}
9992

10093
const handlerKeyup = (ac, e) => {
@@ -168,6 +161,11 @@ export function dispose(id) {
168161
EventHandler.off(input, 'blur');
169162
Input.dispose(input);
170163
}
164+
165+
const { AutoComplete } = window.BootstrapBlazor;
166+
AutoComplete.dispose(id, () => {
167+
EventHandler.off(document, 'click', ac.closePopover);
168+
});
171169
}
172170

173171
const scrollIntoView = (el, item) => {

0 commit comments

Comments
 (0)