123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <script setup>
  2. import { computed } from 'vue'
  3. const props = defineProps({
  4. label: {
  5. type: String,
  6. required: true,
  7. },
  8. error: {
  9. type: String,
  10. default: null,
  11. },
  12. })
  13. const isError = computed(() => (props.error ? true : false))
  14. const ariaDescribedbyLabel = computed(
  15. () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
  16. )
  17. </script>
  18. <template>
  19. <div class="field">
  20. <label>{{ label }}</label>
  21. <Textarea
  22. class="w-full"
  23. :class="{ 'p-invalid': isError }"
  24. v-bind="$attrs"
  25. @input="$emit('update:modelValue', $event.target.value)"
  26. />
  27. <small
  28. v-if="error"
  29. :aria-describedby="ariaDescribedbyLabel"
  30. :class="{ 'p-error': isError }"
  31. >
  32. {{ error }}
  33. </small>
  34. </div>
  35. </template>