Commit 500694ba394473d0a0d097cbb12dae6164e41161
1 parent
f0c2af9d
fixed Select bug when options is null and keydown `up` or `down`
Showing
2 changed files
with
61 additions
and
35 deletions
Show diff stats
examples/routers/select.vue
... | ... | @@ -219,15 +219,25 @@ |
219 | 219 | <template> |
220 | 220 | <Row> |
221 | 221 | <Col span="12" style="padding-right:10px"> |
222 | - <Select v-model="model11" disabled filterable> | |
223 | - <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option> | |
222 | + <Select | |
223 | + v-model="model13" | |
224 | + filterable | |
225 | + remote | |
226 | + :remote-method="remoteMethod1" | |
227 | + :loading="loading1"> | |
228 | + <Option v-for="(option, index) in options1" :value="option.value" :key="index">{{option.label}}</Option> | |
224 | 229 | </Select> |
225 | 230 | </Col> |
226 | 231 | <Col span="12"> |
227 | - <!--<Select v-model="model12" filterable multiple>--> | |
228 | - <!--<Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option>--> | |
229 | - <!--</Select>--> | |
230 | - <Input v-model="model13" disabled="" /> | |
232 | + <Select | |
233 | + v-model="model14" | |
234 | + multiple | |
235 | + filterable | |
236 | + remote | |
237 | + :remote-method="remoteMethod2" | |
238 | + :loading="loading2"> | |
239 | + <Option v-for="(option, index) in options2" :value="option.value" :key="index">{{option.label}}</Option> | |
240 | + </Select> | |
231 | 241 | </Col> |
232 | 242 | </Row> |
233 | 243 | </template> |
... | ... | @@ -235,37 +245,52 @@ |
235 | 245 | export default { |
236 | 246 | data () { |
237 | 247 | return { |
238 | - cityList: [ | |
239 | - { | |
240 | - value: 'New York', | |
241 | - label: 'New York' | |
242 | - }, | |
243 | - { | |
244 | - value: 'London', | |
245 | - label: 'London' | |
246 | - }, | |
247 | - { | |
248 | - value: 'Sydney', | |
249 | - label: 'Sydney' | |
250 | - }, | |
251 | - { | |
252 | - value: 'Ottawa', | |
253 | - label: 'Ottawa' | |
254 | - }, | |
255 | - { | |
256 | - value: 'Paris', | |
257 | - label: 'Paris' | |
258 | - }, | |
259 | - { | |
260 | - value: 'Canberra', | |
261 | - label: 'Canberra' | |
262 | - } | |
263 | - ], | |
264 | - model11: 'New York', | |
265 | - model12: [], | |
266 | - model13: 'New York' | |
248 | + model13: '', | |
249 | + loading1: false, | |
250 | + options1: [], | |
251 | + model14: [], | |
252 | + loading2: false, | |
253 | + options2: [], | |
254 | + list: ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New hampshire', 'New jersey', 'New mexico', 'New york', 'North carolina', 'North dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode island', 'South carolina', 'South dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West virginia', 'Wisconsin', 'Wyoming'] | |
255 | + } | |
256 | + }, | |
257 | + methods: { | |
258 | + remoteMethod1 (query) { | |
259 | + if (query !== '') { | |
260 | + this.loading1 = true; | |
261 | + setTimeout(() => { | |
262 | + this.loading1 = false; | |
263 | + const list = this.list.map(item => { | |
264 | + return { | |
265 | + value: item, | |
266 | + label: item | |
267 | + }; | |
268 | + }); | |
269 | + this.options1 = list.filter(item => item.label.toLowerCase().indexOf(query.toLowerCase()) > -1); | |
270 | + }, 200); | |
271 | + } else { | |
272 | + this.options1 = []; | |
273 | + } | |
274 | + }, | |
275 | + remoteMethod2 (query) { | |
276 | + if (query !== '') { | |
277 | + this.loading2 = true; | |
278 | + setTimeout(() => { | |
279 | + this.loading2 = false; | |
280 | + const list = this.list.map(item => { | |
281 | + return { | |
282 | + value: item, | |
283 | + label: item | |
284 | + }; | |
285 | + }); | |
286 | + this.options2 = list.filter(item => item.label.toLowerCase().indexOf(query.toLowerCase()) > -1); | |
287 | + }, 200); | |
288 | + } else { | |
289 | + this.options2 = []; | |
290 | + } | |
267 | 291 | } |
268 | 292 | } |
269 | 293 | } |
270 | 294 | </script> |
271 | 295 | |
296 | + | ... | ... |
src/components/select/select.vue
... | ... | @@ -556,6 +556,7 @@ |
556 | 556 | }, |
557 | 557 | resetScrollTop () { |
558 | 558 | const index = this.focusIndex - 1; |
559 | + if (!this.optionInstances.length) return; | |
559 | 560 | let bottomOverflowDistance = this.optionInstances[index].$el.getBoundingClientRect().bottom - this.$refs.dropdown.$el.getBoundingClientRect().bottom; |
560 | 561 | let topOverflowDistance = this.optionInstances[index].$el.getBoundingClientRect().top - this.$refs.dropdown.$el.getBoundingClientRect().top; |
561 | 562 | ... | ... |