* @param container - Parent container element * @param onSearch - Callback function called when search term changes * @param debounceMs - Debounce delay in milliseconds (default: 300)
( container: HTMLElement, onSearch: (term: string) => void, debounceMs = 300 )
| 25 | * @param debounceMs - Debounce delay in milliseconds (default: 300) |
| 26 | */ |
| 27 | constructor( |
| 28 | container: HTMLElement, |
| 29 | onSearch: (term: string) => void, |
| 30 | debounceMs = 300 |
| 31 | ) { |
| 32 | this.container = container; |
| 33 | this.onSearch = onSearch; |
| 34 | this.debounceMs = debounceMs; |
| 35 | |
| 36 | // Create debounced search handler with destroyed check |
| 37 | this.debouncedSearch = debounce( |
| 38 | (term: string) => { |
| 39 | // Don't execute if component has been destroyed |
| 40 | if (!this.destroyed) { |
| 41 | this.onSearch(term); |
| 42 | } |
| 43 | }, |
| 44 | this.debounceMs, |
| 45 | false // trailing debounce |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Render the search box UI |
nothing calls this directly
no test coverage detected