• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alma-oss / spirit-design-system / 28179456061

25 Jun 2026 02:59PM UTC coverage: 86.433% (+0.9%) from 85.576%
28179456061

Pull #2741

github

crishpeen
fix(web): remove unused mixins and variables
Pull Request #2741: refactor(web,web-react)!: switch toggle to composition markup #DS-564

2639 of 3519 branches covered (74.99%)

Branch coverage included in aggregate %.

67 of 79 new or added lines in 4 files covered. (84.81%)

12 existing lines in 6 files now uncovered.

7223 of 7891 relevant lines covered (91.53%)

209.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.47
/packages/web-react/src/components/TextArea/TextArea.tsx
1
'use client';
2

3
import React, { type ForwardedRef, type RefObject, forwardRef, useEffect, useRef } from 'react';
167✔
4
import { warning } from '../../common/utilities';
167✔
5
import { type ForwardRefComponent, type SpiritTextAreaProps } from '../../types';
6
import { normalizeStringValue } from '../../utils';
167✔
7
import { useCharacterCounterState } from '../CharacterCounter';
167✔
8
import { TextFieldBase } from '../TextFieldBase';
167✔
9
import { TEXTAREA_MAX_SAFE_LENGTH } from './constants';
167✔
10
import { useAdjustHeight } from './useAdjustHeight';
167✔
11

12
const isCounterActive = (hasCounter: boolean | undefined, counterThreshold: number | undefined): boolean =>
167✔
13
  hasCounter === true || counterThreshold !== undefined;
31✔
14

15
const resolveCounterNativeMaxLength = (consumerMaxLength: number | undefined): number =>
167✔
UNCOV
16
  consumerMaxLength === undefined ? TEXTAREA_MAX_SAFE_LENGTH : consumerMaxLength;
×
17

18
const _TextArea = (props: SpiritTextAreaProps, ref: ForwardedRef<HTMLTextAreaElement>): JSX.Element => {
167✔
19
  const {
20
    onInput,
21
    isAutoResizing,
22
    autoResizingMaxHeight = 400,
31✔
23
    counterThreshold,
24
    hasCounter,
25
    onChange,
26
    value,
27
    defaultValue,
28
    helperText,
29
    isDisabled,
30
    id,
31
    ...restProps
32
  } = props;
31✔
33

34
  const elementReference = useRef(ref);
31✔
35
  const { adjustHeightOnAutoresize, onInput: onInputHandler } = useAdjustHeight({
31✔
36
    elementReference,
37
    onInput,
38
    isAutoResizing,
39
    maxHeight: autoResizingMaxHeight,
40
  });
41

42
  const normalizedValue = normalizeStringValue(value);
31✔
43
  const normalizedDefaultValue = normalizeStringValue(defaultValue);
31✔
44

45
  const { counterProps, handleChange } = useCharacterCounterState({
31✔
46
    value: normalizedValue,
47
    defaultValue: normalizedDefaultValue,
48
    counterThreshold,
49
    hasCounter,
50
    onChange,
51
  });
52

53
  const counterOn = isCounterActive(hasCounter, counterThreshold);
31✔
54
  const nativeMaxLength = counterOn ? resolveCounterNativeMaxLength(restProps.maxLength) : undefined;
31!
55
  const changeHandler = counterOn ? handleChange : onChange;
31!
56

57
  const didWarnMaxLengthLowerThanThresholdRef = useRef(false);
31✔
58
  useEffect(() => {
31✔
59
    if (
31!
60
      counterThreshold !== undefined &&
31!
61
      restProps.maxLength !== undefined &&
62
      restProps.maxLength < counterThreshold &&
63
      !didWarnMaxLengthLowerThanThresholdRef.current
64
    ) {
UNCOV
65
      didWarnMaxLengthLowerThanThresholdRef.current = true;
×
UNCOV
66
      warning(
×
67
        false,
68
        'TextArea: `maxLength` should be greater than or equal to `counterThreshold` to keep visible counter and hard input limit aligned.',
69
      );
70
    }
71
  }, [counterThreshold, restProps.maxLength]);
72

73
  return (
74
    <TextFieldBase
75
      id={id}
76
      isMultiline
77
      ref={elementReference as RefObject<HTMLTextAreaElement>}
78
      onInput={onInputHandler}
79
      onFocus={adjustHeightOnAutoresize}
80
      onChange={changeHandler}
81
      value={value}
82
      defaultValue={defaultValue}
83
      helperText={helperText}
84
      isDisabled={isDisabled}
85
      counterProps={counterProps}
86
      {...restProps}
87
      {...(nativeMaxLength !== undefined && { maxLength: nativeMaxLength })}
31!
88
    />
89
  );
90
};
91

92
const TextArea = forwardRef<HTMLTextAreaElement, SpiritTextAreaProps>(_TextArea) as ForwardRefComponent<
167✔
93
  HTMLTextAreaElement,
94
  SpiritTextAreaProps
95
>;
96

97
TextArea.spiritComponent = 'TextArea';
167✔
98
TextArea.displayName = 'TextArea';
167✔
99

100
export default TextArea;
167✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc