Autocomplete allows you to have a text field input which can use the entered
string to search for potential completion options. The search function can
make an API request, filter local data, generate options on the fly, or
anything that returns a list of results.
<script>
import { Autocomplete } from '@thetinkerinc/colibri';
import style from './style.js';
let value;
async function getOptions(search) {
const resp = await fetch(
`https://gutendex.com/books?search=${encodeURIComponent(
search
)}`
);
const json = await resp.json();
return json.results;
}
function getDisplay(item) {
if (item.title.length > 50) {
return item.title.slice(0, 50) + '...';
}
return item.title;
}
</script>
<Autocomplete {getOptions} {getDisplay} {style} placeholder="Search books" bind:value></Autocomplete>