All files / components/inputs/TextArea TextArea.tsx

100% Statements 8/8
60% Branches 6/10
100% Functions 1/1
100% Lines 8/8

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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80    1x               1x     1x 1x   1x                                                   6x                                                                   1x   1x  
/* eslint-disable no-ternary, max-lines-per-function */
 
import {
  ErrorText,
  InfoText,
  Label,
  SuccessText,
  TextAreaInput,
  TextAreaWrapper
} from "./styled"
import React, { ForwardedRef, forwardRef } from "react"
import { ComponentProps } from "."
 
const DEFAULT_COLS = 50
const DEFAULT_ROWS = 10
 
const TextArea = forwardRef(
  (
    {
      className,
      cols = DEFAULT_COLS,
      defaultValue,
      disabled,
      error,
      errorText,
      infoText,
      inputId,
      isExpanded,
      label,
      labelId,
      name,
      onBlur,
      onChange,
      placeholder,
      required,
      rows = DEFAULT_ROWS,
      success,
      successText,
      value
    }: ComponentProps,
    ref: ForwardedRef<HTMLTextAreaElement>
  ) => (
    <TextAreaWrapper $isExpanded={isExpanded} className={className}>
      <TextAreaInput
        $error={error}
        $success={success}
        aria-labelledby={labelId}
        cols={cols}
        defaultValue={defaultValue}
        disabled={disabled}
        id={inputId}
        name={name}
        onBlur={onBlur}
        onChange={onChange}
        placeholder={placeholder}
        ref={ref}
        required={required}
        rows={rows}
        value={value}
      />
      {label ? (
        <Label htmlFor={inputId} id={labelId}>
          {label}
        </Label>
      ) : null}
      {errorText ? <ErrorText role="alert">{errorText}</ErrorText> : null}
      {infoText ? (
        <InfoText aria-live="polite">{infoText}</InfoText>
      ) : null}{" "}
      {successText ? (
        <SuccessText aria-live="polite">{successText}</SuccessText>
      ) : null}
    </TextAreaWrapper>
  )
)
 
TextArea.displayName = "TextArea"
 
export default TextArea