Improve the autocomplete UX a little
This commit is contained in:
@@ -31,11 +31,15 @@
|
||||
if (!name) {
|
||||
foodSearch = [];
|
||||
} else {
|
||||
updateAutocomplete();
|
||||
}
|
||||
}
|
||||
|
||||
function updateAutocomplete() {
|
||||
if (!per100Edited)
|
||||
GetLastPer100(name.trim()).then((res) => {
|
||||
// Prevent search when there's nothing to search
|
||||
// Sometimes we get search results after deleting name
|
||||
console.log(name.trim(), res);
|
||||
if (res.success && res.data && name) {
|
||||
foodSearch = res.data;
|
||||
} else {
|
||||
@@ -43,7 +47,6 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function update(event: KeyboardEvent & { currentTarget: EventTarget & HTMLTableCellElement }) {
|
||||
name = name.trim();
|
||||
@@ -102,7 +105,7 @@
|
||||
// }
|
||||
function setInputVal(food: main.Food) {
|
||||
name = food.food;
|
||||
per100 = String(food.per100)
|
||||
per100 = String(food.per100);
|
||||
hiLiteIndex = null;
|
||||
foodSearch = [];
|
||||
}
|
||||
@@ -133,6 +136,8 @@
|
||||
contenteditable="true"
|
||||
autofocus
|
||||
on:keydown={update}
|
||||
on:focusin={updateAutocomplete}
|
||||
on:focusout={() => foodSearch = []}
|
||||
bind:this={nameElement}
|
||||
/>
|
||||
<td
|
||||
@@ -162,11 +167,7 @@
|
||||
{#if foodSearch.length > 0}
|
||||
<ul bind:this={autocompleteList} class="z-50 fixed top-0 left-0 w-3/12 border border-x-gray-800">
|
||||
{#each foodSearch as f, i}
|
||||
<FoodSearchEntry
|
||||
itemLabel={f.food}
|
||||
highlighted={i == hiLiteIndex}
|
||||
on:click={() => setInputVal(f)}
|
||||
/>
|
||||
<FoodSearchEntry itemLabel={f.food} highlighted={i == hiLiteIndex} on:click={() => setInputVal(f)} />
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
|
Reference in New Issue
Block a user