From 07eb7b1b8f2c411134f46b66543db920a7243383 Mon Sep 17 00:00:00 2001 From: Simone Todaro Date: Wed, 17 Jan 2018 20:26:39 +0000 Subject: [PATCH 01/28] Allow user to specify the value property when options are objects --- src/components/Select.vue | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/components/Select.vue b/src/components/Select.vue index 83c14a9..53c7cc3 100644 --- a/src/components/Select.vue +++ b/src/components/Select.vue @@ -499,6 +499,16 @@ default: 'label' }, + /** + * Tells vue-select what key to use when generating option + * values when each `option` is an object. + * @type {String} + */ + index: { + type: String, + default: null + }, + /** * Callback to generate the label text. If {option} * is an object, returns option[this.label] by default. @@ -521,6 +531,15 @@ return option[this.label] } } + if(this.index) { + let label = option + this.options.forEach((val) => { + if (val[this.index] == option) { + label = val[this.label] + } + }) + return label + } return option; } }, @@ -765,7 +784,15 @@ if (this.taggable && !this.optionExists(option)) { option = this.createOption(option) } - + if(this.index) { + if (!option.hasOwnProperty(this.index)) { + console.warn( + `[vue-select warn]: Index key "option.${this.index}" does not` + + ` exist in options object ${JSON.stringify(option)}.\n`; + ) + } + option = option[this.index] + } if (this.multiple && !this.mutableValue) { this.mutableValue = [option] } else if (this.multiple) { @@ -787,7 +814,7 @@ if (this.multiple) { let ref = -1 this.mutableValue.forEach((val) => { - if (val === option || typeof val === 'object' && val[this.label] === option[this.label]) { + if (val === option || (this.index && val === option[this.index]) || (typeof val === 'object' && val[this.label] === option[this.label])) { ref = val } }) From d1de8da59f11903927eaf58cf7590e9c50f8989b Mon Sep 17 00:00:00 2001 From: Simone Todaro Date: Wed, 17 Jan 2018 21:03:12 +0000 Subject: [PATCH 02/28] Update documentation --- docs/gitbook/Basics/Options.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/gitbook/Basics/Options.md b/docs/gitbook/Basics/Options.md index 0eeb671..6269732 100644 --- a/docs/gitbook/Basics/Options.md +++ b/docs/gitbook/Basics/Options.md @@ -33,6 +33,27 @@ If you wanted to display `Canada` in the dropdown, you'd use the `countryName` k [](codepen://sagalbot/aEjLPB?height=500) + +### Option index {#values} + +When the `options` array contains objects, `vue-select` returns the whole object as dropdown value upon selection. You can specify your own `index` prop to return only the value contained in the specific property. + +For example, consider an object with `value` and `label` properties: + +```json +{ + value: "CA", + label: "Canada" +} +``` + +If you wanted to return `CA` in the dropdown when `Canada` is selected, you'd use the `index` key: + +```html + +``` + + ### Null / Empty Options {#emptyOptions} `vue-select` requires the `option` property to be an `array`. If you are using Vue in development mode, you will get warnings attempting to pass anything other than an `array` to the `options` prop. If you need a `null`/`empty` value, use an empty array `[]`. From 852890fe2ce1ede7ae018ac3d54d07f6cd916a5f Mon Sep 17 00:00:00 2001 From: Simone Todaro Date: Wed, 17 Jan 2018 22:02:11 +0000 Subject: [PATCH 03/28] Fix typo --- src/components/Select.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Select.vue b/src/components/Select.vue index 53c7cc3..ae01e1a 100644 --- a/src/components/Select.vue +++ b/src/components/Select.vue @@ -788,7 +788,7 @@ if (!option.hasOwnProperty(this.index)) { console.warn( `[vue-select warn]: Index key "option.${this.index}" does not` + - ` exist in options object ${JSON.stringify(option)}.\n`; + ` exist in options object ${JSON.stringify(option)}.` ) } option = option[this.index] From f5557bcd786393cd34ddf3e4090685e161725a16 Mon Sep 17 00:00:00 2001 From: Simone Todaro Date: Wed, 17 Jan 2018 22:08:35 +0000 Subject: [PATCH 04/28] Move console warning --- src/components/Select.vue | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/Select.vue b/src/components/Select.vue index ae01e1a..c4285c8 100644 --- a/src/components/Select.vue +++ b/src/components/Select.vue @@ -527,6 +527,16 @@ 'http://sagalbot.github.io/vue-select/#ex-labels' ) } + + if(this.index) { + if (!option.hasOwnProperty(this.index)) { + console.warn( + `[vue-select warn]: Index key "option.${this.index}" does not` + + ` exist in options object ${JSON.stringify(option)}.` + ) + } + } + if (this.label && option[this.label]) { return option[this.label] } @@ -785,12 +795,6 @@ option = this.createOption(option) } if(this.index) { - if (!option.hasOwnProperty(this.index)) { - console.warn( - `[vue-select warn]: Index key "option.${this.index}" does not` + - ` exist in options object ${JSON.stringify(option)}.` - ) - } option = option[this.index] } if (this.multiple && !this.mutableValue) { From 76a90246d8bf6d223cc7c4ed14b4b258a51a23b5 Mon Sep 17 00:00:00 2001 From: Simone Todaro Date: Wed, 17 Jan 2018 22:09:05 +0000 Subject: [PATCH 05/28] Add tests --- test/unit/specs/Select.spec.js | 124 +++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/test/unit/specs/Select.spec.js b/test/unit/specs/Select.spec.js index 8aa1e82..4f98e92 100644 --- a/test/unit/specs/Select.spec.js +++ b/test/unit/specs/Select.spec.js @@ -837,6 +837,130 @@ describe('Select.vue', () => { }) }) + describe('When index prop is defined', () => { + it('can accept an array of objects and pre-selected value (single)', () => { + const vm = new Vue({ + template: '
', + components: {vSelect}, + data: { + index: 'value', + value: 'foo', + options: [{label: 'This is Foo', value: 'foo'}, {label: 'This is Bar', value: 'bar'}] + } + }).$mount() + expect(vm.$children[0].mutableValue).toEqual(vm.value) + }) + + it('can accept an array of objects and pre-selected values (multiple)', () => { + const vm = new Vue({ + template: '
', + components: {vSelect}, + data: { + index: 'value', + value: ['foo', 'bar'], + options: [{label: 'This is Foo', value: 'foo'}, {label: 'This is Bar', value: 'bar'}] + } + }).$mount() + expect(vm.$children[0].mutableValue).toEqual(vm.value) + }) + + it('can deselect a pre-selected object', () => { + const vm = new Vue({ + template: '
', + data: { + index: 'value', + value: ['foo', 'bar'], + options: [{label: 'This is Foo', value: 'foo'}, {label: 'This is Bar', value: 'bar'}] + } + }).$mount() + vm.$children[0].select('foo') + expect(vm.$children[0].mutableValue.length).toEqual(1) + }) + + it('can deselect an option when multiple is false', () => { + const vm = new Vue({ + template: `
`, + data: { + index: 'value', + value: 'foo', + options: [{label: 'This is Foo', value: 'foo'}, {label: 'This is Bar', value: 'bar'}] + } + }).$mount() + vm.$children[0].select('foo') + expect(vm.$children[0].mutableValue).toEqual(null) + }) + + it('can use v-model syntax for a two way binding to a parent component', (done) => { + const vm = new Vue({ + template: '
', + components: {vSelect}, + data: { + index: 'value', + value: 'foo', + options: [{label: 'This is Foo', value: 'foo'}, {label: 'This is Bar', value: 'bar'}, {label: 'This is Baz', value: 'baz'}] + } + }).$mount() + + expect(vm.$children[0].value).toEqual('foo') + expect(vm.$children[0].mutableValue).toEqual('foo') + + vm.$children[0].mutableValue = 'bar' + + Vue.nextTick(() => { + expect(vm.value).toEqual('bar') + done() + }) + }), + + it('can generate labels using a custom label key', () => { + const vm = new Vue({ + template: '
', + components: {vSelect}, + data: { + index: 'value', + value: ['baz'], + options: [{value: 'foo', name: 'Foo'}, {value: 'baz', name: 'Baz'}] + } + }).$mount() + expect(vm.$children[0].$refs.toggle.querySelector('.selected-tag').textContent).toContain('Baz') + }) + + it('will console.warn when options contain objects without a valid index key', (done) => { + spyOn(console, 'warn') + const vm = new Vue({ + template: '
', + data: { + index: 'value', + options: [{label: 'Foo'}] + } + }).$mount() + vm.$children[0].open = true + Vue.nextTick(() => { + expect(console.warn).toHaveBeenCalledWith( + `[vue-select warn]: Index key "option.value" does not exist in options object {"label":"Foo"}.` + ) + done() + }) + }) + + it('will not console.warn when options contain objects without an index key', (done) => { + spyOn(console, 'warn') + const vm = new Vue({ + template: '
', + data: { + options: [{label: 'Foo'}] + } + }).$mount() + vm.$children[0].open = true + Vue.nextTick(() => { + expect(console.warn).not.toHaveBeenCalledWith( + `[vue-select warn]: Index key "option.value" does not exist in options object {"label":"Foo"}.` + ) + done() + }) + }) + }) + describe('When Tagging Is Enabled', () => { it('can determine if a given option string already exists', () => { const vm = new Vue({ From 79893024b51f470b5e153d77fa18a3d60037fb7a Mon Sep 17 00:00:00 2001 From: Jeff Date: Sun, 28 Jan 2018 17:41:32 -0800 Subject: [PATCH 06/28] - update getOptionLabel to be consistent when using `index` - move index warning from getOptionLabel to `select` method - update isOptionSelected, pull up object comparator to it's own method - add test edge cases --- src/components/Select.vue | 103 ++++++++++++-------- test/unit/specs/Select.spec.js | 166 ++++++++++++++++++++++++++------- 2 files changed, 195 insertions(+), 74 deletions(-) diff --git a/src/components/Select.vue b/src/components/Select.vue index fd15431..33ab63e 100644 --- a/src/components/Select.vue +++ b/src/components/Select.vue @@ -346,13 +346,13 @@ aria-label="Search for option" > - @@ -512,6 +512,12 @@ /** * Callback to generate the label text. If {option} * is an object, returns option[this.label] by default. + * + * Label text is used for filtering comparison and + * displaying. If you only need to adjust the + * display, you should use the `option` and + * `selected-option` slots. + * * @type {Function} * @param {Object || String} option * @return {String} @@ -519,6 +525,10 @@ getOptionLabel: { type: Function, default(option) { + if( this.index ) { + option = this.findOptionByIndexValue(option) + } + if (typeof option === 'object') { if (!option.hasOwnProperty(this.label)) { return console.warn( @@ -527,28 +537,7 @@ 'http://sagalbot.github.io/vue-select/#ex-labels' ) } - - if(this.index) { - if (!option.hasOwnProperty(this.index)) { - console.warn( - `[vue-select warn]: Index key "option.${this.index}" does not` + - ` exist in options object ${JSON.stringify(option)}.` - ) - } - } - - if (this.label && option[this.label]) { - return option[this.label] - } - } - if(this.index) { - let label = option - this.options.forEach((val) => { - if (val[this.index] == option) { - label = val[this.label] - } - }) - return label + return option[this.label] } return option; } @@ -793,7 +782,13 @@ option = this.createOption(option) } if(this.index) { - option = option[this.index] + if (!option.hasOwnProperty(this.index)) { + return console.warn( + `[vue-select warn]: Index key "option.${this.index}" does not` + + ` exist in options object ${JSON.stringify(option)}.` + ) + } + option = option[this.index] } if (this.multiple && !this.mutableValue) { this.mutableValue = [option] @@ -875,22 +870,50 @@ * @return {Boolean} True when selected | False otherwise */ isOptionSelected(option) { - if (this.multiple && this.mutableValue) { let selected = false - this.mutableValue.forEach(opt => { - if (typeof opt === 'object' && opt[this.label] === option[this.label]) { - selected = true - } else if (typeof opt === 'object' && opt[this.label] === option) { - selected = true - } - else if (opt === option) { + this.valueAsArray.forEach(value => { + if (typeof value === 'object') { + selected = this.optionObjectComparator(value, option) + } else if (value === option || value === option[this.index]) { selected = true } }) return selected - } + }, - return this.mutableValue === option + /** + * Determine if two option objects are matching. + * + * @param value {Object} + * @param option {Object} + * @returns {boolean} + */ + optionObjectComparator(value, option) { + if (this.index && value === option[this.index]) { + return true + } else if ((value[this.label] === option[this.label]) || (value[this.label] === option)) { + return true + } else if (this.index && value[this.index] === option[this.index]) { + return true + } + return false; + }, + + /** + * Finds an option from this.options + * where option[this.index] matches + * the passed in value. + * + * @param value {Object} + * @returns {*} + */ + findOptionByIndexValue(value) { + this.options.forEach(_option => { + if (JSON.stringify(_option[this.index]) === JSON.stringify(value)) { + value = _option + } + }) + return value }, /** @@ -1070,7 +1093,7 @@ * @return {Array} */ valueAsArray() { - if (this.multiple) { + if (this.multiple && this.mutableValue) { return this.mutableValue } else if (this.mutableValue) { return [].concat(this.mutableValue) diff --git a/test/unit/specs/Select.spec.js b/test/unit/specs/Select.spec.js index 72cab14..fe1cd33 100644 --- a/test/unit/specs/Select.spec.js +++ b/test/unit/specs/Select.spec.js @@ -851,6 +851,45 @@ describe('Select.vue', () => { expect(vm.$children[0].mutableValue).toEqual(vm.value) }) + it('can determine if an object is pre-selected', () => { + const vm = new Vue({ + template: '
', + components: {vSelect}, + data: { + value: 'foo', + options: [{ + id: 'foo', + label: 'This is Foo' + }] + } + }).$mount() + + expect(vm.$children[0].isOptionSelected({ + id: 'foo', + label: 'This is Foo' + })).toEqual(true) + }) + + it('can determine if an object is selected after it has been chosen', () => { + const vm = new Vue({ + template: '
', + components: {vSelect}, + data: { + options: [{id: 'foo', label: 'FooBar'}] + } + }).$mount() + + vm.$children[0].select({id: 'foo', label: 'FooBar'}); + + // Vue.nextTick(() => { + expect(vm.$children[0].isOptionSelected({ + id: 'foo', + label: 'This is Foo' + })).toEqual(true) + // done() + // }) + }) + it('can accept an array of objects and pre-selected values (multiple)', () => { const vm = new Vue({ template: '
', @@ -873,8 +912,9 @@ describe('Select.vue', () => { options: [{label: 'This is Foo', value: 'foo'}, {label: 'This is Bar', value: 'bar'}] } }).$mount() - vm.$children[0].select('foo') + vm.$children[0].deselect('foo') expect(vm.$children[0].mutableValue.length).toEqual(1) + expect(vm.$children[0].mutableValue).toEqual(['bar']) }) it('can deselect an option when multiple is false', () => { @@ -886,7 +926,7 @@ describe('Select.vue', () => { options: [{label: 'This is Foo', value: 'foo'}, {label: 'This is Bar', value: 'bar'}] } }).$mount() - vm.$children[0].select('foo') + vm.$children[0].deselect('foo') expect(vm.$children[0].mutableValue).toEqual(null) }) @@ -925,39 +965,97 @@ describe('Select.vue', () => { expect(vm.$children[0].$refs.toggle.querySelector('.selected-tag').textContent).toContain('Baz') }) - it('will console.warn when options contain objects without a valid index key', (done) => { - spyOn(console, 'warn') - const vm = new Vue({ - template: '
', - data: { - index: 'value', - options: [{label: 'Foo'}] - } - }).$mount() - vm.$children[0].open = true - Vue.nextTick(() => { - expect(console.warn).toHaveBeenCalledWith( - `[vue-select warn]: Index key "option.value" does not exist in options object {"label":"Foo"}.` - ) - done() - }) + it('will console.warn when attempting to select an option with an undefined index', () => { + spyOn(console, 'warn') + + const vm = new Vue({ + template: '
', + data: { + options: [{label: 'Foo'}] + } + }).$mount() + vm.$children[0].select({label: 'Foo'}) + expect(console.warn).toHaveBeenCalledWith( + `[vue-select warn]: Index key "option.value" does not exist in options object {"label":"Foo"}.` + ) + }) + + it('can find the original option within this.options', () => { + const vm = new Vue({ + template: '
', + data: { + options: [{id: 1, label: 'Foo'},{id:2, label: 'Bar'}] + } + }).$mount() + + expect(vm.$children[0].findOptionByIndexValue(1)).toEqual({id: 1, label: 'Foo'}) + expect(vm.$children[0].findOptionByIndexValue({id: 1, label: 'Foo'})).toEqual({id: 1, label: 'Foo'}) }) - it('will not console.warn when options contain objects without an index key', (done) => { - spyOn(console, 'warn') - const vm = new Vue({ - template: '
', - data: { - options: [{label: 'Foo'}] - } - }).$mount() - vm.$children[0].open = true - Vue.nextTick(() => { - expect(console.warn).not.toHaveBeenCalledWith( - `[vue-select warn]: Index key "option.value" does not exist in options object {"label":"Foo"}.` - ) - done() + describe('And when option[index] is a nested object', () => { + it('can determine if an object is pre-selected', () => { + const nestedOption = { + value: { + nested: true + }, + label: 'foo' + }; + const vm = new Vue({ + template: '
', + components: {vSelect}, + data: { + value: { + nested: true + }, + options: [nestedOption] + } + }).$mount() + expect(vm.$children[0].isOptionSelected({ + nested: true + })).toEqual(true) }) + + it('can determine if an object is selected after it is chosen', () => { + const nestedOption = { + value: { + nested: true + }, + label: 'foo' + }; + const vm = new Vue({ + template: '
', + components: {vSelect}, + data: { + options: [nestedOption] + } + }).$mount() + vm.$children[0].select(nestedOption) + expect(vm.$children[0].isOptionSelected(nestedOption)).toEqual(true) + }) + + it('can determine a selected values label', () => { + const nestedOption = { + value: { + nested: true + }, + label: 'foo' + }; + const vm = new Vue({ + template: '
', + components: {vSelect}, + data: { + value: { + nested: true + }, + options: [nestedOption] + } + }).$mount() + + expect(vm.$children[0].getOptionLabel({ + nested: true + })).toEqual('foo') + }) + }) }) @@ -1501,7 +1599,7 @@ describe('Select.vue', () => { value: 'foo' } }).$mount() - + expect(vm.mutableValue).toEqual('foo') vm.$el.querySelector( 'button.clear' ).click() expect(vm.mutableValue).toEqual(null) @@ -1520,6 +1618,6 @@ describe('Select.vue', () => { const buttonEl = vm.$el.querySelector( 'button.clear' ) expect(buttonEl.disabled).toEqual(true); }) - + }); }) From b92428101f1c6d4aa1fe864a88eb7079c245e009 Mon Sep 17 00:00:00 2001 From: Jeff Date: Sun, 28 Jan 2018 17:54:25 -0800 Subject: [PATCH 07/28] fix isValueEmpty bug when working with integers --- src/components/Select.vue | 4 ++-- test/unit/specs/Select.spec.js | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/components/Select.vue b/src/components/Select.vue index 33ab63e..57e626a 100644 --- a/src/components/Select.vue +++ b/src/components/Select.vue @@ -1080,9 +1080,9 @@ isValueEmpty() { if (this.mutableValue) { if (typeof this.mutableValue === 'object') { - return !Object.keys(this.mutableValue).length + return ! Object.keys(this.mutableValue).length } - return !this.mutableValue.length + return ! this.valueAsArray.length } return true; diff --git a/test/unit/specs/Select.spec.js b/test/unit/specs/Select.spec.js index fe1cd33..54fd3e9 100644 --- a/test/unit/specs/Select.spec.js +++ b/test/unit/specs/Select.spec.js @@ -249,7 +249,20 @@ describe('Select.vue', () => { expect(vm.$children[0].isOptionSelected('foo')).toEqual(true) }), - describe('change Event', () => { + it('can work with an array of integers', () => { + const vm = new Vue({ + template: '
', + components: {vSelect}, + data: { + value: 5, + } + }).$mount() + + expect(vm.$children[0].isOptionSelected(5)).toEqual(true) + expect(vm.$children[0].isValueEmpty).toEqual(false) + }) + + describe('change Event', () => { it('will trigger the input event when the selection changes', (done) => { const vm = new Vue({ template: `
`, @@ -1564,7 +1577,7 @@ describe('Select.vue', () => { }) }) - describe( 'Clear button', () => { + describe('Clear button', () => { it( 'should be displayed on single select when value is selected', () => { const VueSelect = Vue.extend( vSelect ) From 1ba47798ee6373cd4bcdae1c894bbae97363cf5a Mon Sep 17 00:00:00 2001 From: Denis Golubkov Date: Fri, 9 Feb 2018 14:53:58 +0300 Subject: [PATCH 08/28] Update README.md Added link to github page --- docs/gitbook/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/gitbook/README.md b/docs/gitbook/README.md index e6810a8..26e8d9a 100644 --- a/docs/gitbook/README.md +++ b/docs/gitbook/README.md @@ -22,4 +22,5 @@ #### Resources - **[CodePen Template](http://codepen.io/sagalbot/pen/NpwrQO)** -- **[Trello Roadmap](https://trello.com/b/vWvITNzS/vue-select)** \ No newline at end of file +- **[Trello Roadmap](https://trello.com/b/vWvITNzS/vue-select)** +- **[GitHub](https://github.com/sagalbot/vue-select)** From 970d1da3c2fbcefeadb2ee8910cd383c98f56032 Mon Sep 17 00:00:00 2001 From: Erik Nygren Date: Wed, 18 Apr 2018 13:04:22 +0100 Subject: [PATCH 09/28] Fixing unexpected linebreak on single selects What --- - Hiding the search input field if the component is in the single value option. - Making the search input field full width if no options are selected in either single or multi select mode. - Shrinking it to width auto if there are selected entries in multi mode. Why --- The component broke into two lines when selecting a a value in single mode, because an empty, non-interactable input field was pushed down to the next row if the selected entry had a long label. --- src/components/Select.vue | 25 +++++++++++++- test/unit/specs/Select.spec.js | 59 +++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/src/components/Select.vue b/src/components/Select.vue index a0e4ffa..e8710f6 100644 --- a/src/components/Select.vue +++ b/src/components/Select.vue @@ -73,6 +73,7 @@ padding: 0; background: none; border: 1px solid rgba(60, 60, 60, .26); + min-height: 36px; border-radius: 4px; white-space: normal; } @@ -213,6 +214,16 @@ .v-select.unsearchable input[type="search"]:hover { cursor: pointer; } + .v-select input[type="search"].hidden { + display: none; + } + .v-select input[type="search"].shrunk { + width: auto; + } + .v-select input[type="search"].empty { + width: 100%; + } + /* List Items */ .v-select li { line-height: 1.42857143; /* Normalize line height */ @@ -336,12 +347,12 @@ @focus="onSearchFocus" type="search" class="form-control" + :class="inputClasses" autocomplete="off" :disabled="disabled" :placeholder="searchPlaceholder" :tabindex="tabindex" :readonly="!searchable" - :style="{ width: isValueEmpty ? '100%' : 'auto' }" :id="inputId" aria-label="Search for option" > @@ -972,6 +983,18 @@ } }, + /** + * Classes to be output on input.form-control + * @return {Object} + */ + inputClasses() { + return { + hidden: !this.multiple && !this.isValueEmpty, + shrunk: this.multiple && !this.isValueEmpty, + empty: this.isValueEmpty, + } + }, + /** * If search text should clear on blur * @return {Boolean} True when single and clearSearchOnSelect diff --git a/test/unit/specs/Select.spec.js b/test/unit/specs/Select.spec.js index f67dcc5..e2d152d 100644 --- a/test/unit/specs/Select.spec.js +++ b/test/unit/specs/Select.spec.js @@ -249,6 +249,36 @@ describe('Select.vue', () => { expect(vm.$children[0].isOptionSelected('foo')).toEqual(true) }), + it('applies the "empty" class to the search input when no value is selected', () => { + const vm = new Vue({ + template: '
', + components: {vSelect}, + data: { + value: null, + options: [{label: 'one'}] + } + }).$mount() + + expect(vm.$children[0].inputClasses.empty).toEqual(true) + expect(vm.$children[0].inputClasses.shrunk).toEqual(false) + expect(vm.$children[0].inputClasses.hidden).toEqual(false) + }), + + it('applies the "shrunk" class to the search input when one or more value is selected', () => { + const vm = new Vue({ + template: '
', + components: {vSelect}, + data: { + value: [{label: 'one'}], + options: [{label: 'one'}] + } + }).$mount() + + expect(vm.$children[0].inputClasses.shrunk).toEqual(true) + expect(vm.$children[0].inputClasses.empty).toEqual(false) + expect(vm.$children[0].inputClasses.hidden).toEqual(false) + }), + describe('change Event', () => { it('will trigger the input event when the selection changes', (done) => { const vm = new Vue({ @@ -1318,7 +1348,34 @@ describe('Select.vue', () => { expect(vm.$refs.select.search).toEqual('') done() }) - }) + }) + + it('should apply the "empty" class to the search input when it does not have a selected value', () => { + const vm = new Vue({ + template: '
', + data: { + value: '', + options: ['one', 'two', 'three'] + } + }).$mount() + expect(vm.$children[0].inputClasses.empty).toEqual(true) + expect(vm.$children[0].inputClasses.shrunk).toEqual(false) + expect(vm.$children[0].inputClasses.hidden).toEqual(false) + }) + + it('should apply the "hidden" class to the search input when a value is present', () => { + const vm = new Vue({ + template: '
', + data: { + value: 'one', + options: ['one', 'two', 'three'] + } + }).$mount() + + expect(vm.$children[0].inputClasses.hidden).toEqual(true) + expect(vm.$children[0].inputClasses.empty).toEqual(false) + expect(vm.$children[0].inputClasses.shrunk).toEqual(false) + }) it ('should not reset the search input on focus lost when clearSearchOnSelect is false', (done) => { const vm = new Vue({ From 68a14d4d6caa06ffa59b6fd37211342a4965a635 Mon Sep 17 00:00:00 2001 From: ldrovira <31676496+luisDanielRoviraContreras@users.noreply.github.com> Date: Sun, 6 May 2018 12:46:17 -0400 Subject: [PATCH 10/28] Add license in README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 246679c..503f845 100644 --- a/README.md +++ b/README.md @@ -104,3 +104,7 @@ When provided an array of objects, `vue-select` will display a single value of t ``` ### For more information, please visit the [vue-select documentation.](https://sagalbot.github.io/vue-select) + +## License + +[MIT](https://github.com/sagalbot/vue-select/blob/master/LICENSE.md) From d2efc965f936344ae020912ad1a51967b7ebbb47 Mon Sep 17 00:00:00 2001 From: Kevin Ball Date: Tue, 5 Jun 2018 15:47:52 -0700 Subject: [PATCH 11/28] Add select on tab option and example --- dev/dev.html | 3 ++- src/components/Select.vue | 31 +++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/dev/dev.html b/dev/dev.html index fe481cb..c75ec22 100644 --- a/dev/dev.html +++ b/dev/dev.html @@ -9,7 +9,7 @@