Skip to content

Commit

Permalink
test(textarea): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
core-ds-bot authored and hextion committed Nov 5, 2024
1 parent 2db9808 commit 0d64d33
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions packages/textarea/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,15 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(

nativeScrollbar = Boolean(nativeScrollbarProp ?? nativeScrollbar);

const textareaRef = useRef<HTMLTextAreaElement>(null);
const [textareaNode, setTextareaNode] = useState<HTMLTextAreaElement | null>(null);
const pseudoTextareaRef = useRef<HTMLDivElement>(null);

const [focused, setFocused] = useState(false);
const [stateValue, setStateValue] = useState(defaultValue || '');
const [scrollPosition, setScrollPosition] = useState(0);

const [focusVisible] = useFocus(
/*
* При первом рендере textareaRef.current === null, то нужно пересоздать реф для корректной работы хука
* TODO: исправить хук useFocus, чтобы он поддерживал изменение ноды
*/
// eslint-disable-next-line react-hooks/exhaustive-deps
useMemo(() => ({ current: textareaRef.current }), [textareaRef.current]),
useMemo(() => ({ current: textareaNode }), [textareaNode]),
'keyboard',
);

Expand All @@ -108,10 +103,10 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(

// Хак, так как react-textarea-autosize перестал поддерживать maxHeight
useEffect(() => {
if (autosize && maxHeight && textareaRef.current && textareaRef.current.style) {
textareaRef.current.style.maxHeight = `${maxHeight}px`;
if (autosize && maxHeight && textareaNode && textareaNode.style) {
textareaNode.style.maxHeight = `${maxHeight}px`;
}
}, [autosize, maxHeight]);
}, [autosize, maxHeight, textareaNode]);

const handleTextareaFocus = (event: React.FocusEvent<HTMLTextAreaElement>) => {
setFocused(true);
Expand Down Expand Up @@ -185,7 +180,7 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
onChange: handleTextareaChange,
value: uncontrolled ? stateValue : value,
rows,
ref: mergeRefs([ref, textareaRef]),
ref: mergeRefs([ref, setTextareaNode]),
'data-test-id': dataTestId,
onScroll: handleTeaxtareaScroll,
};
Expand Down

0 comments on commit 0d64d33

Please sign in to comment.