From 20228a5ece31745e2553de1898b9aef3585de753 Mon Sep 17 00:00:00 2001 From: John Leider Date: Sun, 6 May 2018 17:13:50 -0400 Subject: [PATCH] feat(v-autocomplete): add new **hide-no-data** prop allow the user to explicitly disable the **no-data** tile resolves #2613 --- src/components/VAutocomplete/VAutocomplete.js | 10 ++++++-- src/components/VSelect/VSelect.js | 1 + src/components/VSelect/VSelectList.js | 2 +- .../VAutocomplete/VAutocomplete.spec.js | 23 +++++++++++++++++++ .../__snapshots__/VOverflowBtn.spec.js.snap | 2 +- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/components/VAutocomplete/VAutocomplete.js b/src/components/VAutocomplete/VAutocomplete.js index 1ee25d0856d..1588b429974 100644 --- a/src/components/VAutocomplete/VAutocomplete.js +++ b/src/components/VAutocomplete/VAutocomplete.js @@ -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), { diff --git a/src/components/VSelect/VSelect.js b/src/components/VSelect/VSelect.js index ee2e6d87242..7ba6f297534 100644 --- a/src/components/VSelect/VSelect.js +++ b/src/components/VSelect/VSelect.js @@ -71,6 +71,7 @@ export default { contentClass: String, deletableChips: Boolean, dense: Boolean, + hideNoData: Boolean, hideSelected: Boolean, items: { type: Array, diff --git a/src/components/VSelect/VSelectList.js b/src/components/VSelect/VSelectList.js index 1e1b8b4bbda..aac08f45173 100644 --- a/src/components/VSelect/VSelectList.js +++ b/src/components/VSelect/VSelectList.js @@ -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) diff --git a/test/unit/components/VAutocomplete/VAutocomplete.spec.js b/test/unit/components/VAutocomplete/VAutocomplete.spec.js index 4dab589b7b1..cacf8f07e54 100644 --- a/test/unit/components/VAutocomplete/VAutocomplete.spec.js +++ b/test/unit/components/VAutocomplete/VAutocomplete.spec.js @@ -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) + }) }) diff --git a/test/unit/components/VOverflowBtn/__snapshots__/VOverflowBtn.spec.js.snap b/test/unit/components/VOverflowBtn/__snapshots__/VOverflowBtn.spec.js.snap index 27898718973..96f931dc36b 100644 --- a/test/unit/components/VOverflowBtn/__snapshots__/VOverflowBtn.spec.js.snap +++ b/test/unit/components/VOverflowBtn/__snapshots__/VOverflowBtn.spec.js.snap @@ -12,7 +12,7 @@ exports[`VOverflowBtn should use default autocomplete selections 1`] = `
- foo, + foo