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

[Q] How to pre-select a value without the dropdown showing? #54

Closed
dominikus opened this issue Aug 29, 2022 · 2 comments · Fixed by #55
Closed

[Q] How to pre-select a value without the dropdown showing? #54

dominikus opened this issue Aug 29, 2022 · 2 comments · Fixed by #55
Labels
enhancement New feature or request

Comments

@dominikus
Copy link

Hi all,

is it possible to pre-select a value on mount without the dropdown showing?

I'm binding a value variable to the component which I set to an item from the data array on mount. The value shows up in the search box (good!), but unfortunately the dropdown is open as well, showing exactly one result (not so good!):

image

Is there any way to prevent this from happening?

// rough code:
let value = 'UNITED STATES';
...
<Typeahead autoselect data={countries} {extract} bind:value />
@metonym metonym added the enhancement New feature or request label Aug 29, 2022
metonym added a commit that referenced this issue Aug 29, 2022
metonym added a commit that referenced this issue Aug 29, 2022
@metonym
Copy link
Owner

metonym commented Aug 29, 2022

This is supported in v4.3.0.

Set showDropdownOnFocus to true for the results dropdown to only be shown if the search input is focused. I believe this addresses your use case where an initial value is desired without obtrusively showing the dropdown.

Svelte REPL

<Typeahead value="ca" showDropdownOnFocus {data} {extract} />

@dominikus
Copy link
Author

Brilliant, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants