-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: Fixed the issue that the asynchronous setting of enterKeyHint fails when textarea is in autoFocus #6917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…ils when textarea is in autoFocus 当TextArea设置autoFocus时,通过useLayoutEffect设置的enterKeyHint属性在当次不会生效,需要重新触发焦点才能生效; 和豆酱沟通后提交pr,增加默认enterKeyHint设置;
📝 WalkthroughWalkthrough本次更改在 Changes
Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/components/text-area/text-area.tsx (1)
96-102
:useInputHandleKeyDown
参数对象每次渲染都会重新创建
此处直接向自定义 Hook 传递字面量对象,会导致 Hook 内部依赖全部变化而无法利用useMemo
/useCallback
等缓存,影响性能。可提前用useMemo
封装:-const handleKeydown = useInputHandleKeyDown({ - onEnterPress: props.onEnterPress, - onKeyDown: props.onKeyDown, - nativeInputRef: nativeTextAreaRef, - enterKeyHint: props.enterKeyHint, -}) +const keydownConfig = React.useMemo( + () => ({ + onEnterPress: props.onEnterPress, + onKeyDown: props.onKeyDown, + nativeInputRef: nativeTextAreaRef, + enterKeyHint: props.enterKeyHint, + }), + [props.onEnterPress, props.onKeyDown, props.enterKeyHint], +) +const handleKeydown = useInputHandleKeyDown(keydownConfig)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/components/text-area/text-area.tsx
(1 hunks)
🔇 Additional comments (2)
src/components/text-area/text-area.tsx (2)
45-53
: 属性类型定义完备,接口保持向后兼容 👍
新增的enterKeyHint
枚举值覆盖了规范中所有合法取值,并且保持可选,现有调用方不会破坏。
196-205
: 确认enterKeyHint
最低支持版本
MDN 文档显示enterkeyhint
属性在 Chrome/Edge/Chrome for Android ≥ 77、Firefox ≥ 94、Safari ≥ 13.1(iOS Safari ≥ 13.4)等主流浏览器中均已支持¹。
- 若您项目最低支持环境均在这些版本及以上,可直接依赖 React 原生属性,无需额外同步;
- 如需兼容更早版本(如某些旧 Android WebView < 77),建议在组件内部补充一次原生属性赋值。
需关注位置:
- 文件:
src/components/text-area/text-area.tsx
- 渲染
<textarea>
(约 196–205 行)useIsomorphicLayoutEffect
同步阶段示例改动:
<textarea … onKeyDown={handleKeydown} - enterKeyHint={props.enterKeyHint} + enterKeyHint={props.enterKeyHint} // React 会原样输出 unknown attribute,HTML 属性名不区分大小写 /> // 布局阶段补充原生属性,覆盖老旧环境兼容差异 useIsomorphicLayoutEffect(() => { - if (props.enterKeyHint && nativeTextAreaRef.current) { - (nativeTextAreaRef.current as any).enterKeyHint = props.enterKeyHint - } + if (props.enterKeyHint && nativeTextAreaRef.current) { + (nativeTextAreaRef.current as any).enterKeyHint = props.enterKeyHint + } }, [props.enterKeyHint])请根据您的浏览器矩阵确认是否需要保留并使用上述原生属性同步方案。
¹ 引自 MDN:https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/enterkeyhint
fix: Fixed the issue that the asynchronous setting of enterKeyHint fails when textarea is in autoFocus
当TextArea设置autoFocus时,通过useLayoutEffect设置的enterKeyHint属性在当次不会生效,需要重新触发焦点才能生效;
和豆酱沟通后提交pr,增加默认enterKeyHint设置;
Summary by CodeRabbit