Skip to content

[FIX] If loadOptions changes, items are not reloaded #723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Problem reproduction
  • Loading branch information
Przemyslaw Horban committed Feb 7, 2025
commit e9f3a8f00a8a69aefb49d31beef8ad5b474fe48b
79 changes: 79 additions & 0 deletions src/routes/tests/reproductions/itemsNotRefreshed/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<script>
import Select from '$lib/Select.svelte';
import Fuse from 'fuse.js';
import { onMount } from 'svelte';

const bananas = ['Banana 1', 'Banana 2', 'Banana 3'];
const apples = ['Apple 1', 'Apple 2', 'Apple 3'];

let selectedFruit = 'bananas';
let showSelect = true;
let selectInput;
let listVisible = false;

const createOptionsHandler = (items) => {
return async (filterText) => {
console.log('loadOptions called with:', { items, filterText }); // Debug handler execution
if (filterText.length === 0) return [...items];
const fuse = new Fuse([...items]);
const results = fuse.search(filterText).map(({ item }) => item);
console.log('loadOptions returns:', results); // Debug results
return results;
};
};

$: loadOptions = createOptionsHandler(selectedFruit === 'bananas' ? bananas : apples);
console.log('loadOptions changed:', selectedFruit); // Debug log for loadOptions change

$: if (selectedFruit) {
console.log('Selected fruit changed to:', selectedFruit);
}

const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));

const actions = [
() => listVisible = true,
() => listVisible = false,
() => selectedFruit = selectedFruit === 'bananas' ? 'apples' : 'bananas',
() => listVisible = true,
() => listVisible = false,
() => showSelect = false,
() => showSelect = true
];

async function runSequence() {
for (const action of actions) {
action();
await sleep(1000);
}
runSequence(); // Loop
}

onMount(() => {
runSequence();
});
</script>

<button on:click={() => showSelect = !showSelect}>
{showSelect ? 'Hide' : 'Show'} Select
</button>


{#if showSelect}
<Select
{loadOptions}
debounceWait="0"
bind:input={selectInput}
bind:listOpen={listVisible}
/>
{/if}

<div>
<label>
<input type="radio" bind:group={selectedFruit} value="bananas"> Bananas
</label>
<label>
<input type="radio" bind:group={selectedFruit} value="apples"> Apples
</label>
</div>