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

Commit c66fe6e

Browse files
committed
Use native placeholder
1 parent aa5a96a commit c66fe6e

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

components/FloatLabel.vue

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ export default {
1616
hasValue: false,
1717
isActive: false,
1818
label: '',
19-
placeholderIndentation: 6,
2019
width: 'auto'
2120
}
2221
},
2322
mounted () {
2423
this.input = this.$el.querySelector('input, textarea')
25-
this.width = `${this.input.clientWidth - this.placeholderIndentation}px`
24+
this.width = `${this.input.clientWidth}px`
2625
this.label = this.input.placeholder
27-
this.input.placeholder = ''
2826
this.input.addEventListener('input', this.updateHasValue)
2927
this.input.addEventListener('input', this.updateIsActive)
3028
this.input.addEventListener('blur', this.updateIsActive)
@@ -59,22 +57,29 @@ export default {
5957
6058
.vfl-label {
6159
position: absolute;
62-
top: 0.25em;
63-
left: 0.3em;
60+
top: 0;
61+
left: 0.1em;
6462
overflow: hidden;
6563
font-family: sans-serif;
66-
font-size: 0.7em;
64+
font-size: 0.8em;
6765
color: #aaa;
6866
text-overflow: ellipsis;
6967
white-space: nowrap;
70-
transition: top 0.2s ease-out;
68+
transition: all 0.2s ease-out;
69+
opacity: 0
7170
}
7271
7372
.vfl-label-on-input {
7473
top: -1.3em;
74+
opacity: 1;
7575
}
7676
7777
.vfl-label-on-focus {
7878
color: #0074d9;
7979
}
80+
81+
.vfl-has-label input:focus,
82+
.vfl-has-label textarea:focus {
83+
outline: 0;
84+
}
8085
</style>

demo/Demo.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ body {
3333
input,
3434
textarea {
3535
margin-bottom: 2.5em;
36-
}
37-
38-
input:focus,
39-
textarea:focus {
40-
outline: 0;
36+
line-height: 1.15;
37+
font-size: 100%;
4138
}
4239
</style>

test/components/FloatLabel.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ const getFloatLabel = () => {
2020
test('setup on mount', () => {
2121
const vm = getFloatLabel()
2222
expect(vm.input).toBeInstanceOf(HTMLInputElement)
23-
expect(vm.width).toEqual('-6px') // clientWidth = 0
2423
expect(vm.label).toEqual('Name')
25-
expect(vm.input.placeholder).toEqual('')
2624
})
2725

2826
test('classObject', () => {

0 commit comments

Comments
 (0)