Files
c9e66b221e Frontend: Lint warning cleanup part 1 (#43411)
## Issue
- First batch of @iansltx 's work of cleaning up lint warnings #43387 

## Description
- Quick PR review and grabbed as many confirmed low-risk quick wins as I
could `git checkout lint-cleanup <file/path/1> <file/path/2>`

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

This release contains internal code improvements with one minor UI
tweak:

* **Style**
* Dropdown menu background color adjusted for clearer contrast in action
lists
* **Refactor**
* Improved type safety across the codebase with stricter TypeScript
annotations
  * Removed unused imports and constants to reduce code clutter
* Enhanced React hook dependency arrays for more consistent component
behavior
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Rachel Perkins <rachel@Rachels-MacBook-Pro.local>
Co-authored-by: Ian Littman <iansltx@gmail.com>
2026-04-10 19:49:52 -05:00

98 lines
2.4 KiB
TypeScript

import React, { KeyboardEvent, useEffect, useRef } from "react";
import classnames from "classnames";
export interface IAutoSizeInputFieldProps {
name: string;
placeholder: string;
value: string;
inputClassName?: string;
maxLength: number;
hasError?: boolean;
isDisabled?: boolean;
isFocused?: boolean;
onFocus?: () => void;
onBlur?: () => void;
onChange: (newSelectedValue: string) => void;
onKeyPress: (event: KeyboardEvent<HTMLTextAreaElement>) => void;
disableTabability?: boolean;
}
const baseClass = "component__auto-size-input-field";
const AutoSizeInputField = ({
name,
placeholder,
value,
inputClassName,
maxLength,
hasError,
isDisabled,
isFocused,
onFocus = () => null,
onBlur = () => null,
onChange,
onKeyPress,
disableTabability = false,
}: IAutoSizeInputFieldProps): JSX.Element => {
const inputClasses = classnames(baseClass, inputClassName, "no-hover", {
[`${baseClass}--disabled`]: isDisabled,
[`${baseClass}--error`]: hasError,
[`${baseClass}__textarea`]: true,
});
const inputElement = useRef<HTMLTextAreaElement>(null);
useEffect(() => {
if (isFocused && inputElement.current) {
inputElement.current.focus();
const end = inputElement.current.value.length;
inputElement.current.selectionStart = end;
inputElement.current.selectionEnd = end;
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isFocused]);
const onInputFocus = () => {
isFocused = true;
onFocus();
};
const onInputBlur = () => {
isFocused = false;
onBlur();
};
const onInputKeyPress = (event: KeyboardEvent<HTMLTextAreaElement>) => {
onKeyPress(event);
};
const onInputChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
onChange(event.target.value);
};
return (
<div className={baseClass}>
<label className="input-sizer" data-value={value} htmlFor={name}>
<textarea
name={name}
id={name}
onChange={onInputChange}
placeholder={placeholder}
value={value}
maxLength={maxLength}
className={inputClasses}
cols={1}
rows={1}
tabIndex={disableTabability ? -1 : 0}
onFocus={onInputFocus}
onBlur={onInputBlur}
onKeyPress={onInputKeyPress}
ref={inputElement}
/>
</label>
</div>
);
};
export default AutoSizeInputField;