@@ -9,7 +9,7 @@ export function init(id, invoke) {
99 const el = document . getElementById ( id )
1010 const menu = el . querySelector ( '.dropdown-menu' )
1111 const input = document . getElementById ( `${ id } _input` )
12- const ac = { el, invoke, menu }
12+ const ac = { el, invoke, menu, input }
1313 Data . set ( id , ac )
1414
1515 const isPopover = input . getAttribute ( 'data-bs-toggle' ) === 'bb.dropdown' ;
@@ -102,24 +102,36 @@ export function init(id, invoke) {
102102 const d = Data . get ( id ) ;
103103 if ( d ) {
104104 d . close ( ) ;
105+ d . blur ( ) ;
105106 }
106107 }
107108 } ) ;
108109 }
109- ac . blur = e => {
110+
111+ ac . keyup = e => {
110112 if ( e . key === 'Tab' ) {
111113 [ ...document . querySelectorAll ( '.auto-complete.show' ) ] . forEach ( a => {
112114 const id = a . getAttribute ( 'id' ) ;
113115 const d = Data . get ( id ) ;
114116 if ( d ) {
115117 d . close ( ) ;
118+ d . blur ( ) ;
116119 }
117120 } ) ;
118121 }
119122 }
123+
124+ ac . blur = function ( ) {
125+ const { input, invoke } = this ;
126+ const triggerBlur = input . getAttribute ( 'data-bb-blur' ) === 'true' ;
127+ if ( triggerBlur ) {
128+ invoke . invokeMethodAsync ( 'TriggerBlur' ) ;
129+ }
130+ }
131+
120132 registerBootstrapBlazorModule ( 'AutoComplete' , id , ( ) => {
121133 EventHandler . on ( document , 'click' , ac . closePopover ) ;
122- EventHandler . on ( document , 'keyup' , ac . blur ) ;
134+ EventHandler . on ( document , 'keyup' , ac . keyup ) ;
123135 } ) ;
124136}
125137
@@ -183,7 +195,7 @@ export function dispose(id) {
183195 const { AutoComplete } = window . BootstrapBlazor ;
184196 AutoComplete . dispose ( id , ( ) => {
185197 EventHandler . off ( document , 'click' , ac . closePopover ) ;
186- EventHandler . off ( document , 'keyup' , ac . blur ) ;
198+ EventHandler . off ( document , 'keyup' , ac . keyup ) ;
187199 } ) ;
188200}
189201
0 commit comments