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

Correct way perform query programmatically? #52

Closed
luaz opened this issue Aug 2, 2018 · 3 comments · Fixed by #93
Closed

Correct way perform query programmatically? #52

luaz opened this issue Aug 2, 2018 · 3 comments · Fixed by #93
Assignees

Comments

@luaz
Copy link

luaz commented Aug 2, 2018

I manage to perform query programmatically using the following code, was wondering is this the best way to do it? (especially trigger the search UI to popup)

this.fetchResults("singapore", "")
// need to call for the UI to popup
this.$refs.autocomplete.listeners.click()

The code is based on this sample: https://codesandbox.io/s/mjqrk7v2rx

<vue-autosuggest
    :suggestions="suggestions"
    :inputProps="inputProps"
    :sectionConfigs="sectionConfigs"
    :renderSuggestion="renderSuggestion"
    :getSuggestionValue="getSuggestionValue"
    @focus="focusMe"
    ref="autocomplete" />
export default {
  data() {
    return {
      inputProps: {
        id: "autosuggest__input",
        onInputChange: this.fetchResults,
        placeholder: 'Search places'
      }
    }
  }
}
@darrenjennings
Copy link
Owner

It would be better for vue-autosuggest to have a prop that controls this, as right now there is an internal state variable called "loading" that I'm using. Until then, you could override it's default value which is true in the mounted lifecycle:

mounted(){
    this.$refs.autocomplete.loading = false
    this.fetchResults('singapore')
}

Thanks for the feedback!

@scottadamsmith
Copy link
Contributor

I am interested in this topic as well. I found today I had used the same approach of triggering a click event.

Regarding a potential enhancement, are suggesting a boolean prop that shows/hides suggestions and can be toggled from the outside? Originally I had though perhaps just exposing a method via ref would work, but the prop approach mitigates more $ref usage, which is ideal.

@darrenjennings
Copy link
Owner

@scottadamsmith IMO an even better enhancement would be to introduce the idea of a stateReducer. Taking inspiration from https://github.com/paypal/downshift#statereducer, we could give users ability to override data values without needing to use "control props".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants