darrenjennings / vue-autosuggest

🔍 Vue autosuggest component.
https://darrenjennings.github.io/vue-autosuggest
MIT License
621 stars 91 forks source link

Minor bug when there is no 'default' section #148

Closed twbagustin closed 5 years ago

twbagustin commented 5 years ago

Relevant code or config

First minor bug is here, following codesanbox demo https://codesandbox.io/s/vueautosuggest-api-fetching-57d4e, if there is no "default" section, then this.sectionConfigs["default"] will be undefined and Uncaught TypeError: Cannot read property 'onSelected' of undefinedwill raise! Just search any query and hit enter will trigger selected() and raise the error, which points to 2nd bug why is selected raised in the first place if I didn't actually select anything

        selected: () => {
          (...)
          } else if (this.sectionConfigs["default"].onSelected) {
            this.sectionConfigs["default"].onSelected(null, this.searchInputOriginal);
          } else if (this.$listeners.selected) {
          (...)
        }

I currently solve this locally by setting an empty "default" section:

sectionConfigs: {
        default: {},
        (... my sections)
}

What you did: Playing with the library!

What happened: - Reproduction repository: - Problem description: -

Suggested solution:

'default' in $vm.sectionConfigs && this.sectionConfigs["default"].onSelected
darrenjennings commented 5 years ago

I am not getting this issue in the codesandbox that you linked. Can you fork the sandbox and define steps for reproduction?

darrenjennings commented 5 years ago

Closing due to inactivity. If you can provide more detailed steps then I can look again.