@@ -26,65 +26,6 @@ export function init(id, invoke, options) {
2626 popover
2727 }
2828
29- const onSearch = debounce ( async v => {
30- search . parentElement . classList . add ( 'l' ) ;
31- await invoke . invokeMethodAsync ( 'TriggerOnSearch' , v ) ;
32- search . parentElement . classList . remove ( 'l' ) ;
33- } ) ;
34-
35- const shown = ( ) => {
36- if ( search ) {
37- search . focus ( ) ;
38- }
39- const active = popover . toggleMenu . querySelector ( '.dropdown-item.active' ) ;
40- if ( active ) {
41- scrollIntoView ( el , active ) ;
42- }
43- }
44-
45- const keydown = e => {
46- const menu = popover . toggleMenu ;
47- const key = e . key ;
48- if ( key === "Enter" || key === 'NumpadEnter' ) {
49- if ( popover . isPopover ) {
50- popover . hide ( ) ;
51- }
52- else {
53- menu . classList . remove ( 'show' ) ;
54- }
55- const activeItem = menu . querySelector ( '.active' ) ;
56- let index = indexOf ( menu , activeItem )
57- invoke . invokeMethodAsync ( confirmMethodCallback , index )
58- }
59- else if ( key === 'ArrowUp' || key === 'ArrowDown' ) {
60- e . preventDefault ( ) ;
61-
62- if ( menu . querySelector ( '.dropdown-virtual' ) ) {
63- return ;
64- }
65-
66- const items = [ ...menu . querySelectorAll ( '.dropdown-item:not(.disabled)' ) ] ;
67- if ( items . length > 0 ) {
68- let current = menu . querySelector ( '.active' ) ;
69- if ( current !== null ) {
70- current . classList . remove ( 'active' ) ;
71- }
72-
73- let index = current === null ? - 1 : items . indexOf ( current ) ;
74- index = key === 'ArrowUp' ? index - 1 : index + 1 ;
75- if ( index < 0 ) {
76- index = items . length - 1 ;
77- }
78- else if ( index > items . length - 1 ) {
79- index = 0 ;
80- }
81- current = items [ index ] ;
82- current . classList . add ( 'active' ) ;
83- scrollIntoView ( el , current ) ;
84- }
85- }
86- }
87-
8829 Input . composition ( search , onSearch ) ;
8930 EventHandler . on ( search , 'keydown' , keydown ) ;
9031
@@ -182,13 +123,3 @@ export function dispose(id) {
182123 EventHandler . off ( search , 'keydown' ) ;
183124 }
184125}
185-
186- function indexOf ( el , element ) {
187- const items = el . querySelectorAll ( '.dropdown-item' )
188- return Array . prototype . indexOf . call ( items , element )
189- }
190-
191- const scrollIntoView = ( el , item ) => {
192- const behavior = el . getAttribute ( 'data-bb-scroll-behavior' ) ?? 'smooth' ;
193- item . scrollIntoView ( { behavior : behavior , block : "nearest" , inline : "start" } ) ;
194- }
0 commit comments