All files PjField.vue

100% Statements 8/8
50% Branches 8/16
100% Functions 3/3
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33      1x               1x 1x 1x             1x                        
<script setup lang="ts">
import { computed } from "vue";
 
const props = defineProps<{
  label: string;
  forId: string;
  hint?: string;
  error?: string | null;
  required?: boolean;
}>();
 
const hintId = computed(() => props.hint ? `${props.forId}-hint` : null);
const errorId = computed(() => props.error ? `${props.forId}-error` : null);
const describedBy = computed(() => [
  hintId.value,
  errorId.value,
].filter(Boolean).join(" ") || undefined);
</script>
 
<template>
  <div class="pj-field" :class="{ 'pj-field--error': Boolean(error) }">
    <label class="pj-field__label" :for="forId">
      {{ label }}
      <span v-if="required" class="pj-field__required" aria-hidden="true">*</span>
    </label>
    <slot :described-by="describedBy" :invalid="Boolean(error)" />
    <p v-if="hint" :id="hintId ?? undefined" class="pj-field__hint">{{ hint }}</p>
    <p v-if="error" :id="errorId ?? undefined" class="pj-field__error" role="alert">
      {{ error }}
    </p>
  </div>
</template>