43 lines
979 B
Vue
43 lines
979 B
Vue
<template>
|
|
<div :class="$attrs.class">
|
|
<label v-if="label" class="form-label" :for="id">{{ label }}:</label>
|
|
<input :id="id" ref="input" v-bind="{ ...$attrs, class: null }" class="form-input" :class="{ error: error }" :type="type" :value="modelValue" @input="$emit('update:modelValue', $event.target.value)" />
|
|
<div v-if="error" class="form-error">{{ error }}</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { v4 as uuid } from 'uuid'
|
|
|
|
export default {
|
|
inheritAttrs: false,
|
|
props: {
|
|
id: {
|
|
type: String,
|
|
default() {
|
|
return `text-input-${uuid()}`
|
|
},
|
|
},
|
|
type: {
|
|
type: String,
|
|
default: 'text',
|
|
},
|
|
class: String,
|
|
error: String,
|
|
label: String,
|
|
modelValue: String,
|
|
},
|
|
methods: {
|
|
focus() {
|
|
this.$refs.input.focus()
|
|
},
|
|
select() {
|
|
this.$refs.input.select()
|
|
},
|
|
setSelectionRange(start, end) {
|
|
this.$refs.input.setSelectionRange(start, end)
|
|
},
|
|
},
|
|
}
|
|
</script>
|