11/* eslint-disable no-undef */
22import { ApolloError } from '@apollo/client' ;
3- import { SearchFunction , SearchResult } from 'hds-react' ;
3+ import { Option , SearchFunction , SearchResult , SelectData } from 'hds-react' ;
44import React , { useCallback } from 'react' ;
55import { useTranslation } from 'react-i18next' ;
66
@@ -93,18 +93,6 @@ const SingleKeywordSelector: React.FC<SingleKeywordSelectorProps> = ({
9393 }
9494 } , [ keywordsOptions , keywordsData ] ) ;
9595
96- const handleChange = React . useCallback (
97- ( ...args : unknown [ ] ) => {
98- setOptions ( initialOptions . current ) ;
99-
100- if ( onChange ) {
101- // eslint-disable-next-line @typescript-eslint/no-explicit-any
102- ( onChange as any ) ( ...args ) ;
103- }
104- } ,
105- [ onChange ]
106- ) ;
107-
10896 const handleSearch : SearchFunction = React . useCallback (
10997 async ( searchValue : string ) : Promise < SearchResult > => {
11098 try {
@@ -116,21 +104,32 @@ const SingleKeywordSelector: React.FC<SingleKeywordSelectorProps> = ({
116104 throw error ;
117105 }
118106
119- const newOptions = getValue (
120- newkeywordsData ?. keywords . data . map ( ( keyword ) =>
121- getOption ( { keyword : keyword as KeywordFieldsFragment , locale } )
107+ return {
108+ options : getValue (
109+ newkeywordsData ?. keywords . data . map ( ( keyword ) =>
110+ getOption ( { keyword : keyword as KeywordFieldsFragment , locale } )
111+ ) ,
112+ [ ]
122113 ) ,
123- [ ]
124- ) ;
125-
126- return { options : newOptions } ;
114+ } ;
127115 } catch ( error ) {
128116 return Promise . reject ( error as ApolloError ) ;
129117 }
130118 } ,
131119 [ refetch , locale ]
132120 ) ;
133121
122+ const handleChange = React . useCallback (
123+ ( selectedOptions : Option [ ] , clickedOption : Option , data : SelectData ) => {
124+ setOptions ( initialOptions . current ) ;
125+
126+ if ( onChange ) {
127+ onChange ( selectedOptions , clickedOption , data ) ;
128+ }
129+ } ,
130+ [ onChange ]
131+ ) ;
132+
134133 const selectedKeyword = React . useMemo (
135134 ( ) =>
136135 keywordData ?. keyword
0 commit comments