Skip to content

Commit

Permalink
feat(v-autocomplete): add new **hide-no-data** prop
Browse files Browse the repository at this point in the history
allow the user to explicitly disable the **no-data** tile

resolves #2613
  • Loading branch information
johnleider committed May 6, 2018
1 parent 0565d37 commit 20228a5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/components/VAutocomplete/VAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,15 @@ export default {
return this.internalSearch !== this.getText(this.internalValue)
},
menuCanShow () {
if (!this.isAnyValueAllowed) return true
if (!this.isFocused) return false

return this.isFocused && this.filteredItems.length > 0
const filtered = this.filteredItems.length > 0

if (this.isAnyValueAllowed) {
return filtered
}

return !this.hideNoData || filtered
},
menuProps () {
return Object.assign(VSelect.computed.menuProps.call(this), {
Expand Down
1 change: 1 addition & 0 deletions src/components/VSelect/VSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default {
contentClass: String,
deletableChips: Boolean,
dense: Boolean,
hideNoData: Boolean,
hideSelected: Boolean,
items: {
type: Array,
Expand Down
2 changes: 1 addition & 1 deletion src/components/VSelect/VSelectList.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default {

if (!this.$scopedSlots.item) {
return this.$createElement(VListTile, tile, [
this.action && !this.hideSelected
this.action && !this.hideSelected && this.items.length > 0
? this.genAction(item, value)
: null,
this.genTileContent(item)
Expand Down
23 changes: 23 additions & 0 deletions test/unit/components/VAutocomplete/VAutocomplete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,4 +712,27 @@ test('VAutocomplete.js', ({ mount, shallow }) => {

expect(wrapper.vm.filteredItems.length).toBe(2)
})

it('should hide menu when no data', async () => {
const wrapper = mount(VAutocomplete)

const input = wrapper.first('input')
input.trigger('focus')
input.element.value = 'foo'
input.trigger('input')

expect(wrapper.vm.menuCanShow).toBe(true)

wrapper.setProps({ hideNoData: true })

await wrapper.vm.$nextTick()

expect(wrapper.vm.menuCanShow).toBe(false)

wrapper.setProps({ hideNoData: false })

await wrapper.vm.$nextTick()

expect(wrapper.vm.menuCanShow).toBe(true)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports[`VOverflowBtn should use default autocomplete selections 1`] = `
<div class="v-select__slot">
<div class="v-select__selections">
<div class="v-select__selection v-select__selection--comma">
foo,
foo
</div>
<input readonly="readonly"
tabindex="0"
Expand Down

0 comments on commit 20228a5

Please sign in to comment.