mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-03 20:25:18 +02:00
feat: Add AutoComplete functionality to activity types input
This commit is contained in:
parent
349520572d
commit
d02aa8efdb
3 changed files with 33 additions and 7 deletions
|
@ -1,12 +1,21 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let items: String[] = [];
|
export let items: String[] = [];
|
||||||
|
export let displayValue: String = "";
|
||||||
export let selectedItem;
|
export let selectedItem;
|
||||||
|
|
||||||
|
let newAdd: String[] = [];
|
||||||
|
|
||||||
$: inputVal = "";
|
$: inputVal = "";
|
||||||
|
|
||||||
function onItemClicked(item: String) {
|
function onItemClicked(item: String) {
|
||||||
selectedItem = item;
|
// items.push(item);
|
||||||
inputVal = "";
|
console.log(newAdd);
|
||||||
|
if (newAdd.includes(item)) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
newAdd.push(item);
|
||||||
|
selectedItem = item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: filteredItems = items.filter(function (item) {
|
$: filteredItems = items.filter(function (item) {
|
||||||
|
@ -17,15 +26,21 @@
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<input
|
<input
|
||||||
class="input input-bordered"
|
class="input input-bordered"
|
||||||
placeholder="Existing Activity Types"
|
placeholder=""
|
||||||
bind:value={inputVal}
|
bind:value={displayValue}
|
||||||
/>
|
/>
|
||||||
|
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||||
<ul
|
<ul
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
class="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52 max-h-80 flex-nowrap overflow-auto"
|
class="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52 max-h-80 flex-nowrap overflow-auto"
|
||||||
>
|
>
|
||||||
{#each filteredItems as item}
|
{#each filteredItems as item}
|
||||||
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
|
<!-- svelte-ignore a11y-missing-attribute -->
|
||||||
<li>
|
<li>
|
||||||
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
|
<!-- svelte-ignore a11y-missing-attribute -->
|
||||||
<a on:click|preventDefault={() => onItemClicked(item)}>{item}</a>
|
<a on:click|preventDefault={() => onItemClicked(item)}>{item}</a>
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
@ -151,11 +151,17 @@
|
||||||
<label for="date">Activity Types (Comma Seperated)</label>
|
<label for="date">Activity Types (Comma Seperated)</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
|
hidden
|
||||||
id="activityTypes"
|
id="activityTypes"
|
||||||
bind:value={activityInput}
|
bind:value={activityInput}
|
||||||
class="input input-bordered w-full max-w-xs"
|
class="input input-bordered w-full max-w-xs"
|
||||||
/>
|
/>
|
||||||
<AutoComplete items={activityTypes} bind:selectedItem={selected} />
|
|
||||||
|
<AutoComplete
|
||||||
|
items={activityTypes}
|
||||||
|
bind:selectedItem={selected}
|
||||||
|
bind:displayValue={activityInput}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="rating">Rating</label>
|
<label for="rating">Rating</label>
|
||||||
|
|
|
@ -137,14 +137,19 @@
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="date">Activity Types (Comma Seperated)</label>
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
|
hidden
|
||||||
id="activityTypes"
|
id="activityTypes"
|
||||||
bind:value={activityInput}
|
bind:value={activityInput}
|
||||||
class="input input-bordered w-full max-w-xs"
|
class="input input-bordered w-full max-w-xs"
|
||||||
/>
|
/>
|
||||||
<AutoComplete items={activityTypes} bind:selectedItem={selected} />
|
<label for="date">Activity Types (Comma Seperated)</label>
|
||||||
|
<AutoComplete
|
||||||
|
items={activityTypes}
|
||||||
|
bind:selectedItem={selected}
|
||||||
|
bind:displayValue={activityInput}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="rating">Rating</label>
|
<label for="rating">Rating</label>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue