Skip to content

Commit 3024f13

Browse files
authored
Bug/629 show selected value (sagalbot#631)
* Show current selection before searching * remove 'hidden' input class remove left border on input, adjust padding * Set 0 width for search input
1 parent 9262863 commit 3024f13

File tree

2 files changed

+10
-77
lines changed

2 files changed

+10
-77
lines changed

src/components/Select.vue

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
flex-grow: 1;
8080
flex-wrap: wrap;
8181
padding: 0 2px;
82+
position: relative;
8283
}
8384
.v-select .vs__actions {
8485
display: flex;
@@ -145,13 +146,17 @@
145146
line-height: 1.42857143; /* Normalize line height */
146147
margin: 4px 2px 0px 2px;
147148
padding: 0 0.25em;
149+
transition: opacity .25s;
148150
}
149151
.v-select.single .selected-tag {
150152
background-color: transparent;
151153
border-color: transparent;
152154
}
153-
.v-select.single.open .selected-tag,
154-
.v-select.single.loading .selected-tag {
155+
.v-select.single.open .selected-tag {
156+
position: absolute;
157+
opacity: .4;
158+
}
159+
.v-select.single.searching .selected-tag {
155160
display: none;
156161
}
157162
.v-select .selected-tag .close {
@@ -191,34 +196,22 @@
191196
font-size: 1em;
192197
display: inline-block;
193198
border: 1px solid transparent;
199+
border-left: none;
194200
outline: none;
195201
margin: 4px 0 0 0;
196-
padding: 0 0.5em;
202+
padding: 0 7px;
197203
max-width: 100%;
198204
background: none;
199205
box-shadow: none;
200-
201-
/* `flex-grow` will stretch the input to take all remaining space, but We
202-
need to ensure a small amount of space so there's room to type input. We'll
203-
set the input to "hidden" (via width: 0) when the dropdown is closed, to
204-
prevent adding a "blank" line (see: https://github.com/sagalbot/vue-select/pull/512).
205-
In that case, the flex-grow will still stretch the input to take any
206-
available space, on the same "line."
207-
*/
208206
flex-grow: 1;
209-
width: 4em;
207+
width: 0;
210208
}
211209
.v-select.unsearchable input[type="search"] {
212210
opacity: 0;
213211
}
214212
.v-select.unsearchable input[type="search"]:hover {
215213
cursor: pointer;
216214
}
217-
.v-select input[type="search"].hidden {
218-
border: none;
219-
padding: 0;
220-
width: 0;
221-
}
222215
223216
/* List Items */
224217
.v-select li {
@@ -343,7 +336,6 @@
343336
@focus="onSearchFocus"
344337
type="search"
345338
class="form-control"
346-
:class="inputClasses"
347339
autocomplete="off"
348340
:disabled="disabled"
349341
:placeholder="searchPlaceholder"
@@ -1074,16 +1066,6 @@
10741066
}
10751067
},
10761068
1077-
/**
1078-
* Classes to be output on input.form-control
1079-
* @return {Object}
1080-
*/
1081-
inputClasses() {
1082-
return {
1083-
hidden: !this.isValueEmpty && !this.dropdownOpen && !this.mutableLoading
1084-
}
1085-
},
1086-
10871069
/**
10881070
* If search text should clear on blur
10891071
* @return {Boolean} True when single and clearSearchOnSelect

test/unit/specs/Select.spec.js

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,55 +1591,6 @@ describe('Select.vue', () => {
15911591
})
15921592
})
15931593

1594-
it('should apply the "hidden" class to the search input when a value is present', () => {
1595-
const vm = new Vue({
1596-
template: '<div><v-select ref="select" :options="options" :value="value"></v-select></div>',
1597-
data: {
1598-
value: 'one',
1599-
options: ['one', 'two', 'three']
1600-
}
1601-
}).$mount()
1602-
1603-
expect(vm.$children[0].inputClasses.hidden).toEqual(true)
1604-
})
1605-
1606-
it('should not apply the "hidden" class to the search input when a value is present, and the dropdown is open', (done) => {
1607-
const vm = new Vue({
1608-
template: '<div><v-select ref="select" :options="options" :value="value"></v-select></div>',
1609-
data: {
1610-
value: 'one',
1611-
options: ['one', 'two', 'three'],
1612-
open: true
1613-
}
1614-
}).$mount()
1615-
vm.$children[0].toggleDropdown({target: vm.$children[0].$refs.search})
1616-
Vue.nextTick(() => {
1617-
Vue.nextTick(() => {
1618-
expect(vm.$children[0].open).toEqual(true)
1619-
expect(vm.$children[0].inputClasses.hidden).toEqual(false)
1620-
done()
1621-
})
1622-
})
1623-
})
1624-
1625-
it('should not apply the "hidden" class to the search input when a value is present, the dropdown is closed, and options are loading', (done) => {
1626-
const vm = new Vue({
1627-
template: '<div><v-select ref="select" :options="options" :value="value"></v-select></div>',
1628-
data: {
1629-
value: 'one',
1630-
options: ['one', 'two', 'three'],
1631-
open: true
1632-
}
1633-
}).$mount()
1634-
vm.$refs.select.toggleLoading(true)
1635-
Vue.nextTick(() => {
1636-
Vue.nextTick(() => {
1637-
expect(vm.$children[0].inputClasses.hidden).toEqual(false)
1638-
done()
1639-
})
1640-
})
1641-
})
1642-
16431594
it ('should not reset the search input on focus lost when clearSearchOnSelect is false', (done) => {
16441595
const vm = new Vue({
16451596
template: '<div><v-select ref="select" :options="options" :value="value" :clear-search-on-select="false"></v-select></div>',

0 commit comments

Comments
 (0)