@@ -63,6 +63,8 @@ export type ModalProps = {
6363 defaultCurrency ?: string ;
6464 currencyPosition ?: currencyPosition ;
6565 responsive ?: boolean ;
66+ open ?: boolean ;
67+ onOpenChange ?: ( open : boolean ) => void ;
6668 debounceMs ?: number ;
6769} ;
6870
@@ -151,17 +153,17 @@ function ModalProvider({
151153 } ) ;
152154 const [ query , setQuery ] = useState ( "" ) ;
153155 const [ results , setResults ] = useState < ChunkWithHighlights [ ] | GroupChunk [ ] > (
154- [ ]
156+ [ ] ,
155157 ) ;
156158 const [ requestID , setRequestID ] = useState ( "" ) ;
157159 const [ loadingResults , setLoadingResults ] = useState ( false ) ;
158- const [ open , setOpen ] = useState ( false ) ;
160+ const [ open , setOpen ] = useState ( props . open ?? false ) ;
159161 const inputRef = useRef < HTMLInputElement > ( null ) ;
160162 const [ mode , setMode ] = useState ( props . defaultSearchMode || "search" ) ;
161163 const modalRef = useRef < HTMLDivElement > ( null ) ;
162164 const [ tagCounts , setTagCounts ] = useState < CountChunkQueryResponseBody [ ] > ( [ ] ) ;
163165 const [ currentTag , setCurrentTag ] = useState (
164- props . tags ?. find ( ( t ) => t . selected ) ?. tag || "all"
166+ props . tags ?. find ( ( t ) => t . selected ) ?. tag || "all" ,
165167 ) ;
166168
167169 const trieve = new TrieveSDK ( {
@@ -177,6 +179,10 @@ function ModalProvider({
177179 } ) ) ;
178180 } , [ onLoadProps ] ) ;
179181
182+ useEffect ( ( ) => {
183+ props . onOpenChange ?.( open ) ;
184+ } , [ open ] ) ;
185+
180186 const search = async ( abortController : AbortController ) => {
181187 if ( ! query ) {
182188 setResults ( [ ] ) ;
@@ -247,8 +253,8 @@ function ModalProvider({
247253 trieve : trieve ,
248254 abortController,
249255 ...( tag . tag !== "all" && { tag : tag . tag } ) ,
250- } )
251- )
256+ } ) ,
257+ ) ,
252258 ) ;
253259 setTagCounts ( numberOfRecords ) ;
254260 } catch ( e ) {
@@ -304,8 +310,7 @@ function ModalProvider({
304310 currentTag,
305311 setCurrentTag,
306312 tagCounts,
307- } }
308- >
313+ } } >
309314 { children }
310315 </ ModalContext . Provider >
311316 ) ;
0 commit comments