From 246fd8730264da6ca706cde89faa48555f3f2c95 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 16 Apr 2025 19:02:31 -0700 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=20Tab=20?= =?UTF-8?q?=E6=8C=89=E9=94=AE=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/AutoComplete/AutoComplete.razor.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js b/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js index 33efe4cd3ce..fa26a60dbc9 100644 --- a/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js +++ b/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js @@ -106,8 +106,20 @@ export function init(id, invoke) { } }); } + ac.blur = 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(); + } + }); + } + } registerBootstrapBlazorModule('AutoComplete', id, () => { EventHandler.on(document, 'click', ac.closePopover); + EventHandler.on(document, 'keyup', ac.blur); }); } @@ -131,7 +143,7 @@ const handlerKeyup = (ac, e) => { } } else if (key === 'ArrowUp' || key === 'ArrowDown') { - el.classList.add('show'); + ac.show(); const items = [...menu.querySelectorAll('.dropdown-item')]; let current = menu.querySelector('.active'); if (current !== null) { @@ -171,6 +183,7 @@ export function dispose(id) { const { AutoComplete } = window.BootstrapBlazor; AutoComplete.dispose(id, () => { EventHandler.off(document, 'click', ac.closePopover); + EventHandler.off(document, 'keyup', ac.blur); }); }