Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"classnames": "^2.2.1",
"@rc-component/input": "~1.0.0",
"@rc-component/resize-observer": "^1.0.0",
"@rc-component/util": "^1.2.0"
"@rc-component/util": "^1.3.0"
},
"devDependencies": {
"@rc-component/father-plugin": "^2.0.2",
Expand Down
11 changes: 6 additions & 5 deletions src/ResizableTextArea.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import classNames from 'classnames';
import ResizeObserver from '@rc-component/resize-observer';
import useControlledState from '@rc-component/util/lib/hooks/useControlledState';
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
import useMergedState from '@rc-component/util/lib/hooks/useMergedState';
import raf from '@rc-component/util/lib/raf';
import classNames from 'classnames';
import * as React from 'react';
import type { TextAreaProps } from '.';
import calculateAutoSizeStyle from './calculateNodeHeight';
Expand Down Expand Up @@ -32,10 +32,11 @@ const ResizableTextArea = React.forwardRef<ResizableTextAreaRef, TextAreaProps>(
};

// =============================== Value ================================
const [mergedValue, setMergedValue] = useMergedState(defaultValue, {
const [internalValue, setMergedValue] = useControlledState(
defaultValue,
value,
postState: (val) => val ?? '',
});
);
const mergedValue = internalValue ?? '';

const onInternalChange: React.ChangeEventHandler<HTMLTextAreaElement> = (
event,
Expand Down
9 changes: 3 additions & 6 deletions src/TextArea.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import clsx from 'classnames';
import { BaseInput } from '@rc-component/input';
import { type HolderRef } from '@rc-component/input/lib/BaseInput';
import useCount from '@rc-component/input/lib/hooks/useCount';
import { resolveOnChange } from '@rc-component/input/lib/utils/commonUtils';
import useMergedState from '@rc-component/util/lib/hooks/useMergedState';
import useControlledState from '@rc-component/util/lib/hooks/useControlledState';
import clsx from 'classnames';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

导入 clsx 而非 classnames

注意这里使用了 clsx 而不是 classnames,但在 package.json 中看到的依赖是 classnames。需要确认 clsx 是否可用或者是否应该保持使用 classnames

请运行以下脚本来检查项目中 clsx 的可用性:


🏁 Script executed:

#!/bin/bash
# 检查 clsx 是否在依赖中或者是否为 classnames 的别名
echo "检查 package.json 中的 clsx 依赖:"
cat package.json | jq '.dependencies.clsx // "not found"'

echo "检查 node_modules 中是否有 clsx:"
fd "clsx" node_modules --type d --max-depth 2 | head -5

Length of output: 66


🏁 Script executed:

#!/bin/bash
# 检查 package.json 中的 classnames 依赖:
echo "检查 package.json 中的 classnames 依赖:"
cat package.json | jq '.dependencies.classnames // "not found"'

# 检查 node_modules 中是否有 classnames:
echo "检查 node_modules 中是否有 classnames:"
fd "classnames" node_modules --type d --max-depth 2 | head -5

Length of output: 75


安装或重命名
依赖中没有 clsx 包,只有 classnames。请确认是要安装并使用 clsx(npm install clsx),还是将 import 改为 import classNames from 'classnames' 以消除命名混淆。

🤖 Prompt for AI Agents
In src/TextArea.tsx around line 6 the import uses `clsx` but the project has
only the `classnames` package; either install `clsx` (npm install clsx / yarn
add clsx) and keep the import, or change the import to `import classNames from
'classnames'` and update any subsequent usages (rename `clsx(...)` to
`classNames(...)`) to remove the naming mismatch.

import type { ReactNode } from 'react';
import React, { useEffect, useImperativeHandle, useRef } from 'react';
import ResizableTextArea from './ResizableTextArea';
Expand Down Expand Up @@ -45,10 +45,7 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
},
ref,
) => {
const [value, setValue] = useMergedState(defaultValue, {
value: customValue,
defaultValue,
});
const [value, setValue] = useControlledState(defaultValue, customValue);
const formatValue =
value === undefined || value === null ? '' : String(value);

Expand Down
6 changes: 6 additions & 0 deletions tests/__snapshots__/allowClear.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`should support allowClear should not show icon if defaultValue is undef
>
<button
class="rc-textarea-clear-icon rc-textarea-clear-icon-hidden"
tabindex="-1"
type="button"
>
Expand All @@ -32,6 +33,7 @@ exports[`should support allowClear should not show icon if defaultValue is undef
>
<button
class="rc-textarea-clear-icon rc-textarea-clear-icon-hidden"
tabindex="-1"
type="button"
>
Expand All @@ -52,6 +54,7 @@ exports[`should support allowClear should not show icon if defaultValue is undef
>
<button
class="rc-textarea-clear-icon rc-textarea-clear-icon-hidden"
tabindex="-1"
type="button"
>
Expand All @@ -72,6 +75,7 @@ exports[`should support allowClear should not show icon if value is undefined, n
>
<button
class="rc-textarea-clear-icon rc-textarea-clear-icon-hidden"
tabindex="-1"
type="button"
>
Expand All @@ -92,6 +96,7 @@ exports[`should support allowClear should not show icon if value is undefined, n
>
<button
class="rc-textarea-clear-icon rc-textarea-clear-icon-hidden"
tabindex="-1"
type="button"
>
Expand All @@ -112,6 +117,7 @@ exports[`should support allowClear should not show icon if value is undefined, n
>
<button
class="rc-textarea-clear-icon rc-textarea-clear-icon-hidden"
tabindex="-1"
type="button"
>
Expand Down