improved autocomplete
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -15,7 +15,8 @@
|
||||
const ignore = ['ArrowLeft','ArrowRight'];
|
||||
//let candidate = $state({ display : '' });
|
||||
let selected = $state([]);
|
||||
let candidates = $derived(getCandidates(candidate.display));
|
||||
let candidates = $state([]);
|
||||
let timer = null;
|
||||
|
||||
async function dummyGetCandidates(text){
|
||||
console.warn(`getCandidates(${text}) not overridden!`);
|
||||
@@ -56,6 +57,11 @@
|
||||
onSelect(candidate);
|
||||
}
|
||||
|
||||
async function fetchCandidates(){
|
||||
candidates = await getCandidates(candidate.display);
|
||||
if (selected>candidates.length) selected = candidates.length;
|
||||
}
|
||||
|
||||
async function onkeyup(ev){
|
||||
if (ignore.includes(ev.key)) return;
|
||||
if (ev.key == 'ArrowDown'){
|
||||
@@ -94,8 +100,8 @@
|
||||
}
|
||||
|
||||
candidate = { display : candidate.display };
|
||||
candidates = await getCandidates(candidate.display);
|
||||
if (selected>candidates.length) selected = candidates.length;
|
||||
if (timer) clearTimeout(timer);
|
||||
timer = setTimeout(fetchCandidates,400);
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
@@ -109,7 +115,7 @@
|
||||
</style>
|
||||
|
||||
<span>
|
||||
<input type="text" bind:value={candidate.display} {onkeyup} autofocus={autofocus} {id} />
|
||||
<input type="text" bind:value={candidate.display} {onkeyup} autofocus={autofocus} />
|
||||
{#if candidates && candidates.length > 0}
|
||||
<select bind:value={selected} {ondblclick} multiple tabindex="-1">
|
||||
{#each candidates as candidate,i}
|
||||
|
||||
Reference in New Issue
Block a user