import { defineComponent, nextTick, onMounted, type PropType, ref } from 'vue'; import InputWrapper from './_input'; const component = defineComponent({ inheritAttrs: true, props: { id: String, class: String, value: String, modelValue: String, placeholder: String, label: String, type: { type: String as PropType<'text' | 'email'>, default: 'text', }, invalidText: String, disabled: Boolean, helperText: String, focusOnLoad: Boolean, }, emits: { enter: () => { return true; }, input: (_: string) => { return true; }, 'update:modelValue': (_: string) => { return true; }, }, setup(props, ctx) { const inputRef = ref(null); function inputHandler(event: Event) { const element = event.target as HTMLInputElement; if (!element) { return; } ctx.emit('update:modelValue', element.value); ctx.emit('input', element.value); } onMounted(() => { nextTick(() => { if (props.focusOnLoad && inputRef.value) { inputRef.value.focus(); } }); }); return () => { return ( { inputHandler(event); if (event.key === 'Enter') { ctx.emit('enter'); } }} /> ); }; }, }); export default component;