import { defineComponent, onBeforeUpdate, onMounted, ref } from 'vue'; import InputWrapper from '../input/_input'; const component = defineComponent({ props: { class: { type: String, default: '', }, modelValue: String, value: { type: String, default: '', }, placeholder: { type: String, default: '', }, label: { type: String, default: '', }, }, emits: { input: (_: string) => { return true; }, 'update:modelValue': (_?: string) => { return true; }, }, setup(props, ctx) { const textBoxRef = ref(null); const inputHandler = (event: Event) => { const element = event.target as HTMLElement; ctx.emit('update:modelValue', element.innerText); ctx.emit('input', element.innerText); }; onMounted(() => { if (props.value && textBoxRef.value) { textBoxRef.value.innerText = props.value; } }); onBeforeUpdate(() => { if (textBoxRef.value) { if (textBoxRef.value.innerText !== props.value) { textBoxRef.value.innerText = props.value; } } }); return () => { return (
{!props.value && ( {props.placeholder} )} { event.preventDefault(); const text = event.clipboardData?.getData('text/plain'); document.execCommand('insertHTML', false, text); }} onKeyup={(event) => { inputHandler(event); }} onInput={inputHandler} >
); }; }, }); export default component;