Skip to content

Commit dbb9b8d

Browse files
authored
refactor(AutoComplete): auto close dropdown box after press tab (#5833)
1 parent daf5f10 commit dbb9b8d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,20 @@ export function init(id, invoke) {
106106
}
107107
});
108108
}
109+
ac.blur = e => {
110+
if (e.key === 'Tab') {
111+
[...document.querySelectorAll('.auto-complete.show')].forEach(a => {
112+
const id = a.getAttribute('id');
113+
const d = Data.get(id);
114+
if (d) {
115+
d.close();
116+
}
117+
});
118+
}
119+
}
109120
registerBootstrapBlazorModule('AutoComplete', id, () => {
110121
EventHandler.on(document, 'click', ac.closePopover);
122+
EventHandler.on(document, 'keyup', ac.blur);
111123
});
112124
}
113125

@@ -131,7 +143,7 @@ const handlerKeyup = (ac, e) => {
131143
}
132144
}
133145
else if (key === 'ArrowUp' || key === 'ArrowDown') {
134-
el.classList.add('show');
146+
ac.show();
135147
const items = [...menu.querySelectorAll('.dropdown-item')];
136148
let current = menu.querySelector('.active');
137149
if (current !== null) {
@@ -171,6 +183,7 @@ export function dispose(id) {
171183
const { AutoComplete } = window.BootstrapBlazor;
172184
AutoComplete.dispose(id, () => {
173185
EventHandler.off(document, 'click', ac.closePopover);
186+
EventHandler.off(document, 'keyup', ac.blur);
174187
});
175188
}
176189

0 commit comments

Comments
 (0)