Vue change toggle focus style of select
by Roland Doda
HTML
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div id="app" class="selectdiv">
<label>
<select v-model="selected_item" @click="changed">
<option :value="null">Select item</option>
<option v-for="todo in todos" :key="todo.id" :value="todo.text">
{{todo.text}}
</option>
</select>
</label>
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
.selectdiv {
position: relative;
/*Don't really need this just for demo styling*/
float: left;
min-width: 200px;
margin: 50px 33%;
}
.selectdiv:after {
content: '\f078';
font: normal normal normal 17px/1 FontAwesome;
color: #0ebeff;
right: 11px;
top: 6px;
height: 34px;
padding: 15px 0px 0px 8px;
border-left: 1px solid #0ebeff;
position: absolute;
pointer-events: none;
}
/* IE11 hide native button (thanks Matt!) */
select::-ms-expand {
display: none;
}
.selectdiv select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
/* Add some styling */
display: block;
width: 100%;
max-width: 320px;
height: 50px;
float: right;
margin: 5px 0px;
padding: 0px 24px;
font-size: 16px;
line-height: 1.75;
color: #333;
background-color: #ffffff;
background-image: none;
border: 1px solid #0ebeff;
-ms-word-break: normal;
word-break: normal;
}
select:focus {
border: 5px solid indigo;
}
Vue
new Vue({
el: "#app",
data: {
selected_item: null,
todos: [
{ text: "Learn JavaScript", id: 1 },
{ text: "Learn Vue", id: 2 },
{ text: "Play around in JSFiddle", id: 3 },
{ text: "Build something awesome", id: 4 }
]
},
methods: {
changed(event) {
event.target.blur()
}
}
})