inputBox.vue
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<template>
<div type="text" class="input-box-wrapper">
<div
class="content textarea"
ref="richText"
v-on="listeners"
v-bind="$attrs"
:contenteditable="true"
></div>
<div class="append-wrapper">
<slot name="append"></slot>
</div>
</div>
</template>
<script>
export default {
name: "input-box",
props: {},
data() {
return {};
},
computed: {
listeners() {
return Object.assign({}, this.$listeners, {
input: function (e) {
const inputContent = e.target.innerHTML;
this.$emit("input", inputContent);
}.bind(this),
});
},
},
mounted() {},
methods: {
focus() {
this.$refs.richText.focus();
},
reset() {
this.$refs.richText.innerHTML = "";
},
},
};
</script>
<style scoped lang="less">
.input-box-wrapper {
position: relative;
}
.content {
max-height: 200px;
overflow: auto;
&::-webkit-scrollbar {
width: 0;
}
&.textarea {
min-height: 100px;
}
&.text {
min-height: 80px;
}
&:empty:before {
content: attr(placeholder);
color: @borderBoldColor;
position: absolute;
left: 10px;
top: 7px;
}
&.focused {
border: #66b1ff 1px solid;
cursor: text;
}
&:focus {
outline: none;
}
border: 1px solid @borderBoldColor;
border-radius: 3px;
padding: 7px 10px;
padding-right: 30px;
position: relative;
}
.append-wrapper {
position: absolute;
right: 1px;
top: 1px;
bottom: 1px;
display: flex;
cursor: pointer;
align-items: center;
}
</style>