@@ -21,6 +21,7 @@ export default function KernDropdown(props: KernDropdownProps) {
21
21
const [ disabledOptions , setDisabledOptions ] = useState < boolean [ ] > ( [ ] ) ;
22
22
const [ backgroundColors , setBackgroundColors ] = useState < string [ ] > ( [ ] ) ;
23
23
const [ searchText , setSearchText ] = useState ( '' ) ;
24
+ const [ searchIndexes , setSearchIndexes ] = useState < number [ ] > ( ) ;
24
25
const [ isOpen , setIsOpen_ ] = useState ( false ) ;
25
26
const [ selectedCheckboxes , setSelectedCheckboxes ] = useState < any [ ] > ( [ ] ) ;
26
27
const [ position , setPosition ] = useState ( null ) ;
@@ -51,11 +52,15 @@ export default function KernDropdown(props: KernDropdownProps) {
51
52
useEffect ( ( ) => {
52
53
const prepareOptions = prepareDropdownOptionsToArray ( props . options , props . hasSearchBar , props . valuePropertyPath ) ;
53
54
if ( props . hasSearchBar ) {
54
- setDropdownCaptions ( setOptionsWithSearchBar ( prepareOptions , searchText ) ) ;
55
+ const [ remaining , indexes ] = setOptionsWithSearchBar ( prepareOptions , searchText )
56
+ setDropdownCaptions ( remaining ) ;
57
+ setSearchIndexes ( indexes ) ;
55
58
} else if ( props . hasCheckboxes ) {
56
59
setOptionsWithCheckboxes ( prepareOptions ) ;
60
+ setSearchIndexes ( null ) ;
57
61
} else {
58
62
setDropdownCaptions ( prepareOptions ) ;
63
+ setSearchIndexes ( null ) ;
59
64
}
60
65
} , [ props . options , searchText , selectedCheckboxes , props . hasSearchBar , props . hasCheckboxes , props . selectedCheckboxes , props . hasSelectAll , props . valuePropertyPath ] ) ;
61
66
@@ -167,10 +172,12 @@ export default function KernDropdown(props: KernDropdownProps) {
167
172
return ;
168
173
}
169
174
if ( props . selectedOption ) {
170
- props . selectedOption ( props . options [ index ] ) ;
171
175
if ( props . hoverBoxList ) setHoverBoxPosition ( null ) ;
172
176
if ( props . hasSearchBar ) {
173
177
setSearchText ( option ) ;
178
+ props . selectedOption ( props . options [ searchIndexes [ index ] ] ) ;
179
+ } else {
180
+ props . selectedOption ( props . options [ index ] ) ;
174
181
}
175
182
setIsOpen ( false ) ;
176
183
}
0 commit comments