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

initial pass at a 'no results found' implementation. #44

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 2.0.2 - 22 May 2020
- Add `noResultInfo` for when there are no results matching the user's search
## 2.0.1 - 22 May 2020
- Add migration instructions

Expand Down
1 change: 1 addition & 0 deletions docs/guide/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
| inputClass | String | | Class to be added to the `input` tag for validation, etc.
| maxMatches | Number | 10 | Maximum amount of list items to appear.
| minMatchingChars | Number | 2 | Minimum matching characters in query before the typeahead list appears
| noResultsInfo | String | 'No results found.' | Text to show when no results are found for what the user typed.
| prepend | String | | Text to be prepended to the `input-group`
| serializer | Function | `input => input`| Function used to convert the entries in the data array into a text string. |
| showAllResults | `Boolean` | false | Show all results even ones that highlighting doesn't match. This is useful when interacting with a API that returns results based on different values than what is displayed. Ex: user searches for "USA" and the service returns "United States of America".
Expand Down
4 changes: 4 additions & 0 deletions src/components/VueTypeAheadBootstrap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export default {
type: Boolean,
default: false
},
noResultsInfo: {
type: String,
default: "No results found."
},
showOnFocus: {
type: Boolean,
default: false
Expand Down
9 changes: 9 additions & 0 deletions src/components/VueTypeaheadBootstrapList.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<template>
<div class="list-group shadow" ref="suggestionList">
<div class="vbst-item list-group-item list-group-item-action" v-if="matchedItems.length == 0">{{ noResultsInfo }}</div>
<vue-typeahead-bootstrap-list-item
v-else-if="matchedItems.length > 0"
v-for="(item, id) in matchedItems" :key="id"
:active="isListItemActive(id)"
:data="item.data"
Expand Down Expand Up @@ -62,6 +64,10 @@ export default {
type: Number,
default: 2
},
noResultsText: {
type: String,
default: "No results found."
},
showOnFocus: {
type: Boolean,
default: false
Expand Down Expand Up @@ -89,6 +95,9 @@ export default {
},

computed: {
noResultsInfo() {
return "Searched for: " +this.query+ ". " + this.noResultsText
},
highlight() {
return text => {
text = sanitize(text)
Expand Down