Skip to content

Commit 16b6bd7

Browse files
committed
Fix hidden input when reselecting in single mode
What --- - Removing hidden class from single inputs when the dropdown is hidden. - Changing from `display:none` to zero width when hiding the input. Why --- Because the user will be typing for another element if reopening the dropdown, which we need to allow.
1 parent 970d1da commit 16b6bd7

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/components/Select.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@
215215
cursor: pointer;
216216
}
217217
.v-select input[type="search"].hidden {
218-
display: none;
218+
width: 0px;
219+
padding: 0;
219220
}
220221
.v-select input[type="search"].shrunk {
221222
width: auto;
@@ -989,7 +990,7 @@
989990
*/
990991
inputClasses() {
991992
return {
992-
hidden: !this.multiple && !this.isValueEmpty,
993+
hidden: !this.multiple && !this.isValueEmpty && !this.dropdownOpen,
993994
shrunk: this.multiple && !this.isValueEmpty,
994995
empty: this.isValueEmpty,
995996
}

test/unit/specs/Select.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,28 @@ describe('Select.vue', () => {
13771377
expect(vm.$children[0].inputClasses.shrunk).toEqual(false)
13781378
})
13791379

1380+
1381+
it('should not apply the "hidden" class to the search input when a value is present, and the dropdown is open', () => {
1382+
const vm = new Vue({
1383+
template: '<div><v-select ref="select" :options="options" :value="value"></v-select></div>',
1384+
data: {
1385+
value: 'one',
1386+
options: ['one', 'two', 'three'],
1387+
open: true
1388+
}
1389+
}).$mount()
1390+
vm.$children[0].toggleDropdown({target: vm.$children[0].$refs.search})
1391+
Vue.nextTick(() => {
1392+
Vue.nextTick(() => {
1393+
expect(vm.$children[0].open).toEqual(true)
1394+
expect(vm.$children[0].inputClasses.hidden).toEqual(false)
1395+
expect(vm.$children[0].inputClasses.empty).toEqual(false)
1396+
expect(vm.$children[0].inputClasses.shrunk).toEqual(false)
1397+
done()
1398+
})
1399+
})
1400+
})
1401+
13801402
it ('should not reset the search input on focus lost when clearSearchOnSelect is false', (done) => {
13811403
const vm = new Vue({
13821404
template: '<div><v-select ref="select" :options="options" :value="value" :clear-search-on-select="false"></v-select></div>',

0 commit comments

Comments
 (0)