1- import { getHeight , getInnerHeight , getTransitionDelayDurationFromElement } from "../../modules/utility.js"
1+ import { debounce , getHeight , getInnerHeight , getTransitionDelayDurationFromElement } from "../../modules/utility.js"
22import Data from "../../modules/data.js"
33import EventHandler from "../../modules/event-handler.js"
44import Popover from "../../modules/base-popover.js"
55
6- export function init ( id , invoke , method ) {
6+ export function init ( id , invoke , options ) {
77 const el = document . getElementById ( id )
8-
8+ const { confirmMethodCallback , searchMethodCallback } = options ;
99 if ( el == null ) {
1010 return
1111 }
@@ -64,7 +64,7 @@ export function init(id, invoke, method) {
6464 if ( e . key === "Enter" ) {
6565 popover . toggleMenu . classList . remove ( 'show' )
6666 let index = indexOf ( el , activeItem )
67- invoke . invokeMethodAsync ( method , index )
67+ invoke . invokeMethodAsync ( confirmMethodCallback , index )
6868 }
6969 }
7070 }
@@ -77,7 +77,27 @@ export function init(id, invoke, method) {
7777 el,
7878 popover
7979 }
80- Data . set ( id , select )
80+ Data . set ( id , select ) ;
81+
82+ const onSearch = debounce ( v => invoke . invokeMethodAsync ( searchMethodCallback , v ) ) ;
83+ let isComposing = false ;
84+
85+ EventHandler . on ( el , 'input' , '.search-text' , e => {
86+ if ( isComposing ) {
87+ return ;
88+ }
89+
90+ onSearch ( e . delegateTarget . value ) ;
91+ } ) ;
92+
93+ EventHandler . on ( el , 'compositionstart' , '.search-text' , e => {
94+ isComposing = true ;
95+ } ) ;
96+
97+ EventHandler . on ( el , 'compositionend' , '.search-text' , e => {
98+ isComposing = false ;
99+ onSearch ( e . delegateTarget . value ) ;
100+ } ) ;
81101}
82102
83103export function show ( id ) {
@@ -108,7 +128,10 @@ export function dispose(id) {
108128
109129 if ( select ) {
110130 EventHandler . off ( select . el , 'shown.bs.dropdown' )
111- EventHandler . off ( select . el , 'keydown' )
131+ EventHandler . off ( select . el , 'keydown' ) ;
132+ EventHandler . off ( select . el , 'input' ) ;
133+ EventHandler . off ( select . el , 'compositionstart' ) ;
134+ EventHandler . off ( select . el , 'compositionend' )
112135 Popover . dispose ( select . popover )
113136 }
114137}
0 commit comments