import { useState } from 'react'; import { Combobox, InputBase, useCombobox } from '@mantine/core'; const MOCKDATA = Array(100000) .fill(0) .map((_, index) => `Item ${index}`); function getFilteredOptions(data: string[], searchQuery: string, limit: number) { const result: string[] = []; for (let i = 0; i < data.length; i += 1) { if (result.length === limit) { break; } if (data[i].toLowerCase().includes(searchQuery.trim().toLowerCase())) { result.push(data[i]); } } return result; } export function SelectLimit() { const combobox = useCombobox({ onDropdownClose: () => combobox.resetSelectedOption(), }); const [value, setValue] = useState(null); const [search, setSearch] = useState(''); const filteredOptions = getFilteredOptions(MOCKDATA, search, 7); const options = filteredOptions.map((item) => ( {item} )); return ( { setValue(val); setSearch(val); combobox.closeDropdown(); }} > } value={search} onChange={(event) => { combobox.openDropdown(); combobox.updateSelectedOptionIndex(); setSearch(event.currentTarget.value); }} onClick={() => combobox.openDropdown()} onFocus={() => combobox.openDropdown()} onBlur={() => { combobox.closeDropdown(); setSearch(value || ''); }} placeholder="Search value" rightSectionPointerEvents="none" /> {options.length > 0 ? options : Nothing found} ); }