mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-22 10:30:34 +03:00
fix focus/toggle issues
This commit is contained in:
Vendored
+11636
-136
File diff suppressed because one or more lines are too long
+63
-70
@@ -3,26 +3,36 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.open-indicator {
|
||||||
|
position: absolute;
|
||||||
|
top: 10px;
|
||||||
|
right: 10px;
|
||||||
|
display: inline-block;
|
||||||
|
cursor: pointer;
|
||||||
|
pointer-events: all;
|
||||||
|
transition: all 150ms cubic-bezier(1.000, -0.115, 0.975, 0.855);
|
||||||
|
transition-timing-function: cubic-bezier(1.000, -0.115, 0.975, 0.855);
|
||||||
|
}
|
||||||
|
|
||||||
|
.open .open-indicator {
|
||||||
|
transform: rotate(180deg);
|
||||||
|
}
|
||||||
|
|
||||||
.dropdown-toggle {
|
.dropdown-toggle {
|
||||||
display: block;
|
display: block;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
background: none;
|
background: none;
|
||||||
border: 1px solid rgba(60,60,60,.26);
|
border: 1px solid rgba(60,60,60,.26);
|
||||||
|
border-radius: 4px;
|
||||||
|
white-space: normal;
|
||||||
}
|
}
|
||||||
|
.searchable .dropdown-toggle {
|
||||||
.dropdown-toggle:hover,
|
cursor: text;
|
||||||
.dropdown-toggle:active,
|
|
||||||
.dropdown-toggle:focus,
|
|
||||||
.open .dropdown-toggle:hover,
|
|
||||||
.open .dropdown-toggle:active,
|
|
||||||
.open .dropdown-toggle:focus {
|
|
||||||
background: none;
|
|
||||||
/*border-color: #337ab7;*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.open .dropdown-toggle {
|
.open .dropdown-toggle {
|
||||||
background: none;
|
/*background: none;*/
|
||||||
border-color: #337ab7;
|
/*border-color: #337ab7;*/
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
border-bottom-left-radius: 0;
|
border-bottom-left-radius: 0;
|
||||||
border-bottom-right-radius: 0;
|
border-bottom-right-radius: 0;
|
||||||
@@ -33,15 +43,15 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
border-top: none;
|
border-top: none;
|
||||||
border-color: #337ab7;
|
/*border-color: #337ab7;*/
|
||||||
border-top-left-radius: 0;
|
border-top-left-radius: 0;
|
||||||
border-top-right-radius: 0;
|
border-top-right-radius: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.alert {
|
.alert {
|
||||||
margin: 0;
|
margin: 3px 1px 0px 3px;
|
||||||
margin-left: 6px;
|
padding: .02em .25em;
|
||||||
padding: .25em;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.alert .close {
|
.alert .close {
|
||||||
@@ -50,48 +60,23 @@
|
|||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type=search] {
|
input[type=search],
|
||||||
|
input[type=search]:focus {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
border: none;
|
border: none;
|
||||||
outline: none;
|
outline: none;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
width: 100%;
|
width: 10em;
|
||||||
|
max-width: 100%;
|
||||||
background: none;
|
background: none;
|
||||||
position: relative;
|
position: relative;
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
|
float: left;
|
||||||
|
clear: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type=search]:focus {
|
input[type=search]:disabled {
|
||||||
box-shadow: none;
|
cursor: pointer;
|
||||||
}
|
|
||||||
|
|
||||||
input[type=search].inline {
|
|
||||||
width: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dropdown-toggle:after {
|
|
||||||
display: block;
|
|
||||||
position: absolute;
|
|
||||||
top: 10px;
|
|
||||||
right: 10px;
|
|
||||||
display: inline-block;
|
|
||||||
font-family: 'Glyphicons Halflings';
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 400;
|
|
||||||
line-height: 1;
|
|
||||||
-webkit-font-smoothing: antialiased;
|
|
||||||
content: "\e114";
|
|
||||||
|
|
||||||
transition: all 150ms cubic-bezier(1.000, -0.115, 0.975, 0.855);
|
|
||||||
transition-timing-function: cubic-bezier(1.000, -0.115, 0.975, 0.855);
|
|
||||||
}
|
|
||||||
|
|
||||||
.open .dropdown-toggle:after {
|
|
||||||
transform: rotate(180deg);
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-control {
|
|
||||||
border: none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
li a {
|
li a {
|
||||||
@@ -111,9 +96,9 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="dropdown" :class="{open: open, }">
|
<div class="dropdown" :class="{open: open, searchable: searchable}">
|
||||||
<div v-el:toggle @click="toggleDropdown" class="btn dropdown-toggle clearfix" type="button">
|
<div v-el:toggle @mousedown.prevent="toggleDropdown" class="dropdown-toggle clearfix" type="button">
|
||||||
<span class="form-control" v-if="! searchable && placeholder && isValueEmpty">
|
<span class="form-control" v-if="!searchable && isValueEmpty">
|
||||||
{{ placeholder }}
|
{{ placeholder }}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
@@ -133,15 +118,16 @@
|
|||||||
@keydown.up.prevent="typeAheadUp"
|
@keydown.up.prevent="typeAheadUp"
|
||||||
@keydown.down.prevent="typeAheadDown"
|
@keydown.down.prevent="typeAheadDown"
|
||||||
@keydown.enter.prevent="typeAheadSelect"
|
@keydown.enter.prevent="typeAheadSelect"
|
||||||
@focus="open = true"
|
|
||||||
@blur="open = false"
|
@blur="open = false"
|
||||||
type="search"
|
type="search"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
:placeholder="searchPlaceholder"
|
:placeholder="searchPlaceholder"
|
||||||
>
|
>
|
||||||
|
|
||||||
|
<i v-el:open-indicator role="presentation" class="open-indicator glyphicon-chevron-down glyphicon"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul v-show="open" :transition="transition" :style="{ 'max-height': maxHeight }" class="dropdown-menu animated">
|
<ul v-show="open" v-el:dropdown-menu :transition="transition" :style="{ 'max-height': maxHeight }" class="dropdown-menu animated">
|
||||||
<li v-for="option in filteredOptions" :class="{ active: isOptionSelected(option), highlight: $index === typeAheadPointer }" @mouseover="typeAheadPointer = $index">
|
<li v-for="option in filteredOptions" :class="{ active: isOptionSelected(option), highlight: $index === typeAheadPointer }" @mouseover="typeAheadPointer = $index">
|
||||||
<a @mousedown.prevent="select(option)">
|
<a @mousedown.prevent="select(option)">
|
||||||
{{ getOptionLabel(option) }}
|
{{ getOptionLabel(option) }}
|
||||||
@@ -162,6 +148,10 @@
|
|||||||
twoway: true,
|
twoway: true,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
options: {
|
||||||
|
type: Array,
|
||||||
|
default() { return [] },
|
||||||
|
},
|
||||||
maxHeight: {
|
maxHeight: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '400px'
|
default: '400px'
|
||||||
@@ -182,10 +172,10 @@
|
|||||||
type: String,
|
type: String,
|
||||||
default: 'expand'
|
default: 'expand'
|
||||||
},
|
},
|
||||||
options: {
|
clearSearchOnSelect: {
|
||||||
type: Array,
|
type: Boolean,
|
||||||
default() { return [] },
|
default: true
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
@@ -197,14 +187,6 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
open( open ) {
|
|
||||||
if( open ) {
|
|
||||||
this.$els.search.focus();
|
|
||||||
} else {
|
|
||||||
this.$els.search.blur();
|
|
||||||
this.typeAheadPointer = 0;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
options() {
|
options() {
|
||||||
this.$set('value', this.multiple ? [] : null)
|
this.$set('value', this.multiple ? [] : null)
|
||||||
},
|
},
|
||||||
@@ -218,7 +200,6 @@
|
|||||||
if (! this.isOptionSelected(option) ) {
|
if (! this.isOptionSelected(option) ) {
|
||||||
if (this.multiple) {
|
if (this.multiple) {
|
||||||
|
|
||||||
// check if value is currently null/undefined/false
|
|
||||||
if( ! this.value ) {
|
if( ! this.value ) {
|
||||||
this.$set('value', [option])
|
this.$set('value', [option])
|
||||||
} else {
|
} else {
|
||||||
@@ -237,12 +218,21 @@
|
|||||||
if (!this.multiple) {
|
if (!this.multiple) {
|
||||||
this.open = !this.open
|
this.open = !this.open
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( this.clearSearchOnSelect ) {
|
||||||
|
this.search = ''
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleDropdown( e ) {
|
toggleDropdown( e ) {
|
||||||
// if( e.target == this.$els.toggle || e.target == this.$els.search ) {
|
if( e.target === this.$els.openIndicator || e.target === this.$els.search || e.target === this.$els.toggle || e.target === this.$el ) {
|
||||||
// this.open = !this.open
|
if( this.open ) {
|
||||||
// }
|
this.$els.search.blur() // dropdown will close on blur
|
||||||
|
} else {
|
||||||
|
this.open = true
|
||||||
|
this.$els.search.focus()
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
isOptionSelected( option ) {
|
isOptionSelected( option ) {
|
||||||
@@ -281,7 +271,10 @@
|
|||||||
if( this.filteredOptions[ this.typeAheadPointer ] ) {
|
if( this.filteredOptions[ this.typeAheadPointer ] ) {
|
||||||
this.select( this.filteredOptions[ this.typeAheadPointer ] );
|
this.select( this.filteredOptions[ this.typeAheadPointer ] );
|
||||||
}
|
}
|
||||||
this.search = "";
|
|
||||||
|
if( this.clearSearchOnSelect ) {
|
||||||
|
this.search = "";
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onEscape() {
|
onEscape() {
|
||||||
|
|||||||
Reference in New Issue
Block a user