fix(chat): improve in-app keyboard avoidance
This commit is contained in:
@@ -18,7 +18,6 @@ import {
|
||||
forwardRef,
|
||||
type FormEvent,
|
||||
type KeyboardEvent,
|
||||
useEffect,
|
||||
useImperativeHandle,
|
||||
useRef,
|
||||
} from "react";
|
||||
@@ -55,20 +54,6 @@ export const ChatInputTextField = forwardRef<
|
||||
// 对外暴露与 forwardRef 同名的 ref(指向内部 textarea 节点)
|
||||
useImperativeHandle(ref, () => innerRef.current as HTMLTextAreaElement, []);
|
||||
|
||||
// 获得焦点时把 textarea 滚到可见区域(修复小米/FB IAB 键盘弹起后
|
||||
// 内容仍被遮挡的场景),rAF 等浏览器完成键盘布局。
|
||||
useEffect(() => {
|
||||
const el = innerRef.current;
|
||||
if (!el) return;
|
||||
const onFocus = () => {
|
||||
window.requestAnimationFrame(() => {
|
||||
el.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
||||
});
|
||||
};
|
||||
el.addEventListener("focus", onFocus);
|
||||
return () => el.removeEventListener("focus", onFocus);
|
||||
}, []);
|
||||
|
||||
const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
|
||||
if (e.key !== "Enter") return;
|
||||
if (e.shiftKey || e.ctrlKey || e.metaKey) return; // 修饰键 → 换行
|
||||
|
||||
Reference in New Issue
Block a user