FormTextarea component

The FormTextarea component is a reusable textarea field designed for integration with useFormik composable. It handles field value updates, validation errors, and accessibility attributes automatically. With support for customization through props, it ensures consistent styling and behavior across forms while simplifying form logic.

Props:

NameTypeRequiredDescription
formikobjectfalseThe Formik instance manages form state, validation, and field values. Using Vue’s provide/inject, the Formik instance can be passed to child components. If no props are provided, the component searches for a parent Formik instance and throws an error if none is found.
namestringtrueThe name of the form field, used to identify the field in the Formik instance.
labelstringfalseAn optional label for the input field. If provided, it is displayed as a field label.
placeholderstringfalseAn optional placeholder for the input field. It is displayed inside the input when no value is present.
rowsnumber | stringfalseThe number of rows to display in the textarea. Defaults to 3 if not provided.
disabledbooleanfalseDetermines if the input field is disabled. Defaults to false.
requiredbooleanfalseDetermines if the input field is required. Defaults to false.
readonlybooleanfalseDetermines if the input field is read-only. Defaults to false.
inputPropsobjectfalseAdditional props to pass to the input field, such as attributes like custom data attributes, etc.

Slots

NameDescription
defaultSlot for rendering additional content or components inside the input container, below the input field.
prependSlot for rendering content or components before the input field, such as an icon or label.
appendSlot for rendering content or components after the input field, such as an action button or icon.
FormTextarea Sketch

Usage:

<FormTextareaField
  :formik="formik"
  name="bio"
  label="Bio:"
  placeholder="Enter your bio"
/>

If your field has array of values then you can use the name like:

<FormTextareaField
  :formik="formik"
  :name="`contacts[${index}].notes`"
  placeholder="Enter notes"
/>

Class Naming Style

  1. Base Classes: The foundational classes for this component are:
    • vf-field: The primary class applied to the container, used for general field styling.
    • vf-textarea-field: An additional base-specific class indicating the field is a textarea input.
  2. Dynamic Classes: Classes applied conditionally based on the component's state and props:
    • vf-field--error: Applied to the container when the field has a validation error, determined by formik.hasFieldError(name).
    • vf-input--disabled: Applied to the textarea element when the disabled prop is true, indicating that the field is not editable.
    • vf-input--readonly: Applied to the textarea element when the readonly prop is true, marking the field as read-only.
    • vf-input--error: Applied to the textarea element when the field has a validation error, determined by formik.hasFieldError(name).
  3. Input Wrapper Class: The vf-input class is applied to the wrapper around the textarea element. It serves as the container for the input and optional prepend/append slots.
  4. Error Message Class:
    • vf-error: Applied to the paragraph element displaying error messages. This class is rendered when formik.hasFieldError(name) is true.