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