Skip to content
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

Autocomplete 'on:selection' Event never triggers when inside of a Modal #2654

Closed
libdev-hacker opened this issue May 12, 2024 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@libdev-hacker
Copy link

Current Behavior

When implementing an Autocomplete component inside of a Modal, the selection event never gets fired, meaning that the inside value of the input never changes when selecting one of the options within the component

Expected Behavior

The selection event gets fired & the value within the input gets updated

Steps To Reproduce

  1. Nest an Autocomplete component within a Modal
  2. Like this <input class="input w-96 max-w-sm max-h-12 mb-2" bind:value={input} type="text" placeholder="Search..."/>
    <Autocomplete bind:input={input} options={Autocomplete} on:selection={onSelection}/>
  3. Try and select one of the options & see what happens

Link to Reproduction / Stackblitz

No response

More Information

No response

@libdev-hacker libdev-hacker added the bug Something isn't working label May 12, 2024
@endigo9740
Copy link
Contributor

@libdev-hacker this is a fairly complex combination of features. A minimal reproduction would be welcome please.

@libdev-hacker
Copy link
Author

Here is a video showing the issue (I apologise for the zip archive): autocomplete-in-modalzip.zip

Here is an example of how I'm trying to use these features:

<script lang='ts'>
  const modalStore: ModalStore = getModalStore();
  var autocomplete: AutocompleteOption<string>[] = [
      { label: "Test", value: "test" }
  ];

  let input: string = "";
  export let parent: SvelteComponent;
</script>
{#if $modalStore[0]}
    <div id="modal" class="bg-slate-800 grid grid-cols-1 grid-rows-2 grid-flow-col justify-items-center rounded-lg w-modal h-56 relative bottom-48">
        <div>
            <input class="input w-96 max-w-sm max-h-12 mb-2" bind:value={input} type="text" placeholder="Search..." />
            <div class="card w-full max-w-sm max-h-48 p-4 overflow-y-auto" tabindex="-1">
                <Autocomplete bind:input={input} options={autocomplete} on:selection={onSelection}/>
            </div>
        </div>
    </div>
{/if}

@endigo9740
Copy link
Contributor

endigo9740 commented May 13, 2024

@libdev-hacker thanks for the snippet. Unfortunately it looks like onSelection() was not included in your code. This is a function you should be defining and handling, like:

function onSelection(event) {
    console.log(event.detail);
}
<Autocomplete ... on:selection={onSelection}/>

This is not well explained in the docs, but is present in the documentation for the main demo at the top of the page. Just tap the Code view, then you'll see this:

Screenshot 2024-05-13 at 3 56 26 PM

Alternatively, if you're not using the on:selection, just prune it from the component.

@libdev-hacker
Copy link
Author

Hi,

Thanks for pointing that out to me, I'm sure you'd be happy to know that it now works.

Thanks for all your help & support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants