ant-design / pro-components

🏆 Use Ant Design like a Pro!
https://pro-components.antdigital.dev
MIT License
4.23k stars 1.35k forks source link

🐛[BUG]EditableProTable可编辑表格组件,实时保存且受控时,input的长输入会发生中断 #8658

Open Yanqi-Lin opened 3 weeks ago

Yanqi-Lin commented 3 weeks ago

🐛 bug 描述

正常进行连续输入:

截屏2024-08-19 15 36 37

出现bug,输入中断,保存为拼音:

截屏2024-08-19 15 37 17

📷 复现步骤

可见:https://codesandbox.io/s/modest-dew-7r5ghf?file=/App.tsx

🏞 期望结果

输入不发生中断

💻 复现代码

可见:https://codesandbox.io/s/modest-dew-7r5ghf?file=/App.tsx

© 版本信息

bobowiki commented 2 weeks ago

请问有解决吗?把他单独抽成受控组件也无法解决问题

bobowiki commented 2 weeks ago

import React, { useRef, useState } from 'react'; import { Input } from 'antd';

const InputHoc: React.FC<{ value?: string; onChange?: any; }> = ({ value, onChange }) => { const ref = useRef(null); const [inputValue, setInputValue] = useState(value);

const handleInputChange = (e: React.ChangeEvent) => { setInputValue(e.target.value); };

const handleInputConfirm = () => { if (inputValue) { onChange?.(inputValue); } };

return ( <Input ref={ref} type="text" value={inputValue} onChange={handleInputChange} onBlur={handleInputConfirm} onPressEnter={handleInputConfirm} /> ); };

export default InputHoc; 官方有一个受控组件的写法,通过onBlur和onPressEnter进行onchange提交,试了下可行