AppInputText.vue 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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="modelValue"
  40. :type="type"
  41. :placeholder="placeholder"
  42. :value="modelValue"
  43. :disabled="disabled"
  44. @input="$emit('update:modelValue', $event.target.value)"
  45. />
  46. <small v-if="error" :id="ariaDescribedbyLabel" :class="{ 'p-error': isError }">
  47. {{ error }}
  48. </small>
  49. </div>
  50. </template>