AppDropdown.vue 882B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <script setup>
  2. import { computed } from 'vue'
  3. const props = defineProps({
  4. label: {
  5. type: String,
  6. required: false,
  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 v-if="label">{{ label }}</label>
  21. <Dropdown
  22. class="w-full"
  23. option-label="label"
  24. option-value="value"
  25. option-disabled="disabled"
  26. :class="{ 'p-invalid': isError }"
  27. v-bind="$attrs"
  28. @change="$emit('update:modelValue', $event.value)"
  29. >
  30. </Dropdown>
  31. <small
  32. v-if="error"
  33. :aria-describedby="ariaDescribedbyLabel"
  34. :class="{ 'p-error': isError }"
  35. >
  36. {{ error }}
  37. </small>
  38. </div>
  39. </template>