Skip to content

Commit 7f969a7

Browse files
v1.18.0 (#33)
* Fixes option return for search in dropdown * Lookup lists unsupported dropdown icon error with existing list --------- Co-authored-by: Lina <lina.lumburovska@kern.ai>
1 parent 1718305 commit 7f969a7

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

components/KernDropdown.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default function KernDropdown(props: KernDropdownProps) {
2121
const [disabledOptions, setDisabledOptions] = useState<boolean[]>([]);
2222
const [backgroundColors, setBackgroundColors] = useState<string[]>([]);
2323
const [searchText, setSearchText] = useState('');
24+
const [searchIndexes, setSearchIndexes] = useState<number[]>();
2425
const [isOpen, setIsOpen_] = useState(false);
2526
const [selectedCheckboxes, setSelectedCheckboxes] = useState<any[]>([]);
2627
const [position, setPosition] = useState(null);
@@ -51,11 +52,15 @@ export default function KernDropdown(props: KernDropdownProps) {
5152
useEffect(() => {
5253
const prepareOptions = prepareDropdownOptionsToArray(props.options, props.hasSearchBar, props.valuePropertyPath);
5354
if (props.hasSearchBar) {
54-
setDropdownCaptions(setOptionsWithSearchBar(prepareOptions, searchText));
55+
const [remaining, indexes] = setOptionsWithSearchBar(prepareOptions, searchText)
56+
setDropdownCaptions(remaining);
57+
setSearchIndexes(indexes);
5558
} else if (props.hasCheckboxes) {
5659
setOptionsWithCheckboxes(prepareOptions);
60+
setSearchIndexes(null);
5761
} else {
5862
setDropdownCaptions(prepareOptions);
63+
setSearchIndexes(null);
5964
}
6065
}, [props.options, searchText, selectedCheckboxes, props.hasSearchBar, props.hasCheckboxes, props.selectedCheckboxes, props.hasSelectAll, props.valuePropertyPath]);
6166

@@ -167,10 +172,12 @@ export default function KernDropdown(props: KernDropdownProps) {
167172
return;
168173
}
169174
if (props.selectedOption) {
170-
props.selectedOption(props.options[index]);
171175
if (props.hoverBoxList) setHoverBoxPosition(null);
172176
if (props.hasSearchBar) {
173177
setSearchText(option);
178+
props.selectedOption(props.options[searchIndexes[index]]);
179+
} else {
180+
props.selectedOption(props.options[index]);
174181
}
175182
setIsOpen(false);
176183
}

components/SVGIcon.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { IconBolt, IconChevronDown, IconCode, IconDotsVertical, IconExternalLink, IconFileInfo, IconFilePencil, IconLoader, IconPlayerPlayFilled, IconSquare, IconSquareCheck, IconTrash } from '@tabler/icons-react';
1+
import { IconBolt, IconChevronDown, IconCode, IconDotsVertical, IconEdit, IconExternalLink, IconFileInfo, IconFilePencil, IconLoader, IconPlayerPlayFilled, IconShieldCheckFilled, IconShieldFilled, IconSquare, IconSquareCheck, IconTrash } from '@tabler/icons-react';
22

33
export const SUPPORTED_ICONS = ['IconCode', 'IconBolt', 'IconSquareCheck', 'IconSquare', 'IconPlayerPlayFilled', 'IconTrash', 'IconExternalLink',
4-
'IconLoader', 'IconFilePencil', 'IconFileInfo'
4+
'IconLoader', 'IconFilePencil', 'IconFileInfo', 'IconEdit', 'IconShieldFilled', 'IconShieldCheckFilled'
55
]
66

77
type SVGIconProps = {
@@ -37,6 +37,12 @@ export default function SVGIcon(props: SVGIconProps) {
3737
return <IconFilePencil size={props.size} strokeWidth={props.strokeWidth} className={`${props.useFillForIcons ? 'fill-gray-800' : ''}`} />
3838
case 'IconFileInfo':
3939
return <IconFileInfo size={props.size} strokeWidth={props.strokeWidth} className={`${props.useFillForIcons ? 'fill-gray-800' : ''}`} />
40+
case 'IconEdit':
41+
return <IconEdit size={props.size} strokeWidth={props.strokeWidth} className={`${props.useFillForIcons ? 'fill-gray-800' : ''}`} />
42+
case 'IconShieldFilled':
43+
return <IconShieldFilled size={props.size} strokeWidth={props.strokeWidth} className={`${props.useFillForIcons ? 'fill-gray-800' : ''}`} />
44+
case 'IconShieldCheckFilled':
45+
return <IconShieldCheckFilled size={props.size} strokeWidth={props.strokeWidth} className={`${props.useFillForIcons ? 'fill-gray-800' : ''}`} />
4046
default: return <IconLoader size={props.size} strokeWidth={props.strokeWidth} className={`${props.useFillForIcons ? 'fill-gray-800' : ''}`} />
4147
}
4248

helpers/dropdown-helper.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ export function prepareDropdownOptionsToArray(options: string[] | any[], hasSear
3333
else return getTextArray(options);
3434
}
3535

36-
export function setOptionsWithSearchBar(options: string[], searchText: string) {
37-
if (!searchText) return options;
38-
return options.filter(option => option.toLowerCase().includes(searchText.toLowerCase()));
36+
export function setOptionsWithSearchBar(options: string[], searchText: string): [string[], number[]] {
37+
if (!searchText) return [options, options.map((_, i) => i)];
38+
const withIdx = options.map((o, i) => ({ origIdx: i, text: o }));
39+
const filtered = withIdx.filter(option => option.text.toLowerCase().includes(searchText.toLowerCase()));
40+
return [filtered.map(f => f.text), filtered.map(f => f.origIdx)];
3941
}
4042

4143
export function checkDropdownProps(props: KernDropdownProps) {

0 commit comments

Comments
 (0)