Skip to content
This repository was archived by the owner on Apr 25, 2020. It is now read-only.

Commit d38c83c

Browse files
jmkenzbartkozal
authored andcommittedNov 23, 2017
Implement native label element (#15)
·
v1.6.1v1.4.0
1 parent 119a79f commit d38c83c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed
 

‎components/FloatLabel.vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<div class="vfl-has-label">
3-
<div class="vfl-label" :class="classObject" :style="{ width }" @click="focusFormEl">
3+
<label class="vfl-label" :class="classObject" :style="{ width }" :for="inputId">
44
{{ floatLabel }}
5-
</div>
5+
</label>
66
<slot></slot>
77
</div>
88
</template>
@@ -22,11 +22,16 @@ export default {
2222
dispatch: {
2323
type: Boolean,
2424
default: true
25+
},
26+
for: {
27+
type: String,
28+
default: null
2529
}
2630
},
2731
data () {
2832
return {
2933
formEl: undefined,
34+
labelEl: undefined,
3035
isActive: false,
3136
isFocused: false
3237
}
@@ -37,6 +42,12 @@ export default {
3742
this.formEl.addEventListener('input', this.updateIsFocused)
3843
this.formEl.addEventListener('blur', this.updateIsFocused)
3944
this.formEl.addEventListener('focus', this.updateIsFocused)
45+
46+
if (!this.for) {
47+
this.labelEl = this.$el.querySelector('label')
48+
this.labelEl.addEventListener('click', this.focusFormEl)
49+
}
50+
4051
this.dispatchInput()
4152
},
4253
beforeDestroy () {
@@ -64,6 +75,9 @@ export default {
6475
}
6576
},
6677
computed: {
78+
inputId () {
79+
return this.for
80+
},
6781
classObject () {
6882
return {
6983
'vfl-label-on-input': this.on && this.isActive,

‎dist/vue-float-label.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
This repository has been archived.