Skip to content

Commit ce8135b

Browse files
committed
docs: fix field component to detect initial value
1 parent b97218f commit ce8135b

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

docs/directive.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ For times when you cannot use the component, you may use the directive instead.
33
### Basic usage
44

55
```js
6-
let value = ''
6+
let value = '12A789MM'
77

88
<example label="Order number">
99
<input type="text" v-model="value" v-facade="'XXX-###-AA'">

styleguide/components/Field.vue

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div :class="['field-wrapper', { hasValue }]" @input="input">
2+
<div :class="['field-wrapper', { hasValue: value }]" @input="input">
33
<slot />
44
<label>{{ label }}</label>
55
</div>
@@ -10,7 +10,11 @@ export default {
1010
name: 'Field',
1111
props: ['label'],
1212
mounted() {
13-
if (this.$children[0]) {
13+
// detect the initial value
14+
const slot = this.$slots.default[0]
15+
if (slot && slot.tag === 'input') {
16+
this.value = slot.elm.value
17+
} else if (this.$children[0]) {
1418
this.value = this.$children[0].value
1519
}
1620
},
@@ -19,11 +23,6 @@ export default {
1923
value: null
2024
}
2125
},
22-
computed: {
23-
hasValue() {
24-
return !!this.value
25-
}
26-
},
2726
methods: {
2827
input(event) {
2928
this.value = event.target.value

styleguide/style.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ html, body {
99
display: none;
1010
}
1111

12-
[class^=rsg--controls], [class^=rsg--toolbar] {
13-
display: none !important;
14-
}
15-
1612
[class^=rsg--preview] {
1713
margin-bottom: 16px !important;
1814
}

0 commit comments

Comments
 (0)