Skip to content

Commit df1f952

Browse files
committed
Fix: Use v-show instead of v-if with DateInput to allow floating labels since the DOM structure remains after mounting the component
1 parent 254ae53 commit df1f952

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/App.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@
228228
<div>
229229
<input v-model="form.input" v-floating-label="{ label: 'A floating label' }" class="w-full">
230230
</div>
231+
<div>
232+
<datepicker v-model="form.datepicker" placeholder="A floating label with a datepicker" v-floating-label />
233+
</div>
231234
<div>
232235
<input v-model="form.input" v-floating-label="{ invalid: true }" placeholder="The placeholder becomes a label, plus this indicates invalid" class="w-full">
233236
</div>

src/components/DateInput.vue

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</script>
2121
<template>
2222
<div class="inline-block relative" :class="$attrs['class']">
23-
<div v-if="dateString">
23+
<div v-show="dateString">
2424
<div class="block flex items-center w-full form-input bg-vxvue-50" :class="{ 'pr-10': showToggle }">
2525
<span class="text-vxvue-700">{{ dateString }}</span>
2626
<button
@@ -32,16 +32,17 @@
3232
</button>
3333
</div>
3434
</div>
35-
<input
36-
v-else
37-
v-model="inputString"
38-
type="text"
39-
class="block w-full form-input peer focus:border-vxvue"
40-
:class="{ 'pr-10': showToggle }"
41-
v-bind="inputAttrs"
42-
@blur="emit('update:modelValue', parseDate(inputString, props.inputFormat).date?.value || null)"
43-
@input.prevent
44-
>
35+
<div v-show="!dateString">
36+
<input
37+
v-model="inputString"
38+
type="text"
39+
class="block w-full form-input peer focus:border-vxvue"
40+
:class="{ 'pr-10': showToggle }"
41+
v-bind="inputAttrs"
42+
@blur="emit('update:modelValue', parseDate(inputString, props.inputFormat).date?.value || null)"
43+
@input.prevent
44+
>
45+
</div>
4546
<button
4647
v-if="showToggle"
4748
ref="toggleButton"

0 commit comments

Comments
 (0)