AppInputText.vue 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <script setup>
  2. import { computed } from 'vue'
  3. const props = defineProps({
  4. type: {
  5. type: String,
  6. default: 'text',
  7. },
  8. label: {
  9. type: String,
  10. required: true,
  11. },
  12. disabled: {
  13. type: Boolean,
  14. default: false,
  15. },
  16. placeholder: {
  17. type: String,
  18. required: true,
  19. },
  20. error: {
  21. type: String,
  22. default: null,
  23. },
  24. modelValue: null,
  25. })
  26. defineEmits(['update:modelValue'])
  27. const isError = computed(() => (props.error ? true : false))
  28. const forLabel = computed(() => props.label.toLowerCase().replace(/\s+/g, '-'))
  29. const ariaDescribedbyLabel = computed(() => props.label.toLowerCase().replace(/\s+/g, '-') + '-help')
  30. </script>
  31. <template>
  32. <div class="field">
  33. <label :for="forLabel">{{ label }}</label>
  34. <InputText
  35. class="w-full"
  36. :class="{ 'p-invalid': isError }"
  37. :id="forLabel"
  38. :aria-describedby="ariaDescribedbyLabel"
  39. :model-value="type"
  40. :placeholder="placeholder"
  41. :value="modelValue"
  42. :disabled="disabled"
  43. @input="$emit('update:modelValue', $event.target.value)"
  44. />
  45. <small v-if="error" :id="ariaDescribedbyLabel" :class="{ 'p-error': isError }">
  46. {{ error }}
  47. </small>
  48. </div>
  49. </template>